Exemplo n.º 1
0
        public void TrySave_Test_ReturnsTrueForSuccessfulSave()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();

                var saveResult = _systemFile.TrySave();

                Assert.IsTrue(saveResult);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 2
0
        public void Equals_Test_ReturnsTrueGivenEqualSystemFile()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                var systemFile1 = GetSystemFile();
                var systemFile2 = GetSystemFile();

                var areEqual = systemFile1.Equals(systemFile2);

                Assert.IsTrue(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 3
0
        public void Equals_Test_ReturnsTrueGivenEqualMetadataFiles()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.originalFilepath);
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.copyOfOriginalFilepath);

                var metadataFile1 = GetMetadataFile();
                var metadataFile2 = GetMetadataFile(FileTestSharedVariables.copyOfOriginalFilepath);

                Assert.IsTrue(metadataFile1.Equals(metadataFile2));
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
        public void DeleteEmptyFolders_Test_EmptyFoldersAreDeleted()
        {
            try
            {
                string testDirectory = FileTestSharedVariables.baseTestDirectory;
                Directory.CreateDirectory(testDirectory);

                FileManipulator.DeleteEmptyFolders(new DirectoryInfo(testDirectory));

                bool deletionSuccessful = !Directory.Exists(testDirectory);
                Assert.IsTrue(deletionSuccessful);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 5
0
        public void Constructor_Test_PopulatesBasicFieldsGivenValidFilepath()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                var metadataFile = GetMetadataFile();
                var properties   = ExtractProperties(metadataFile);

                bool hasEmptyValues = properties.Any(pair => string.IsNullOrEmpty(pair.Value));

                Assert.IsFalse(hasEmptyValues);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 6
0
        public void TrySave_Test_ReturnsFalseForFailedSave()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Artist = exceedsMaxCharString;

                var saveResult = _systemFile.TrySave();

                Assert.IsFalse(saveResult);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
        public void DeleteEmptyFolders_Test_EmptyParentFolderGetsDeletedWhenNoFilesExistInSingleSubdirector()
        {
            try
            {
                string testDirectory = Path.Combine(FileTestSharedVariables.baseTestDirectory, @"Empty Subdirectory\");
                Directory.CreateDirectory(testDirectory);

                FileManipulator.DeleteEmptyFolders(new DirectoryInfo(testDirectory));

                bool deletionSuccessful = !Directory.Exists(FileTestSharedVariables.baseTestDirectory);
                Assert.IsTrue(deletionSuccessful);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
        public void DeleteEmptyFolders_Test_EmptyParentFolderGetsDeletedWhenNoFilesExistInMultipleSubdirectories()
        {
            try
            {
                string middleTestDirectory = Path.Combine(FileTestSharedVariables.baseTestDirectory, @"First Empty Dir\");
                string bottomTestDirectory = Path.Combine(middleTestDirectory, @"Second Empty Dir\");
                Directory.CreateDirectory(bottomTestDirectory);

                FileManipulator.DeleteEmptyFolders(new DirectoryInfo(middleTestDirectory));

                bool deletionSuccessful = !Directory.Exists(FileTestSharedVariables.baseTestDirectory);
                Assert.IsTrue(deletionSuccessful);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 9
0
        public void TrySave_Test_FileDoesNotHaveOldNameAfterValidFileRename()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Title = "Test name";

                _systemFile.TrySave();

                var fileExistsWithOriginalName = System.IO.File.Exists($@"C:\_TempForTesting\{artist}\{album}\{song}");
                Assert.IsFalse(fileExistsWithOriginalName);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 10
0
        public void TrySave_Test_FileIsMovedFromOriginalLocationAfterValidAlbumRename()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Album = "Test Album";

                _systemFile.TrySave();

                var fileExistsInOriginalLocation = System.IO.File.Exists($@"C:\_TempForTesting\{artist}\{album}\{song}");
                Assert.IsFalse(fileExistsInOriginalLocation);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 11
0
        public void IsUpdateNeeded_Test_ReturnsFalseWhenResponseHasSameValues()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.originalFilepath);
                var metadataFile      = GetMetadataFile();
                var gracenoteResponse = GetMatchingAPIResponse(metadataFile);
                metadataFile.Response = gracenoteResponse;

                var isUpdateNeeded = metadataFile.IsUpdateNeeded();

                Assert.IsFalse(isUpdateNeeded);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 12
0
        public void IsUpdateNeeded_Test_ReturnsTrueWhenResponseHasDifferentValues()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.originalFilepath);
                var metadataFile      = GetMetadataFile();
                var gracenoteResponse = GetAPIResponseWithDummyValues();
                metadataFile.Response = gracenoteResponse;

                var isUpdateNeeded = metadataFile.IsUpdateNeeded();

                Assert.IsTrue(isUpdateNeeded);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 13
0
        public void Equals_Test_ReturnsFalseGivenNonEqualMetadataFiles()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.originalFilepath);
                FileTestSharedVariables.CopyFileToTestDir(FileTestSharedVariables.copyOfOriginalFilepath);

                var metadataFile1 = GetMetadataFile();
                var metadataFile2 = GetMetadataFile(FileTestSharedVariables.copyOfOriginalFilepath);
                metadataFile2.Artist = "Something different";

                Assert.IsFalse(metadataFile1.Equals(metadataFile2));
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 14
0
        public void TrySave_Test_FileHasNewNameAfterValidFileRename()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Title = "Test name";

                _systemFile.TrySave();

                var fileExistsWithNewName = System.IO.File.Exists($@"C:\_TempForTesting\{artist}\{album}\Test name.mp3");
                Assert.IsTrue(fileExistsWithNewName);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 15
0
        public void TrySave_Test_DoesNotCreateDestinationDirectoryGivenArtistThatExceedsMaxPathLimit()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Artist = exceedsMaxCharString;

                _systemFile.TrySave();

                var directoryExists = Directory.Exists($@"C:\_TempForTesting\{exceedsMaxCharString}\{album}\{song}");
                Assert.IsFalse(directoryExists);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 16
0
        public void DeleteEmptyFolders_Test_NoDeletionsWhenFolderHasFiles()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                string testDirectory = Path.Combine(
                    FileTestSharedVariables.baseTestDirectory, @"Angels and Airwaves\We Don't Need to Whisper\");

                FileManipulator.DeleteEmptyFolders(new DirectoryInfo(testDirectory));

                bool testDirectoryExists = Directory.Exists(testDirectory);
                Assert.IsTrue(testDirectoryExists);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 17
0
        public void TrySave_Test_FileExistsInNewLocationAfterValidArtistRename()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Artist = "Test Artist";

                _systemFile.TrySave();

                bool fileExistsInNewLocation = System.IO.File.Exists($@"C:\_TempForTesting\Test Artist\{album}\{song}");
                Assert.IsTrue(fileExistsInNewLocation);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 18
0
        public void Equals_Test_ReturnsFalseGivenNotEqualSystemFile()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();

                var systemFile1 = GetSystemFile();
                var systemFile2 = GetSystemFile();
                systemFile2.Extension = ".SomeDifferentExtension";

                var areEqual = systemFile1.Equals(systemFile2);

                Assert.IsFalse(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 19
0
        public void TrySave_Test_MovesSuccesfullyWhenNewAlbumNameOnlyDiffersByCase()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Album = "wE dOn'T nEeD tO wHiSpEr";
                var originalFilepath = _systemFile.Filepath;

                _systemFile.TrySave();

                var newFilePath = _systemFile.Filepath;
                var areEqual    = (originalFilepath == newFilePath);
                Assert.IsFalse(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 20
0
        public void TrySave_Test_MovesSuccesfullyWhenNewArtistNameOnlyDiffersByCase()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Artist = "aNgElS aNd AiRwAvEs";
                var originalFilepath = _systemFile.Filepath;

                _systemFile.TrySave();

                var  newFilePath = _systemFile.Filepath;
                bool areEqual    = (originalFilepath == newFilePath);
                Assert.IsFalse(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 21
0
        public void UpdateMetadata_Test_MetadataFileDoesNotChangeGivenAnAPIResponseWithNoNewValues()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                var metadataFile           = GetMetadataFile();
                var propertiesBeforeUpdate = ExtractProperties(metadataFile);
                var gracenoteResponse      = GetMatchingAPIResponse(metadataFile);

                metadataFile.UpdateMetadata(gracenoteResponse);

                var propertiesAfterUpdate = ExtractProperties(metadataFile);
                var areEqual = AreEqual(propertiesBeforeUpdate, propertiesAfterUpdate);
                Assert.IsTrue(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 22
0
        public void UpdateMetadata_Test_SuccessfullyUpdatesMetadataFileGivenAnAPIResponseWithNewValues()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                var metadataFile           = GetMetadataFile();
                var propertiesBeforeUpdate = ExtractProperties(metadataFile);
                var gracenoteResponse      = GetAPIResponseWithDummyValues();

                metadataFile.UpdateMetadata(gracenoteResponse);

                var propertiesAfterUpdate = ExtractProperties(metadataFile);
                var areEqual = AreEqual(propertiesBeforeUpdate, propertiesAfterUpdate);
                Assert.IsFalse(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Exemplo n.º 23
0
        public void TrySave_Test_RenamesSuccesfullyWhenNewFileNameOnlyDiffersByCase()
        {
            try
            {
                FileTestSharedVariables.CopyFileToTestDir();
                _systemFile = GetSystemFile();
                _systemFile.MetadataFile.Title = "tHe AdVeNtUrE";
                var originalFilepath = _systemFile.Filepath;

                _systemFile.TrySave();

                var newFilePath = _systemFile.Filepath;

                var areEqual = (originalFilepath == newFilePath);
                Assert.IsFalse(areEqual);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }