From 3bcd0baf8c3a12093d7f0faedce55b5efc968fd7 Mon Sep 17 00:00:00 2001 From: max-ieremenko <> Date: Sun, 30 Aug 2026 12:00:11 +0200 Subject: [PATCH] update internal dependencies --- Benchmarks/Directory.Packages.props | 10 +-- Examples/Directory.Packages.props | 26 +++--- Sources/Directory.Packages.props | 6 +- .../OpenApiDocument.cs | 25 ++---- .../SwaggerUiClient.cs | 11 +-- .../DependenciesTest.cs | 88 +++++++++++++++++++ .../DependenciesTest.txt | 39 -------- 7 files changed, 122 insertions(+), 83 deletions(-) create mode 100644 Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.cs delete mode 100644 Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.txt diff --git a/Benchmarks/Directory.Packages.props b/Benchmarks/Directory.Packages.props index b4cfc82c..f06366e6 100644 --- a/Benchmarks/Directory.Packages.props +++ b/Benchmarks/Directory.Packages.props @@ -8,11 +8,11 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Examples/Directory.Packages.props b/Examples/Directory.Packages.props index e270818a..a1335ffd 100644 --- a/Examples/Directory.Packages.props +++ b/Examples/Directory.Packages.props @@ -26,21 +26,21 @@ - - - - - - - - - - - - + + + + + + + + + + + + - + diff --git a/Sources/Directory.Packages.props b/Sources/Directory.Packages.props index 4dbffde1..da190ca0 100644 --- a/Sources/Directory.Packages.props +++ b/Sources/Directory.Packages.props @@ -18,14 +18,14 @@ - + - + @@ -33,6 +33,6 @@ - + \ No newline at end of file diff --git a/Sources/ServiceModel.Grpc.AspNetCore.TestApi/OpenApiDocument.cs b/Sources/ServiceModel.Grpc.AspNetCore.TestApi/OpenApiDocument.cs index 4b476339..b09be616 100644 --- a/Sources/ServiceModel.Grpc.AspNetCore.TestApi/OpenApiDocument.cs +++ b/Sources/ServiceModel.Grpc.AspNetCore.TestApi/OpenApiDocument.cs @@ -15,24 +15,23 @@ // using System.Net.Mime; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json; using Shouldly; namespace ServiceModel.Grpc.AspNetCore.TestApi; public class OpenApiDocument { - public OpenApiDocument(JObject content) + public OpenApiDocument(JsonElement content) { Content = content; } - public JObject Content { get; } + public JsonElement Content { get; } public static async Task DownloadAsync(string location) { - JObject content; + JsonElement content; using (var client = new HttpClient()) { @@ -41,7 +40,7 @@ public static async Task DownloadAsync(string location) response.EnsureSuccessStatusCode(); using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) { - content = (JObject)JsonSerializer.CreateDefault().Deserialize(new JsonTextReader(new StreamReader(stream)))!; + content = JsonSerializer.Deserialize(stream); } } } @@ -49,21 +48,15 @@ public static async Task DownloadAsync(string location) return new OpenApiDocument(content); } - public string GetEndpoint(string serviceName, string methodName) - { - return string.Format("/{0}/{1}", serviceName, methodName); - } + public string GetEndpoint(string serviceName, string methodName) => $"/{serviceName}/{methodName}"; public string GetRequestContentType(string endpoint) { - var post = Content.Value("paths")!.Value(endpoint)!.Value("post")!; - - post.ShouldNotBeNull(endpoint); + var body = Content.GetProperty("paths").GetProperty(endpoint).GetProperty("post").GetProperty("requestBody"); - var body = post.Value("requestBody"); - var contentType = body?.Value("content")!.Properties().First().Name; + var contentType = body.GetProperty("content").EnumerateObject().First().Name; contentType.ShouldBe(MediaTypeNames.Application.Json + "+servicemodel.grpc", "Body is empty or content type is not set."); - return contentType!; + return contentType; } } \ No newline at end of file diff --git a/Sources/ServiceModel.Grpc.AspNetCore.TestApi/SwaggerUiClient.cs b/Sources/ServiceModel.Grpc.AspNetCore.TestApi/SwaggerUiClient.cs index 0d6a8ecb..5dc177b5 100644 --- a/Sources/ServiceModel.Grpc.AspNetCore.TestApi/SwaggerUiClient.cs +++ b/Sources/ServiceModel.Grpc.AspNetCore.TestApi/SwaggerUiClient.cs @@ -15,7 +15,7 @@ // using System.Net.Http.Headers; -using Newtonsoft.Json; +using System.Text.Json; namespace ServiceModel.Grpc.AspNetCore.TestApi; @@ -49,8 +49,8 @@ public async Task InvokeAsync(string methodName, IDictionary(new JsonTextReader(new StreamReader(content)))!; + await using var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + return JsonSerializer.Deserialize(content)!; } public async Task PostAsync(string methodName, IDictionary? parameters = null, IDictionary? headers = null) @@ -62,10 +62,7 @@ public async Task PostAsync(string methodName, IDictionary< using var client = new HttpClient(); using var requestBody = new MemoryStream(); - using (var writer = new StreamWriter(requestBody, leaveOpen: true)) - { - JsonSerializer.CreateDefault().Serialize(writer, parameters); - } + await JsonSerializer.SerializeAsync(requestBody, parameters).ConfigureAwait(false); HttpResponseMessage response; diff --git a/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.cs b/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.cs new file mode 100644 index 00000000..4ecd5a9b --- /dev/null +++ b/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.cs @@ -0,0 +1,88 @@ +// +// Copyright Max Ieremenko +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; +using NUnit.Framework; + +namespace ServiceModel.Grpc.DesignTime.Generator.Test; + +// https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/10.0/asyncenumerable +[TestFixture] +public class DependenciesTest +{ + [Test(Description = "#423: compile with VS2022")] + public void System_Memory() + { + var versions = Collect("System.Memory"); + versions.ShouldBe([new("4.0.1.1")]); + } + + private static HashSet Collect(string referenceName) + { + const string prefix = "ServiceModel.Grpc.DesignTime"; + + var queue = new Queue(); + queue.Enqueue($"{prefix}.Generators"); + + var result = new HashSet(); + var processed = new HashSet(StringComparer.OrdinalIgnoreCase); + + while (queue.TryDequeue(out var next)) + { + if (!processed.Add(next)) + { + continue; + } + + foreach (var reference in GetReferences($"{next}.dll")) + { + if (reference.Name.Equals(referenceName, StringComparison.OrdinalIgnoreCase)) + { + result.Add(reference.Version); + continue; + } + + if (reference.Name.Contains(prefix, StringComparison.OrdinalIgnoreCase)) + { + queue.Enqueue(reference.Name); + } + } + } + + return result; + } + + private static IEnumerable<(string Name, Version Version)> GetReferences(string peFile) + { + var path = Path.Combine(AppContext.BaseDirectory, peFile); + if (!File.Exists(path)) + { + yield break; + } + + using var stream = File.OpenRead(path); + using var reader = new PEReader(stream); + + var metadataReader = reader.GetMetadataReader(); + foreach (var item in metadataReader.AssemblyReferences) + { + var reference = metadataReader.GetAssemblyReference(item); + var name = metadataReader.GetString(reference.Name); + yield return (name, reference.Version); + } + } +} \ No newline at end of file diff --git a/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.txt b/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.txt deleted file mode 100644 index ef781d48..00000000 --- a/Sources/ServiceModel.Grpc.DesignTime.Generator.Test/DependenciesTest.txt +++ /dev/null @@ -1,39 +0,0 @@ -// -// Copyright Max Ieremenko -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; -using NUnit.Framework; - -namespace ServiceModel.Grpc.DesignTime.Generator.Test; - -[TestFixture] -public class DependenciesTest -{ - [Test] - public void Test() - { - var path = Path.Combine(AppContext.BaseDirectory, "ServiceModel.Grpc.DesignTime.Generators.dll"); - var reader = new PEReader(File.OpenRead(path)); - var test = reader.GetMetadataReader(); - foreach (var item in test.AssemblyReferences) - { - var reference = test.GetAssemblyReference(item); - var name = test.GetString(reference.Name); - Console.WriteLine($"{name} {reference.Version}"); - } - } -} \ No newline at end of file