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

                var saveResult = _systemFile.TrySave();

                Assert.IsTrue(saveResult);
            }
            finally
            {
                FileTestSharedVariables.DeleteTestDirectory();
            }
        }
Esempio 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();
            }
        }
        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();
            }
        }
        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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
        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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }
Esempio 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();
            }
        }