public void BodyStringSanitizerIgnoresNonTextualBodies() { var session = TestHelpers.LoadRecordSession("Test.RecordEntries/request_with_binary_content.json"); var targetEntry = session.Session.Entries[0]; var content = Encoding.UTF8.GetString(targetEntry.Request.Body); var bodyStringSanitizer = new BodyStringSanitizer("content"); session.Session.Sanitize(bodyStringSanitizer); Assert.Equal(content, Encoding.UTF8.GetString(targetEntry.Request.Body)); }
public void BodyStringSanitizerApplies(string targetValue, string replacementValue, string recordingFile) { var session = TestHelpers.LoadRecordSession(recordingFile); var targetEntry = session.Session.Entries[0]; var originalBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body); var sanitizer = new BodyStringSanitizer(targetValue, value: replacementValue); session.Session.Sanitize(sanitizer); var resultBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body); Assert.NotEqual(originalBodyValue, resultBodyValue); Assert.Contains(replacementValue, resultBodyValue); Assert.DoesNotContain(targetValue, resultBodyValue); }
public void BodyStringSanitizerQuietlyExits(string targetValue, string replacementValue, string recordingFile) { var session = TestHelpers.LoadRecordSession(recordingFile); var untouchedSession = TestHelpers.LoadRecordSession(recordingFile); var targetEntry = session.Session.Entries[0]; var originalBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body); var targetUntouchedEntry = untouchedSession.Session.Entries[0]; var matcher = new RecordMatcher(); var sanitizer = new BodyStringSanitizer(targetValue, value: replacementValue); session.Session.Sanitize(sanitizer); var resultBodyValue = Encoding.UTF8.GetString(targetEntry.Request.Body); Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Request.Body, targetEntry.Request.Body)); Assert.Equal(0, matcher.CompareBodies(targetUntouchedEntry.Response.Body, targetEntry.Response.Body)); }