Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Benchmarks/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<PackageVersion Include="ServiceModel.Grpc.ProtoBufMarshaller" Version="$(ServiceModelGrpcVersion)" />

<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />
<PackageVersion Include="MagicOnion" Version="7.10.1" />
<PackageVersion Include="MagicOnion.Server" Version="7.10.1" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.9" />
<PackageVersion Include="protobuf-net.Grpc" Version="1.2.2" />
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.2.2" />
<PackageVersion Include="MagicOnion" Version="7.10.2" />
<PackageVersion Include="MagicOnion.Server" Version="7.10.2" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.11" />
<PackageVersion Include="protobuf-net.Grpc" Version="1.3.14" />
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.3.14" />
<PackageVersion Include="System.ServiceModel.Primitives" Version="10.0.652802" />
</ItemGroup>
</Project>
26 changes: 13 additions & 13 deletions Examples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
<PackageVersion Include="Grpc.Tools" Version="2.83.0" />
<PackageVersion Include="Google.Protobuf" Version="3.36.0" />

<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.9" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.19.1" />

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.11" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.22.0" />

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.11" />

<PackageVersion Include="System.ServiceModel.Primitives" Version="10.0.652802" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.9" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.11" />
<PackageVersion Include="Shouldly" Version="4.3.0" />

<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.2.3" />
Expand Down
6 changes: 3 additions & 3 deletions Sources/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Mono.Reflection" Version="2.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nerdbank.MessagePack" Version="1.3.85" />
<PackageVersion Include="NSwag.AspNetCore" Version="14.7.1" />
<PackageVersion Include="NUnit" Version="4.6.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.3.0" />
<PackageVersion Include="protobuf-net" Version="3.4.19" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="10.2.3" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.2.3" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.2.3" />
<PackageVersion Include="System.Reflection.Emit" Version="4.7.0" />
<PackageVersion Include="System.Threading.Channels" Version="10.0.9" />
<PackageVersion Include="System.Threading.Channels" Version="10.0.11" />
</ItemGroup>
</Project>
25 changes: 9 additions & 16 deletions Sources/ServiceModel.Grpc.AspNetCore.TestApi/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@
// </copyright>

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<OpenApiDocument> DownloadAsync(string location)
{
JObject content;
JsonElement content;

using (var client = new HttpClient())
{
Expand All @@ -41,29 +40,23 @@ public static async Task<OpenApiDocument> 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<JsonElement>(stream);
}
}
}

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<JObject>("paths")!.Value<JObject>(endpoint)!.Value<JObject>("post")!;

post.ShouldNotBeNull(endpoint);
var body = Content.GetProperty("paths").GetProperty(endpoint).GetProperty("post").GetProperty("requestBody");

var body = post.Value<JObject>("requestBody");
var contentType = body?.Value<JObject>("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;
}
}
11 changes: 4 additions & 7 deletions Sources/ServiceModel.Grpc.AspNetCore.TestApi/SwaggerUiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// </copyright>

using System.Net.Http.Headers;
using Newtonsoft.Json;
using System.Text.Json;

namespace ServiceModel.Grpc.AspNetCore.TestApi;

Expand Down Expand Up @@ -49,8 +49,8 @@ public async Task<T> InvokeAsync<T>(string methodName, IDictionary<string, objec

response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return JsonSerializer.CreateDefault().Deserialize<T>(new JsonTextReader(new StreamReader(content)))!;
await using var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return JsonSerializer.Deserialize<T>(content)!;
}

public async Task<HttpResponseMessage> PostAsync(string methodName, IDictionary<string, object>? parameters = null, IDictionary<string, string>? headers = null)
Expand All @@ -62,10 +62,7 @@ public async Task<HttpResponseMessage> 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// <copyright>
// 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.
// </copyright>

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<Version> Collect(string referenceName)
{
const string prefix = "ServiceModel.Grpc.DesignTime";

var queue = new Queue<string>();
queue.Enqueue($"{prefix}.Generators");

var result = new HashSet<Version>();
var processed = new HashSet<string>(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);
}
}
}

This file was deleted.