Пример #1
0
        public void ExporterWorksWhenFileIsLocked()
        {
            string resultsDirectoryPath = Path.GetTempPath();
            var    exporter             = new MockExporter();
            var    mockSummary          = GetMockSummary(resultsDirectoryPath);
            var    filePath             = $"{Path.Combine(mockSummary.ResultsDirectoryPath, mockSummary.Title)}-report.txt"; // ExporterBase default

            try
            {
                exporter.ExportToFiles(mockSummary, NullLogger.Instance);

                Assert.Equal(1, exporter.ExportCount);
                Assert.True(File.Exists(filePath));
                using (var handle = File.OpenRead(filePath)) // Gets a lock on the target file
                {
                    exporter.ExportToFiles(mockSummary, NullLogger.Instance);
                    Assert.Equal(2, exporter.ExportCount);
                }
                var savedFiles = Directory.EnumerateFiles(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "*");
                Assert.Equal(2, savedFiles.Count());
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                var otherFiles = Directory.EnumerateFiles(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "*");
                foreach (var file in otherFiles)
                {
                    File.Delete(file);
                }
            }
        }
Пример #2
0
        public void ExporterWritesToFile()
        {
            string resultsDirectoryPath = Path.GetTempPath();
            var    exporter             = new MockExporter();
            var    mockSummary          = GetMockSummary(resultsDirectoryPath);
            var    filePath             = $"{Path.Combine(mockSummary.ResultsDirectoryPath, mockSummary.Title)}-report.txt"; // ExporterBase default

            try
            {
                exporter.ExportToFiles(mockSummary, NullLogger.Instance);

                Assert.Equal(1, exporter.ExportCount);
                Assert.True(File.Exists(filePath));
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }
Пример #3
0
        public void ExporterUsesSummaryTitleAsFileNameWhenBenchmarksJoinedToSingleSummary()
        {
            string resultsDirectoryPath = Path.GetTempPath();
            var    exporter             = new MockExporter();
            var    mockSummary          = GetMockSummary(resultsDirectoryPath, typeof(ClassA), typeof(ClassB));
            var    expectedFilePath     = $"{Path.Combine(mockSummary.ResultsDirectoryPath, mockSummary.Title)}-report.txt";
            string actualFilePath       = null;

            try
            {
                actualFilePath = exporter.ExportToFiles(mockSummary, NullLogger.Instance).First();

                Assert.Equal(expectedFilePath, actualFilePath);
            }
            finally
            {
                if (File.Exists(actualFilePath))
                {
                    File.Delete(actualFilePath);
                }
            }
        }
Пример #4
0
        public void ExporterUsesSimpleTypeNameAsFileNameIfTypeNamesDoNotDuplicate()
        {
            string resultsDirectoryPath = Path.GetTempPath();
            var    exporter             = new MockExporter();
            var    mockSummary          = GetMockSummary(resultsDirectoryPath, typeof(ClassA));
            var    expectedFilePath     = $"{Path.Combine(mockSummary.ResultsDirectoryPath, typeof(ClassA).Name)}-report.txt";
            string actualFilePath       = null;

            try
            {
                actualFilePath = exporter.ExportToFiles(mockSummary, NullLogger.Instance).First();

                Assert.Equal(expectedFilePath, actualFilePath);
            }
            finally
            {
                if (File.Exists(actualFilePath))
                {
                    File.Delete(actualFilePath);
                }
            }
        }
Пример #5
0
        public void ExporterUsesFullyQualifiedTypeNameAsFileName()
        {
            string resultsDirectoryPath = Path.GetTempPath();
            var    exporter             = new MockExporter();
            var    mockSummary          = GetMockSummary(resultsDirectoryPath, config: null, typeof(Generic <int>));
            var    expectedFilePath     = $"{Path.Combine(mockSummary.ResultsDirectoryPath, "BenchmarkDotNet.IntegrationTests.Generic_Int32_")}-report.txt";
            string actualFilePath       = null;

            try
            {
                actualFilePath = exporter.ExportToFiles(mockSummary, NullLogger.Instance).First();

                Assert.Equal(expectedFilePath, actualFilePath);
            }
            finally
            {
                if (File.Exists(actualFilePath))
                {
                    File.Delete(actualFilePath);
                }
            }
        }