public async Task GetTraceFilesAsync_catches_errors_when_reading_a_file_and_logs_them() { var loggerMock = new Mock <ILogger>(); var traceFileReaderMock = new Mock <TraceFileReader>() { CallBase = true }; var sut = new TraceManager(null, null, traceFileReaderMock.Object, new Configuration(), loggerMock.Object); var filePrefix1 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831637"; var filePrefix2 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831700"; IEnumerable <Trace> result; var clientHeaders = new Dictionary <string, string>() { { "Content-Type", "text/plain" }, { "Content-Length", "0" } }; var onPremiseTargetHeaders = new Dictionary <string, string>() { { "Content-Type", "image/png" }, { "Content-Length", "500" } }; Directory.CreateDirectory("tracefiles"); var traceFileWriter = new TraceFileWriter(); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix1 + ".ct.headers", clientHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix1 + ".optt.headers", onPremiseTargetHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix2 + ".crxxxxxxx.headers", clientHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix2 + ".ltrxxxxxxx.headers", onPremiseTargetHeaders); loggerMock.Setup(l => l.Warn(It.IsAny <string>(), It.IsAny <Exception>())); result = await sut.GetTracesAsync(Guid.Parse("7975999f-54d9-4b21-a093-4502ea372723")); Directory.Delete("tracefiles", true); loggerMock.VerifyAll(); result.Count().Should().Be(1); }
public async Task GetTraceFilesAsync_returns_file_info_objects_for_all_trace_files_of_a_given_prefix() { var traceFileReaderMock = new Mock <TraceFileReader>() { CallBase = true }; var sut = new TraceManager(null, null, traceFileReaderMock.Object, new Configuration(), null); var filePrefix1 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831637"; var filePrefix2 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831700"; IEnumerable <Trace> result; var clientHeaders = new Dictionary <string, string>() { { "Content-Type", "text/plain" }, { "Content-Length", "0" } }; var onPremiseTargetHeaders = new Dictionary <string, string>() { { "Content-Type", "image/png" }, { "Content-Length", "500" } }; Directory.CreateDirectory("tracefiles"); var traceFileWriter = new TraceFileWriter(); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix1 + ".ct.headers", clientHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix1 + ".optt.headers", onPremiseTargetHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix2 + ".ct.headers", clientHeaders); await traceFileWriter.WriteHeaderFile("tracefiles/" + filePrefix2 + ".optt.headers", onPremiseTargetHeaders); result = await sut.GetTracesAsync(Guid.Parse("7975999f-54d9-4b21-a093-4502ea372723")); Directory.Delete("tracefiles", true); result.Count().Should().Be(2); }
public async Task Can_read_headers_from_header_file() { var traceFileWriter = new TraceFileWriter(); var headers = new Dictionary <string, string>() { { "Content-Length", "1000" }, { "Content-Type", "text/plain" } }; await traceFileWriter.WriteHeaderFile("test.header.txt", headers); var sut = new TraceFileReader(); var result = sut.ReadHeaderFileAsync("test.header.txt").Result; result.ShouldBeEquivalentTo(headers); File.Delete("test.header.txt"); }
public void WriteHeaderFile_writes_a_file_to_disk_that_contains_the_headers_as_json() { ITraceFileWriter sut = new TraceFileWriter(); IDictionary <string, string> headers = new Dictionary <string, string> { { "Content-Disposition", "attachment" }, { "Content-Length", "3" }, { "X-TTRELAY-TIMEOUT", "OnPremise" }, }; sut.WriteHeaderFile("test.headers.txt", headers); Thread.Sleep(100); // File write is async var referenceObject = JsonConvert.DeserializeObject <IDictionary <string, string> >(File.ReadAllText("test.headers.txt", Encoding.UTF8)); referenceObject.ShouldBeEquivalentTo(headers); File.Delete("test.headers.txt"); }