public void ThrowArgumentException_When_DumpLocationDoesNotExist() { // Arrange var logs = LogFactory.Create(2); _logRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(logs)); _directoryProvider.Setup(x => x.DoesDirectoryExists(It.IsAny <string>())).Returns(false); _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)); var exceptionLogDumpCreator = new DistributeLogDumpCreator( _logRepositoryMock.Object, _dateTimeProvider.Object, _fileProvider.Object, _directoryProvider.Object, _pathProvider.Object, _consoleProvider.Object, _reflectionProvider.Object); // Act string dumpLocation = Guid.NewGuid().ToString(); // Assert Assert.Throws <ArgumentException>(() => exceptionLogDumpCreator.CreateDumpAsync(dumpLocation).Wait(), string.Format("The specified dump location '{0}' does not exist.", dumpLocation)); }
public async Task OneLogWrittenInFile_When_OneLogExists() { // Arrange var logs = LogFactory.Create(1); _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)); }
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)); }