From 57b65fb780cd592c21fb5f10dc372c123e7341f2 Mon Sep 17 00:00:00 2001 From: pengjuyan <42963214+codding-y@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:17:46 +0800 Subject: [PATCH] feat(StackSdks-Dcc): update dcc configformats enum (#565) Co-authored-by: yanpengju --- .../Enum/ConfigFormats.cs | 8 ++-- .../ConfigurationApiClient.cs | 8 ++-- .../DccClientTest.cs | 40 +++++++++---------- .../DccTest.cs | 8 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/BuildingBlocks/StackSdks/Dcc/Masa.BuildingBlocks.StackSdks.Dcc.Contracts/Enum/ConfigFormats.cs b/src/BuildingBlocks/StackSdks/Dcc/Masa.BuildingBlocks.StackSdks.Dcc.Contracts/Enum/ConfigFormats.cs index 6423abee0..cfe9e4b83 100644 --- a/src/BuildingBlocks/StackSdks/Dcc/Masa.BuildingBlocks.StackSdks.Dcc.Contracts/Enum/ConfigFormats.cs +++ b/src/BuildingBlocks/StackSdks/Dcc/Masa.BuildingBlocks.StackSdks.Dcc.Contracts/Enum/ConfigFormats.cs @@ -6,8 +6,8 @@ namespace Masa.BuildingBlocks.StackSdks.Dcc.Contracts.Enum; public enum ConfigFormats { Properties = 1, - Raw, - Json, - Yaml, - Xml + RAW, + JSON, + YAML, + XML } diff --git a/src/Contrib/Configuration/ConfigurationApi/Masa.Contrib.Configuration.ConfigurationApi.Dcc/ConfigurationApiClient.cs b/src/Contrib/Configuration/ConfigurationApi/Masa.Contrib.Configuration.ConfigurationApi.Dcc/ConfigurationApiClient.cs index 95d6fb80e..48dbb2b0f 100644 --- a/src/Contrib/Configuration/ConfigurationApi/Masa.Contrib.Configuration.ConfigurationApi.Dcc/ConfigurationApiClient.cs +++ b/src/Contrib/Configuration/ConfigurationApi/Masa.Contrib.Configuration.ConfigurationApi.Dcc/ConfigurationApiClient.cs @@ -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: @@ -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!); @@ -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(result.Content!); diff --git a/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccClientTest.cs b/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccClientTest.cs index a71424af7..2a6b911c6 100644 --- a/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccClientTest.cs +++ b/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccClientTest.cs @@ -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); @@ -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"); @@ -135,7 +135,7 @@ public void TestFormatEncryptionRawByJsonReturnConfigurationTypeIsJson2() var model = new PublishReleaseModel() { Content = encryptContent, - ConfigFormat = ConfigFormats.Json, + ConfigFormat = ConfigFormats.JSON, Encryption = true }; Assert.ThrowsException(() => client.TestFormatRaw(model, "DccObjectName")); @@ -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); @@ -206,7 +206,7 @@ public void TestFormatRawByXmlAndContentIsErrorReturnThrowArgumentException() https://blazor.masastack.com/ "; - var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.Xml }; + var raw = new PublishReleaseModel() { Content = xml, ConfigFormat = ConfigFormats.XML }; Assert.ThrowsException(() => client.TestFormatRaw(raw, "DccObjectName")); } @@ -222,7 +222,7 @@ public void TestFormatRawByXmlReturnConfigurationTypeIsXml() https://blazor.masastack.com/ "; - 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); @@ -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(() => client.TestFormatRaw(raw, "DccObjectName")); } @@ -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); @@ -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; @@ -280,11 +280,11 @@ public async Task TestGetRawByKeyAsyncReturnConfigurationTypeIsText() .ReturnsAsync(model) .Callback((string value, Action action, Action? 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; }); @@ -316,14 +316,14 @@ public async Task TestGetDynamicAsyncReturnResultNameIsApple() id = "1", name = "Apple" }, _jsonSerializerOptions), - ConfigFormat = ConfigFormats.Json + ConfigFormat = ConfigFormats.JSON }; _client .Setup(c => c.GetAsync(key, It.IsAny>()!, null)) .ReturnsAsync(raw) .Callback((string str, Action action, Action? cacheOptionsAction) => { - _trigger.Formats = ConfigFormats.Json; + _trigger.Formats = ConfigFormats.JSON; _trigger.Content = JsonSerializer.Serialize(new PublishReleaseModel() { Content = JsonSerializer.Serialize(new @@ -331,7 +331,7 @@ public async Task TestGetDynamicAsyncReturnResultNameIsApple() id = "1", name = "HuaWei" }, _jsonSerializerOptions), - ConfigFormat = ConfigFormats.Json + ConfigFormat = ConfigFormats.JSON }, _jsonSerializerOptions); _trigger.Action = action; }); @@ -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 action, Action? cacheOptionsAction) => { - _trigger.Formats = ConfigFormats.Json; + _trigger.Formats = ConfigFormats.JSON; _trigger.Content = newBrand.Serialize(_jsonSerializerOptions); _trigger.Action = action; }); @@ -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 memoryCacheClient = new(); memoryCacheClient @@ -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(), It.IsAny>(), null).Result) @@ -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(), It.IsAny>(), null).Result) .Returns(() => response); @@ -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(), It.IsAny>(), null).Result) diff --git a/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccTest.cs b/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccTest.cs index 51b03fb8d..aef630ca1 100644 --- a/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccTest.cs +++ b/src/Contrib/Configuration/ConfigurationApi/Tests/Masa.Contrib.Configuration.ConfigurationApi.Dcc.Tests/DccTest.cs @@ -144,7 +144,7 @@ public void TestCustomCaller() var response = new PublishReleaseModel() { Content = string.Empty, - ConfigFormat = ConfigFormats.Raw + ConfigFormat = ConfigFormats.RAW }; Mock memoryCacheClient = new(); memoryCacheClient @@ -205,7 +205,7 @@ public void TestUseMultiDcc() var response = new PublishReleaseModel() { Content = JsonSerializer.Serialize(brand), - ConfigFormat = ConfigFormats.Json + ConfigFormat = ConfigFormats.JSON }; Mock memoryCacheClient = new(); memoryCacheClient @@ -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); @@ -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);