mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 23:41:19 +02:00
1.7.x (#1268)
* Fix construction of path in OpenApiParser (#1265) * Server-Sent Events (#1269) * Server Side Events * fixes * await HandleSseStringAsync(responseMessage, response, bodyData); * 1.7.5-preview-01 * IBlockingQueue * 1.7.5-preview-02 (03 April 2025) * IBlockingQueue * ... * Support OpenApi V31 (#1279) * Support OpenApi V31 * Update src/WireMock.Net.OpenApiParser/Extensions/OpenApiSchemaExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fx --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add ProtoDefinitionHelper.FromDirectory (#1263) * Add ProtoDefinitionHelper.FromDirectory * . * unix-windows * move test * imports in the proto files indeed should use a forward slash * updates * . * private Func<IdOrTexts> ProtoDefinitionFunc() * OpenTelemetry * . * fix path utils --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
73
test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs
Normal file
73
test/WireMock.Net.Tests/Grpc/ProtoDefinitionHelperTests.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#if PROTOBUF
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Grpc;
|
||||
|
||||
public class ProtoDefinitionHelperTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task FromDirectory_Greet_ShouldReturnModifiedProtoFiles()
|
||||
{
|
||||
// Arrange
|
||||
var directory = Path.Combine(Directory.GetCurrentDirectory(), "Grpc", "Test");
|
||||
var expectedFilename = "SubFolder/request.proto";
|
||||
var expectedComment = $"// {expectedFilename}";
|
||||
|
||||
// Act
|
||||
var protoDefinitionData = await ProtoDefinitionHelper.FromDirectory(directory);
|
||||
var protoDefinitions = protoDefinitionData.ToList("greet");
|
||||
|
||||
// Assert
|
||||
protoDefinitions.Should().HaveCount(2);
|
||||
protoDefinitions[0].Should().StartWith("// greet.proto");
|
||||
protoDefinitions[1].Should().StartWith(expectedComment);
|
||||
|
||||
// Arrange
|
||||
var resolver = new WireMockProtoFileResolver(protoDefinitions);
|
||||
|
||||
// Act + Assert
|
||||
resolver.Exists(expectedFilename).Should().BeTrue();
|
||||
resolver.Exists("x").Should().BeFalse();
|
||||
|
||||
// Act + Assert
|
||||
var text = await resolver.OpenText(expectedFilename).ReadToEndAsync();
|
||||
text.Should().StartWith(expectedComment);
|
||||
System.Action action = () => resolver.OpenText("x");
|
||||
action.Should().Throw<FileNotFoundException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FromDirectory_OpenTelemetry_ShouldReturnModifiedProtoFiles()
|
||||
{
|
||||
// Arrange
|
||||
var directory = Path.Combine(Directory.GetCurrentDirectory(), "Grpc", "ot");
|
||||
|
||||
// Act
|
||||
var protoDefinitionData = await ProtoDefinitionHelper.FromDirectory(directory);
|
||||
var protoDefinitions = protoDefinitionData.ToList("trace_service");
|
||||
|
||||
// Assert
|
||||
protoDefinitions.Should().HaveCount(10);
|
||||
|
||||
var responseBytes = await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(
|
||||
protoDefinitions,
|
||||
"OpenTelemetry.Proto.Collector.Trace.V1.ExportTracePartialSuccess",
|
||||
new
|
||||
{
|
||||
rejected_spans = 1,
|
||||
error_message = "abc"
|
||||
}
|
||||
);
|
||||
|
||||
// Assert
|
||||
Convert.ToBase64String(responseBytes).Should().Be("AAAAAAcIARIDYWJj");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user