|
1 | | -using Azure.Sdk.Tools.TestProxy.Common; |
| 1 | +using Azure.Sdk.Tools.TestProxy.Common; |
| 2 | +using Azure.Sdk.Tools.TestProxy.Matchers; |
2 | 3 | using Azure.Sdk.Tools.TestProxy.Models; |
3 | 4 | using Azure.Sdk.Tools.TestProxy.Sanitizers; |
| 5 | +using Azure.Sdk.Tools.TestProxy.Transforms; |
4 | 6 | using Microsoft.AspNetCore.Http; |
5 | 7 | using Microsoft.AspNetCore.Mvc; |
6 | 8 | using System; |
@@ -58,5 +60,36 @@ public void TestReflectionModelWithAdvancedType() |
58 | 60 |
|
59 | 61 | var result = controller.Active(); |
60 | 62 | } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public async Task TestReflectionModelWithTargetRecordSession() |
| 66 | + { |
| 67 | + RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory()); |
| 68 | + var httpContext = new DefaultHttpContext(); |
| 69 | + |
| 70 | + await testRecordingHandler.StartPlaybackAsync("Test.RecordEntries/multipart_request.json", httpContext.Response); |
| 71 | + testRecordingHandler.Transforms.Clear(); |
| 72 | + |
| 73 | + var recordingId = httpContext.Response.Headers["x-recording-id"].ToString(); |
| 74 | + |
| 75 | + testRecordingHandler.AddSanitizerToRecording(recordingId, new UriRegexSanitizer(regex: "ABC123")); |
| 76 | + testRecordingHandler.AddSanitizerToRecording(recordingId, new BodyRegexSanitizer(regex: ".+?")); |
| 77 | + testRecordingHandler.SetMatcherForRecording(recordingId, new CustomDefaultMatcher(compareBodies: false, excludedHeaders: "an-excluded-header")); |
| 78 | + |
| 79 | + var model = new ActiveMetadataModel(testRecordingHandler, recordingId); |
| 80 | + var descriptions = model.Descriptions.ToList(); |
| 81 | + |
| 82 | + // we should have exactly 6 if we're counting all the customizations appropriately |
| 83 | + Assert.True(descriptions.Count == 6); |
| 84 | + Assert.True(model.Matchers.Count() == 1); |
| 85 | + Assert.True(model.Sanitizers.Count() == 5); |
| 86 | + |
| 87 | + // confirm that the overridden matcher is showing up |
| 88 | + Assert.True(descriptions[3].ConstructorDetails.Arguments[1].Item2 == "\"ABC123\""); |
| 89 | + Assert.True(descriptions[4].ConstructorDetails.Arguments[1].Item2 == "\".+?\""); |
| 90 | + |
| 91 | + // and finally confirm our sanitizers are what we expect |
| 92 | + Assert.True(descriptions[5].Name == "CustomDefaultMatcher"); |
| 93 | + } |
61 | 94 | } |
62 | 95 | } |
0 commit comments