From 39b2a86ea48cad376f845cbd29dcc6fb69859ecd Mon Sep 17 00:00:00 2001 From: pengweiqhca Date: Tue, 16 Apr 2024 10:04:41 +0800 Subject: [PATCH 1/3] Fix build error. --- test/Apollo.OpenApi.Tests/AppClusterTest.cs | 12 ++++---- .../NamespaceClientTest.cs | 30 +++++++++---------- .../OpenApiFactoryTest.cs | 12 +++----- test/Apollo.Tests/ConfigServiceLocatorTest.cs | 8 ++--- test/Apollo.Tests/ConfigTest.cs | 12 ++++---- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/test/Apollo.OpenApi.Tests/AppClusterTest.cs b/test/Apollo.OpenApi.Tests/AppClusterTest.cs index e0535b1..f956b74 100644 --- a/test/Apollo.OpenApi.Tests/AppClusterTest.cs +++ b/test/Apollo.OpenApi.Tests/AppClusterTest.cs @@ -13,7 +13,7 @@ public AppClusterTest(ITestOutputHelper output) : base(output) { } [Fact] public async Task GetEnvClusterInfo() { - var result = await CreateAppClusterClient().GetEnvClusterInfo().ConfigureAwait(false); + var result = await CreateAppClusterClient().GetEnvClusterInfo(); Dump(result); @@ -31,7 +31,7 @@ public async Task GetEnvClusterInfo() [Fact] public async Task GetCluster() { - var result = await CreateAppClusterClient().GetCluster("DEV").ConfigureAwait(false); + var result = await CreateAppClusterClient().GetCluster("DEV"); Dump(result); @@ -43,7 +43,7 @@ public async Task GetCluster() [Fact] public async Task GetAppInfo() { - var result = await CreateAppClusterClient().GetAppInfo().ConfigureAwait(false); + var result = await CreateAppClusterClient().GetAppInfo(); Dump(result); @@ -55,10 +55,10 @@ public async Task GetAppInfo() [Fact] public async Task GetAppsInfo() { - var result = await CreateAppClusterClient().GetAppsInfo().ConfigureAwait(false); + var result = await CreateAppClusterClient().GetAppsInfo(); Assert.NotNull(result); - Assert.NotEmpty(result); result = await CreateAppClusterClient().GetAppsInfo(AppIds).ConfigureAwait(false); + Assert.NotEmpty(result); result = await CreateAppClusterClient().GetAppsInfo(AppIds); Dump(result); @@ -69,7 +69,7 @@ public async Task GetAppsInfo() [Fact] public async Task GetNamespaces() { - var result = await CreateAppClusterClient().GetNamespaces(Env).ConfigureAwait(false); + var result = await CreateAppClusterClient().GetNamespaces(Env); Dump(result); diff --git a/test/Apollo.OpenApi.Tests/NamespaceClientTest.cs b/test/Apollo.OpenApi.Tests/NamespaceClientTest.cs index 2f9fe07..72bc3d2 100644 --- a/test/Apollo.OpenApi.Tests/NamespaceClientTest.cs +++ b/test/Apollo.OpenApi.Tests/NamespaceClientTest.cs @@ -14,7 +14,7 @@ public async Task GetInfo() { var client = CreateNamespaceClient(); - var result = await client.GetNamespaceInfo().ConfigureAwait(false); + var result = await client.GetNamespaceInfo(); Assert.NotNull(result); Assert.Equal(client.AppId, result!.AppId); @@ -33,8 +33,8 @@ public async Task ItemTest() var value1 = Guid.NewGuid().ToString("N"); var value2 = Guid.NewGuid().ToString("N"); - Assert.Null(await client.GetItem(key).ConfigureAwait(false)); - Assert.False(await client.RemoveItem(key, "apollo").ConfigureAwait(false)); + Assert.Null(await client.GetItem(key)); + Assert.False(await client.RemoveItem(key, "apollo")); try { @@ -43,14 +43,14 @@ public async Task ItemTest() Key = key, Value = value1, DataChangeCreatedBy = "apollo" - }).ConfigureAwait(false); + }); Assert.NotNull(item); Assert.NotNull(item.DataChangeLastModifiedTime); Assert.NotNull(item.DataChangeCreatedBy); Assert.Equal(value1, item.Value); - var item2 = await client.GetItem(key).ConfigureAwait(false); + var item2 = await client.GetItem(key); Assert.NotNull(item2); Assert.Equal(value1, item2!.Value); @@ -58,16 +58,16 @@ public async Task ItemTest() item2.Value = value2; item2.DataChangeLastModifiedBy = item2.DataChangeCreatedBy; - await client.UpdateItem(item2).ConfigureAwait(false); + await client.UpdateItem(item2); - item2 = await client.GetItem(key).ConfigureAwait(false); + item2 = await client.GetItem(key); Assert.NotNull(item); Assert.Equal(value2, item!.Value); } catch { - Assert.True(await client.RemoveItem(key, "apollo").ConfigureAwait(false)); + Assert.True(await client.RemoveItem(key, "apollo")); } key = Guid.NewGuid().ToString("N"); @@ -78,21 +78,21 @@ public async Task ItemTest() Key = key, Value = value1, DataChangeCreatedBy = "apollo" - }).ConfigureAwait(false); + }); Assert.NotNull(item); Assert.NotNull(item!.DataChangeLastModifiedTime); Assert.NotNull(item.DataChangeCreatedBy); Assert.Equal(value1, item.Value); - var item2 = await client.GetItem(key).ConfigureAwait(false); + var item2 = await client.GetItem(key); Assert.NotNull(item2); Assert.Equal(value1, item2!.Value); } catch { - Assert.True(await client.RemoveItem(key, "apollo").ConfigureAwait(false)); + Assert.True(await client.RemoveItem(key, "apollo")); } } @@ -108,7 +108,7 @@ public async Task ReleaseTest() ReleaseTitle = $"{DateTime.Now:yyyyMMddHHmmss}-release" }; - var result = await client.Publish(release).ConfigureAwait(false); + var result = await client.Publish(release); Assert.NotNull(result); Assert.Equal(client.AppId, result.AppId); @@ -118,11 +118,11 @@ public async Task ReleaseTest() Assert.NotNull(result.Configurations); Assert.NotEmpty(result.Configurations!); - var latestActiveRelease = await client.GetLatestActiveRelease().ConfigureAwait(false); + var latestActiveRelease = await client.GetLatestActiveRelease(); Assert.NotNull(latestActiveRelease); - await client.Rollback("apollo", latestActiveRelease.Id).ConfigureAwait(false); + await client.Rollback("apollo", latestActiveRelease.Id); } [Fact] @@ -130,7 +130,7 @@ public async Task ItemsTest() { var client = CreateNamespaceClient(); - var result = await client.GetItems().ConfigureAwait(false); + var result = await client.GetItems(); Assert.True(result.Total > 0); diff --git a/test/Apollo.OpenApi.Tests/OpenApiFactoryTest.cs b/test/Apollo.OpenApi.Tests/OpenApiFactoryTest.cs index 3d7969f..33baca4 100644 --- a/test/Apollo.OpenApi.Tests/OpenApiFactoryTest.cs +++ b/test/Apollo.OpenApi.Tests/OpenApiFactoryTest.cs @@ -18,8 +18,7 @@ public async Task ExceptionTest() PortalUrl = new("http://81.68.181.139:8070"), Token = Guid.NewGuid().ToString("N") }) - .CreateAppClusterClient("abc").GetAppInfo() - .ConfigureAwait(false); + .CreateAppClusterClient("abc").GetAppInfo(); } catch (ApolloOpenApiException e) { @@ -33,8 +32,7 @@ public async Task ExceptionTest() PortalUrl = new("http://81.68.181.139:8070"), Token = "c18d0f7bc815c9e2d9699ee3216712a275b20a8d" }) - .CreateAppClusterClient("abc").GetAppInfo() - .ConfigureAwait(false); + .CreateAppClusterClient("abc").GetAppInfo(); } catch (ApolloOpenApiException e) { @@ -49,8 +47,7 @@ public async Task ExceptionTest() Token = "c18d0f7bc815c9e2d9699ee3216712a275b20a8d" }) .CreateNamespaceClient("apollo.net", "PRO", "test", "test") - .GetNamespaceInfo() - .ConfigureAwait(false); + .GetNamespaceInfo(); } catch (ApolloOpenApiException e) { @@ -65,8 +62,7 @@ public async Task ExceptionTest() Token = "c18d0f7bc815c9e2d9699ee3216712a275b20a8d" }) .CreateNamespaceClient("apollo.net", "DEV", "test", "test") - .GetNamespaceInfo() - .ConfigureAwait(false); + .GetNamespaceInfo(); } catch (ApolloOpenApiException e) { diff --git a/test/Apollo.Tests/ConfigServiceLocatorTest.cs b/test/Apollo.Tests/ConfigServiceLocatorTest.cs index 652860d..2699baa 100644 --- a/test/Apollo.Tests/ConfigServiceLocatorTest.cs +++ b/test/Apollo.Tests/ConfigServiceLocatorTest.cs @@ -21,9 +21,9 @@ public async Task MetaServerTest() var locator = new ConfigServiceLocator(new(options), options); - var services = await locator.GetConfigServices().ConfigureAwait(false); + var services = await locator.GetConfigServices(); - Assert.Equal(1, services.Count); + Assert.Single(services); Assert.Equal(options.MetaServer, services[0].HomepageUrl); } @@ -37,9 +37,9 @@ public async Task ConfigServerTest() var locator = new ConfigServiceLocator(new(options), options); - var services = await locator.GetConfigServices().ConfigureAwait(false); + var services = await locator.GetConfigServices(); - Assert.Equal(1, services.Count); + Assert.Single(services); Assert.Equal(options.ConfigServer?.FirstOrDefault(), services[0].HomepageUrl); } } diff --git a/test/Apollo.Tests/ConfigTest.cs b/test/Apollo.Tests/ConfigTest.cs index e8d3166..59c50ac 100644 --- a/test/Apollo.Tests/ConfigTest.cs +++ b/test/Apollo.Tests/ConfigTest.cs @@ -16,7 +16,7 @@ public async Task SingleNamespaceTest() var repositoryFactory = new FakeConfigRepository(ConfigConsts.NamespaceApplication, new(new Dictionary { ["A"] = "3" })); - var config = await CreateConfig(repositoryFactory).ConfigureAwait(false); + var config = await CreateConfig(repositoryFactory); Assert.Equal("3", config.GetProperty("A", "")); @@ -25,7 +25,7 @@ public async Task SingleNamespaceTest() repositoryFactory.Change(new(new Dictionary())); - await Task.Delay(100).ConfigureAwait(false); + await Task.Delay(100); Assert.NotNull(args); } @@ -41,7 +41,7 @@ public async Task MultipleNamespaceTest() new(new Dictionary {["B"] = "4"})), }; - var config = new MultiConfig(await Task.WhenAll(repositoryFactories.Select(CreateConfig).Reverse()).ConfigureAwait(false)); + var config = new MultiConfig(await Task.WhenAll(repositoryFactories.Select(CreateConfig).Reverse())); Assert.Equal("3", config.GetProperty("A", "")); Assert.Equal("4", config.GetProperty("B", "")); @@ -51,7 +51,7 @@ public async Task MultipleNamespaceTest() repositoryFactories[1].Change(new(new Dictionary())); - await Task.Delay(100).ConfigureAwait(false); + await Task.Delay(100); Assert.NotNull(args); @@ -59,7 +59,7 @@ public async Task MultipleNamespaceTest() repositoryFactories[1].Change(new(new Dictionary {["B"] = "3"})); - await Task.Delay(100).ConfigureAwait(false); + await Task.Delay(100); Assert.Null(args); } @@ -88,4 +88,4 @@ public void Change(Properties properties) FireRepositoryChange(Namespace, properties); } } -} \ No newline at end of file +} From 97fd961256bd8940f560e028127f711649c3954c Mon Sep 17 00:00:00 2001 From: pengweiqhca Date: Tue, 16 Apr 2024 10:05:16 +0800 Subject: [PATCH 2/3] Upgrade dotnet sdk version. --- Directory.Build.props | 3 ++- global.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 97d1213..dcd1f0c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,7 +3,7 @@ ..\..\Apollo.snk enable - 10.0 + 12.0 enable True $(NoWarn);CS0414;CS0436;CS1591 @@ -16,6 +16,7 @@ + diff --git a/global.json b/global.json index 3e5d3c5..5f8d7c3 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.100", + "version": "8.0.100", "rollForward": "latestMajor", "allowPrerelease": false } From 4dd04b72e03260caf422c28913e808218198674f Mon Sep 17 00:00:00 2001 From: pengweiqhca Date: Tue, 16 Apr 2024 10:12:25 +0800 Subject: [PATCH 3/3] Modify demo. --- demo/Apollo.AspNetCore.Demo/Program.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/Apollo.AspNetCore.Demo/Program.cs b/demo/Apollo.AspNetCore.Demo/Program.cs index 5048cc6..c26b3b3 100644 --- a/demo/Apollo.AspNetCore.Demo/Program.cs +++ b/demo/Apollo.AspNetCore.Demo/Program.cs @@ -18,11 +18,13 @@ if (string.IsNullOrWhiteSpace(key)) return Task.CompletedTask; var value = context.RequestServices.GetRequiredService()[key]; - if (value != null) context.Response.StatusCode = 200; + if (value == null) return Task.CompletedTask; + + context.Response.StatusCode = 200; context.Response.Headers["Content-Type"] = "text/html; charset=utf-8"; - return context.Response.WriteAsync(value ?? "undefined"); + return context.Response.WriteAsync(value); }); app.Run();