public void SortUnknownFile_NoneRenameType() { /// Description /// Test that the unknown directory is not created when RenameType is None. /// Expectation /// Unknown directory does not exist // Mock IRenameService var renameServiceMock = new Mock <IRenameService>(); // Mock RenameType renameServiceMock.SetupGet(mock => mock.RenameType) .Returns(RenameType.None) .Verifiable(); // Creates a temp directory for testing var outputPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(outputPath); // Generate a temp IConfiguration object var configuration = CreateInMemoryConfiguration(outputPath); // Get the mocked objects var renameService = renameServiceMock.Object; // Construct the sort service and get the output directories structure var sortService = new SortService(logger, configuration, renameService); sortService.SortDateTime("bob.jpg", "bob-the-builder"); // Verify RenameType is called once renameServiceMock.VerifyGet(mock => mock.RenameType, Times.Once); // Assert unknown directory is not created var unknownDirectoryPath = Path.Combine(outputPath, UNKNOWN_DIRNAME); Assert.False(Directory.Exists(unknownDirectoryPath)); }
public void SortDateTime_InvalidDateTimeName_SortAsUnknown() { /// Description: /// Sort a file with invalid datetime name to the unknown output folder. /// Expectation: /// Call renameServiceMock.RenameFile exactly ONCE! // Mock IRenameService var renameServiceMock = new Mock <IRenameService>(); // Creates a temp directory for testing var outputPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(outputPath); // Generate a temp IConfiguration object var configuration = CreateInMemoryConfiguration(outputPath); // Mock the RenameService.RenameFile to create file in unknown directory renameServiceMock.Setup(mock => mock.RenameFile(It.IsAny <string>(), It.IsAny <string>())); // Get the mocked objects var renameService = renameServiceMock.Object; // Construct the sort service and get the output directories structure var sortService = new SortService(logger, configuration, renameService); sortService.SortDateTime("bob.jpg", "bob-the-builder"); // Verify mock method called renameServiceMock.Verify(mock => mock.RenameFile(It.IsAny <string>(), It.IsAny <string>()), Times.Once); // Assert that unknown directory exists var unknownDirectoryPath = Path.Combine(outputPath, UNKNOWN_DIRNAME); Assert.True(Directory.Exists(unknownDirectoryPath)); }