Esempio n. 1
0
        public void WriteContentFile_writes_an_empty_file_to_disk_if_content_is_null()
        {
            ITraceFileWriter sut = new TraceFileWriter();
            var content          = new byte[] { 65, 66, 67 };

            sut.WriteContentFile("test.content.txt", null);

            Thread.Sleep(100);             // File write is async

            File.ReadAllText("test.content.txt", Encoding.ASCII).Should().BeEmpty();

            File.Delete("test.content.txt");
        }
Esempio n. 2
0
        public void WriteContentFile_writes_a_file_to_disk_that_contains_the_content()
        {
            ITraceFileWriter sut = new TraceFileWriter();
            var content          = new byte[] { 65, 66, 67 };

            sut.WriteContentFile("test.content.txt", content);

            Thread.Sleep(100);             // File write is async

            File.ReadAllText("test.content.txt", Encoding.ASCII).Should().Be("ABC");

            File.Delete("test.content.txt");
        }
Esempio n. 3
0
        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.WriteHeaderFileAsync("test.header.txt", headers);

            var sut    = new TraceFileReader();
            var result = sut.ReadHeaderFileAsync("test.header.txt").Result;

            result.Should().BeEquivalentTo(headers);

            File.Delete("test.header.txt");
        }
        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, CreateDummyConfiguration(), loggerMock.Object);
            const string        filePrefix1 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831637";
            const string        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.WriteHeaderFileAsync("tracefiles/" + filePrefix1 + ".ct.headers", clientHeaders);

            await traceFileWriter.WriteHeaderFileAsync("tracefiles/" + filePrefix1 + ".optt.headers", onPremiseTargetHeaders);

            await traceFileWriter.WriteHeaderFileAsync("tracefiles/" + filePrefix2 + ".crxxxxxxx.headers", clientHeaders);

            await traceFileWriter.WriteHeaderFileAsync("tracefiles/" + filePrefix2 + ".ltrxxxxxxx.headers", onPremiseTargetHeaders);

            loggerMock.Setup(l => l.Warning <string>(It.IsAny <FileNotFoundException>(), It.IsAny <string>(), It.IsAny <string>()));

            result = await sut.GetTracesAsync(Guid.Parse("7975999f-54d9-4b21-a093-4502ea372723"));

            Directory.Delete("tracefiles", true);

            loggerMock.Verify(m => m.Warning(It.IsAny <FileNotFoundException>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2));
            result.Count().Should().Be(1);
        }
Esempio n. 5
0
        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");
        }
        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, CreateDummyConfiguration(), null);
            const string        filePrefix1 = "7975999f-54d9-4b21-a093-4502ea372723-635497418466831637";
            const string        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.WriteHeaderFileAsync("tracefiles/" + filePrefix1 + ".ct.headers", clientHeaders);

            await traceFileWriter.WriteHeaderFileAsync("tracefiles/" + filePrefix1 + ".optt.headers", onPremiseTargetHeaders);

            await traceFileWriter.WriteHeaderFileAsync("tracefiles/" + filePrefix2 + ".ct.headers", clientHeaders);

            await traceFileWriter.WriteHeaderFileAsync("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);
        }