Skip to content

Commit

Permalink
feat(StackSdks-Dcc): update dcc configformats enum (#565)
Browse files Browse the repository at this point in the history
Co-authored-by: yanpengju <[email protected]>
  • Loading branch information
codding-y and yanpengju authored Apr 20, 2023
1 parent d9d859f commit 57b65fb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Masa.BuildingBlocks.StackSdks.Dcc.Contracts.Enum;
public enum ConfigFormats
{
Properties = 1,
Raw,
Json,
Yaml,
Xml
RAW,
JSON,
YAML,
XML
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ protected virtual (string Raw, ConfigurationTypes ConfigurationType) FormatRaw(P

switch (result.ConfigFormat)
{
case ConfigFormats.Json:
case ConfigFormats.JSON:
return (result.Content!, ConfigurationTypes.Json);

case ConfigFormats.Raw:
case ConfigFormats.RAW:
return (result.Content!, ConfigurationTypes.Text);

case ConfigFormats.Properties:
Expand All @@ -162,7 +162,7 @@ protected virtual (string Raw, ConfigurationTypes ConfigurationType) FormatRaw(P
throw new ArgumentException("configObject invalid");
}

case ConfigFormats.Xml:
case ConfigFormats.XML:
try
{
var json = XmlConfigurationParser.XmlToJson(result.Content!);
Expand All @@ -175,7 +175,7 @@ protected virtual (string Raw, ConfigurationTypes ConfigurationType) FormatRaw(P
throw new ArgumentException("configObject invalid");
}

case ConfigFormats.Yaml:
case ConfigFormats.YAML:
try
{
var yamlObject = _yamlDeserializer.Deserialize<object>(result.Content!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void TestFormatRawByJsonReturnConfigurationTypeIsJson()
var model = new PublishReleaseModel()
{
Content = content,
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
};
var result = client.TestFormatRaw(model, "DccObjectName");
Assert.IsTrue(result.Raw == content && result.ConfigurationType == ConfigurationTypes.Json);
Expand All @@ -119,7 +119,7 @@ public void TestFormatEncryptionRawByJsonReturnConfigurationTypeIsJson()
var model = new PublishReleaseModel()
{
Content = encryptContent,
ConfigFormat = ConfigFormats.Json,
ConfigFormat = ConfigFormats.JSON,
Encryption = true
};
var result = client.TestFormatRaw(model, "DccObjectName");
Expand All @@ -135,7 +135,7 @@ public void TestFormatEncryptionRawByJsonReturnConfigurationTypeIsJson2()
var model = new PublishReleaseModel()
{
Content = encryptContent,
ConfigFormat = ConfigFormats.Json,
ConfigFormat = ConfigFormats.JSON,
Encryption = true
};
Assert.ThrowsException<ArgumentNullException>(() => client.TestFormatRaw(model, "DccObjectName"));
Expand All @@ -149,7 +149,7 @@ public void TestFormatRawByTextReturnConfigurationTypeIsText()
var model = new PublishReleaseModel()
{
Content = content,
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
var result = client.TestFormatRaw(model, "DccObjectName");
Assert.IsTrue(result.Raw == content && result.ConfigurationType == ConfigurationTypes.Text);
Expand Down Expand Up @@ -206,7 +206,7 @@ public void TestFormatRawByXmlAndContentIsErrorReturnThrowArgumentException()
<url>https://blazor.masastack.com/</url>
</person>
</root>";
var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.Xml };
var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.XML };

Assert.ThrowsException<ArgumentException>(() => client.TestFormatRaw(raw, "DccObjectName"));
}
Expand All @@ -222,7 +222,7 @@ public void TestFormatRawByXmlReturnConfigurationTypeIsXml()
<url>https://blazor.masastack.com/</url>
</person>
</root>";
var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.Xml };
var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.XML };
var result = client.TestFormatRaw(raw, "DccObjectName");

Assert.IsTrue(result.ConfigurationType == ConfigurationTypes.Xml);
Expand All @@ -238,7 +238,7 @@ public void TestFormatRawByYamlAndContentIsErrorReturnThrowArgumentException()
addresses:
home:
city: hangzhou";
var raw = new PublishReleaseModel() { Content = yaml, ConfigFormat = ConfigFormats.Yaml };
var raw = new PublishReleaseModel() { Content = yaml, ConfigFormat = ConfigFormats.YAML };
Assert.ThrowsException<ArgumentException>(() => client.TestFormatRaw(raw, "DccObjectName"));
}

Expand All @@ -257,7 +257,7 @@ public void TestFormatRawByYamlReturnConfigurationTypeIsXml()

var serializer = new SerializerBuilder().JsonCompatible().Build();
var json = serializer.Serialize(yamlObject);
var raw = new PublishReleaseModel() { Content = yaml, ConfigFormat = ConfigFormats.Yaml };
var raw = new PublishReleaseModel() { Content = yaml, ConfigFormat = ConfigFormats.YAML };
var result = client.TestFormatRaw(raw, "DccObjectName");

Assert.IsTrue(result.Raw == json && result.ConfigurationType == ConfigurationTypes.Yaml);
Expand All @@ -271,7 +271,7 @@ public async Task TestGetRawByKeyAsyncReturnConfigurationTypeIsText()
var model = new PublishReleaseModel()
{
Content = content,
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
string key = "DccObjectName";
bool isExecute = false;
Expand All @@ -280,11 +280,11 @@ public async Task TestGetRawByKeyAsyncReturnConfigurationTypeIsText()
.ReturnsAsync(model)
.Callback((string value, Action<PublishReleaseModel> action, Action<MultilevelCacheOptions>? cacheOptionsAction) =>
{
_trigger.Formats = ConfigFormats.Raw;
_trigger.Formats = ConfigFormats.RAW;
_trigger.Content = JsonSerializer.Serialize(new PublishReleaseModel()
{
Content = "Apple",
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
}, _jsonSerializerOptions);
_trigger.Action = action;
});
Expand Down Expand Up @@ -316,22 +316,22 @@ public async Task TestGetDynamicAsyncReturnResultNameIsApple()
id = "1",
name = "Apple"
}, _jsonSerializerOptions),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
};
_client
.Setup(c => c.GetAsync(key, It.IsAny<Action<PublishReleaseModel>>()!, null))
.ReturnsAsync(raw)
.Callback((string str, Action<PublishReleaseModel> action, Action<MultilevelCacheOptions>? cacheOptionsAction) =>
{
_trigger.Formats = ConfigFormats.Json;
_trigger.Formats = ConfigFormats.JSON;
_trigger.Content = JsonSerializer.Serialize(new PublishReleaseModel()
{
Content = JsonSerializer.Serialize(new
{
id = "1",
name = "HuaWei"
}, _jsonSerializerOptions),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
}, _jsonSerializerOptions);
_trigger.Action = action;
});
Expand Down Expand Up @@ -435,12 +435,12 @@ public async Task TestGetAsyncByJsonReturn(string environment, string cluster, s
.ReturnsAsync(()
=> new PublishReleaseModel()
{
ConfigFormat = ConfigFormats.Json,
ConfigFormat = ConfigFormats.JSON,
Content = brand.Serialize(_jsonSerializerOptions)
})
.Callback((string str, Action<PublishReleaseModel> action, Action<MultilevelCacheOptions>? cacheOptionsAction) =>
{
_trigger.Formats = ConfigFormats.Json;
_trigger.Formats = ConfigFormats.JSON;
_trigger.Content = newBrand.Serialize(_jsonSerializerOptions);
_trigger.Action = action;
});
Expand Down Expand Up @@ -470,7 +470,7 @@ public void TestSingleSection(string environment, string cluster, string appId,
var response = new PublishReleaseModel()
{
Content = brand.Serialize(_jsonSerializerOptions),
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
Mock<IManualMultilevelCacheClient> memoryCacheClient = new();
memoryCacheClient
Expand Down Expand Up @@ -512,7 +512,7 @@ public void TestSingleSection2(string environment, string cluster, string appId,
var response = new PublishReleaseModel()
{
Content = masaDic.Serialize(_jsonSerializerOptions),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
};
memoryCacheClient
.Setup(client => client.GetAsync(It.IsAny<string>(), It.IsAny<Action<PublishReleaseModel?>>(), null).Result)
Expand Down Expand Up @@ -550,7 +550,7 @@ public void TestSingleSection3(string environment, string cluster, string appId,
var response = new PublishReleaseModel()
{
Content = "Test",
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
memoryCacheClient.Setup(client => client.GetAsync(It.IsAny<string>(), It.IsAny<Action<PublishReleaseModel?>>(), null).Result)
.Returns(() => response);
Expand Down Expand Up @@ -586,7 +586,7 @@ public void TestSingleSection4(string environment, string cluster, string appId,
var response = new PublishReleaseModel()
{
Content = null,
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
memoryCacheClient
.Setup(client => client.GetAsync(It.IsAny<string>(), It.IsAny<Action<PublishReleaseModel?>>(), null).Result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void TestCustomCaller()
var response = new PublishReleaseModel()
{
Content = string.Empty,
ConfigFormat = ConfigFormats.Raw
ConfigFormat = ConfigFormats.RAW
};
Mock<IManualMultilevelCacheClient> memoryCacheClient = new();
memoryCacheClient
Expand Down Expand Up @@ -205,7 +205,7 @@ public void TestUseMultiDcc()
var response = new PublishReleaseModel()
{
Content = JsonSerializer.Serialize(brand),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
};
Mock<IManualMultilevelCacheClient> memoryCacheClient = new();
memoryCacheClient
Expand Down Expand Up @@ -245,7 +245,7 @@ public void TestMasaConfigurationByConfigurationApiReturnKeyIsExist()
var value = new PublishReleaseModel()
{
Content = brand.Serialize(_jsonSerializerOptions),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
};
multilevelCacheClient.Set(key, value);

Expand Down Expand Up @@ -288,7 +288,7 @@ public void TestGetSecretReturnSecretEqualSecret()
string value = new PublishReleaseModel()
{
Content = brand.Serialize(_jsonSerializerOptions),
ConfigFormat = ConfigFormats.Json
ConfigFormat = ConfigFormats.JSON
}.Serialize(_jsonSerializerOptions);
multilevelCacheClient.Set(key, value);

Expand Down

0 comments on commit 57b65fb

Please sign in to comment.