mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 22:33:35 +01:00
* Create WireMock.Net.ProtoBuf project * ok * Update Directory.Build.props Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
75 lines
2.3 KiB
C#
75 lines
2.3 KiB
C#
// 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
|
|
{
|
|
private static readonly IProtoBufUtils ProtoBufUtils = new ProtoBufUtils();
|
|
|
|
[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 ProtoDefinitionDataHelper.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 ProtoDefinitionDataHelper.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 |