Example #1
0
        public async Task UniqueTimestampFileNameGenerated_When_NoLogExists()
        {
            // Arrange
            var logs = LogFactory.Create(2);

            _logRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(logs));
            _directoryProvider.Setup(x => x.DoesDirectoryExists(It.IsAny <string>())).Returns(true);
            _dateTimeProvider.Setup(x => x.GetCurrentTime()).Returns(new DateTime(1989, 10, 28, 21, 21, 5, 999));
            _pathProvider.Setup(x => x.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns((string path1, string filePath) => Path.Combine(path1, filePath));
            _fileProvider.Setup(x => x.WriteAllText(It.IsAny <string>(), It.IsAny <string>())).Callback((string filePath, string content) => File.WriteAllText(filePath, content));
            string dumpFileLocation        = DirectoryFactory.CreateTestDirectory();
            var    exceptionLogDumpCreator = new DistributeLogDumpCreator(
                _logRepositoryMock.Object,
                _dateTimeProvider.Object,
                _fileProvider.Object,
                _directoryProvider.Object,
                _pathProvider.Object,
                _consoleProvider.Object,
                _reflectionProvider.Object);

            // Act
            string dumpFile = await exceptionLogDumpCreator.CreateDumpAsync(dumpFileLocation);

            // Assert
            string expectedDumpFileName = "10-28-1989-09-21-05-9990.txt";

            Assert.That(new FileInfo(dumpFile).Name, Is.EqualTo(expectedDumpFileName));
        }
Example #2
0
        public async Task TwoLogWrittenInFile_When_TwoLogExist()
        {
            // Arrange
            var logs = LogFactory.Create(2);

            _logRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(logs));
            _directoryProvider.Setup(x => x.DoesDirectoryExists(It.IsAny <string>())).Returns(true);
            _dateTimeProvider.Setup(x => x.GetCurrentTime()).Returns(DateTime.Now);
            _pathProvider.Setup(x => x.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns((string path1, string filePath) => Path.Combine(path1, filePath));
            _fileProvider.Setup(x => x.WriteAllText(It.IsAny <string>(), It.IsAny <string>())).Callback((string filePath, string content) => File.WriteAllText(filePath, content));
            string dumpFileLocation        = DirectoryFactory.CreateTestDirectory();
            var    exceptionLogDumpCreator = new DistributeLogDumpCreator(
                _logRepositoryMock.Object,
                _dateTimeProvider.Object,
                _fileProvider.Object,
                _directoryProvider.Object,
                _pathProvider.Object,
                _consoleProvider.Object,
                _reflectionProvider.Object);

            // Act
            string dumpFile = await exceptionLogDumpCreator.CreateDumpAsync(dumpFileLocation);

            // Assert
            string dumpFileContent = File.ReadAllText(dumpFile);
            string expectedContent = GetExpectedDumpFileContent(logs);

            Assert.That(dumpFileContent, Is.EqualTo(expectedContent));
        }
Example #3
0
        public void ReturnCorrectFilePaths()
        {
            // Arrange
            string newFolder          = DirectoryFactory.CreateTestDirectory();
            string firstFile          = FileFactory.CreateTestFile(newFolder, null, string.Empty);
            string secondFile         = FileFactory.CreateTestFile(newFolder, null, string.Empty);
            var    expectedCollection = new[] { firstFile, secondFile };
            var    directoryProvider  = new DirectoryProvider();

            // Act
            var files = directoryProvider.GetFiles(newFolder);

            // Assert
            Assert.That(files, Is.EquivalentTo(expectedCollection));
        }
        public void ReturnTrue_When_FolderExists()
        {
            // Arrange
            string newFolder         = DirectoryFactory.CreateTestDirectory();
            var    directoryProvider = new DirectoryProvider();

            // Act
            bool doesFolderExists = directoryProvider.DoesDirectoryExists(newFolder);

            // Assert
            Assert.That(doesFolderExists, Is.True);

            // Clean-up
            Directory.Delete(newFolder);
        }