Skip to content

Commit

Permalink
ensure that the mismatch test throws the expected message
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd committed Oct 25, 2023
1 parent 20e39b3 commit 6da35fa
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Xunit;
using System.Text.Json;
using Azure.Sdk.Tools.TestProxy.Store;
using System.Text;

namespace Azure.Sdk.Tools.TestProxy.Tests
{
Expand Down Expand Up @@ -260,6 +261,41 @@ public async Task TestPlaybackWithGZippedContentPlayback()
}


[Fact]
public async Task TestPlaybackWithGZippedContentPlaybackMismatch()
{
RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
var httpContext = new DefaultHttpContext();
var body = "{\"x-recording-file\":\"Test.RecordEntries/request_response_with_gzipped_content.json\"}";
httpContext.Request.Body = TestHelpers.GenerateStreamRequestBody(body);
httpContext.Request.ContentLength = body.Length;

var controller = new Playback(testRecordingHandler, new NullLoggerFactory())
{
ControllerContext = new ControllerContext()
{
HttpContext = httpContext
}
};
await controller.Start();

var recordingId = httpContext.Response.Headers["x-recording-id"].ToString();
Assert.False(String.IsNullOrEmpty(recordingId));
Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(recordingId));
var entry = testRecordingHandler.PlaybackSessions[recordingId].Session.Entries[0];
HttpRequest request = TestHelpers.CreateRequestFromEntry(entry);

var mismatchBodyBytes = Encoding.UTF8.GetBytes("{{\u0022TableNam\u0022: \u0022listtable09bf2a3d\u0022}");

// compress the body to simulate what the request coming from the library will look like
request.Body = new MemoryStream(CompressionUtilities.CompressBody(mismatchBodyBytes, request.Headers));
HttpResponse response = new DefaultHttpContext().Response;

var assertion = await Assert.ThrowsAsync<TestRecordingMismatchException>(
async () => await testRecordingHandler.HandlePlaybackRequest(recordingId, request, response)
);
}

[Theory]
[InlineData(
@"{
Expand Down

0 comments on commit 6da35fa

Please sign in to comment.