Exemple #1
0
 public void ReadWavFile_FilePathDoesNotExist()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string filePath = tempDirPath.Combine(tempDirPath.Path, "TestData/123.wav");
         Assert.Throws <DirectoryNotFoundException>(() => WavConverter.ReadWavFile(filePath), "DirectoryNotFoundException was not thrown.");
     }
 }
Exemple #2
0
 public void AlreadyExists_DoesNotExist()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         Assert.IsTrue(WavConverter.AlreadyExists(_goodWavFile, destination) == SaveFile.DoesNotExist, "AlreadyExists did not recognize that the destination does not already exist.");
     }
 }
Exemple #3
0
 public void WavToMp3_NullDestination()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         Assert.Throws <ArgumentNullException>(() => WavConverter.WavToMp3(destination, null), "WavToMp3 did not fail when it was given a null DestinationFilePath.");
     }
 }
Exemple #4
0
 public void WavToMp3_ConvertAndSaveSingleFiles()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         WavConverter.WavToMp3(_goodWavFile, destination);
         Assert.IsTrue(File.Exists(destination), "WavConverter did not successfully convert the wav file and save it as an mp3 file.");
     }
 }
Exemple #5
0
 public void SaveBytes_WrongExtension()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         byte[] bytes    = { 177, 209, 137, 61, 204, 127, 103, 88 };
         string fakeFile = tempDirPath.Combine(tempDirPath.Path, "abu2.abc");
         WavConverter.SaveBytes(fakeFile, bytes);
         Assert.IsTrue(File.Exists(Path.ChangeExtension(fakeFile, ".mp3")), "SaveBytes did not change the extension of the SaveFile to .mp3.");
     }
 }
Exemple #6
0
 public void SaveBytes_SaveSingleFile()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         byte[] bytes    = { 177, 209, 137, 61, 204, 127, 103, 88 };
         string fakeFile = tempDirPath.Combine(tempDirPath.Path, "abu3.mp3");
         WavConverter.SaveBytes(fakeFile, bytes);
         Assert.IsTrue(File.Exists(fakeFile), "SaveFile did not successfully save the bytes into a file.");
     }
 }
Exemple #7
0
 public void AlreadyExists_NonIdenticalExists()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         byte[] bytes    = { 177, 209, 137, 61, 204, 127, 103, 88 };
         string fakeFile = tempDirPath.Combine(tempDirPath.Path, "abu2.mp3");
         WavConverter.SaveBytes(fakeFile, bytes);
         Assert.IsTrue(WavConverter.AlreadyExists(_goodWavFile, fakeFile) == SaveFile.NotIdenticalExists, "AlreadyExists did not recognize that the destination exists but is not the converted version of the source.");
     }
 }
Exemple #8
0
 public void AlreadyExists_IdenticalExists()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         WavConverter.WavToMp3(_goodWavFile, destination);
         Assert.IsTrue(WavConverter.AlreadyExists(_goodWavFile, destination) == SaveFile.IdenticalExists, "AlreadyExists did not recognize that the converted file already exists.");
     }
 }
Exemple #9
0
 public void WavToMp3_SourceDoesNotExist()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         var    ex          = Assert.Throws <Exception>(() => WavConverter.WavToMp3(Path.Combine(_goodWavFile, "abcde.wav"), destination));
         Assert.IsTrue(ex.Message.Equals("The source file path is invalid."), "WavToMp3 does not fail when it was given a nonexistent source.");
     }
 }
Exemple #10
0
 public void WavToMp3_NonExistentFolder()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string newDestination = tempDirPath.Combine(tempDirPath.Path, "New/new/abu2.mp3");
         string directory      = tempDirPath.Combine(tempDirPath.Path, "New");
         WavConverter.WavToMp3(_goodWavFile, newDestination);
         Assert.IsTrue(Directory.Exists(directory), "SaveBytes did not create the previously nonexistent folder.");
     }
 }
Exemple #11
0
 public void WavToMp3_WrongExtension()
 {
     using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
     {
         string file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
         string destination = tempDirPath.Combine(tempDirPath.Path, file);
         WavConverter.WavToMp3(_goodWavFile, destination);
         var ex = Assert.Throws <Exception>(() => WavConverter.WavToMp3(destination, destination));
         Assert.IsTrue(ex.Message.Equals("Source file is not a .wav file."), "WavToMp3 did not fail when the source was not a .wav file.");
     }
 }
Exemple #12
0
        public void WavToMp3_ConvertAndSave_ReportsUnsupportedWav()
        {
            var messageBoxAdapter = new MockMessageBox(DialogResult.OK);

            MessageBoxUtils.Manager.SetMessageBoxAdapter(messageBoxAdapter);
            using (var tempDirPath = new TemporaryFolder(Path.GetRandomFileName()))
            {
                var file        = Path.ChangeExtension(Path.GetRandomFileName(), ".mp3");
                var destination = tempDirPath.Combine(tempDirPath.Path, file);
                Assert.DoesNotThrow(() => WavConverter.WavToMp3(_badWavFile, destination));
                Assert.IsFalse(File.Exists(destination), "WavConverter should not have created an mp3 file.");
                Assert.AreEqual(1, messageBoxAdapter.MessagesDisplayed.Count);
                Assert.That(messageBoxAdapter.MessagesDisplayed[0],
                            Is.StringStarting(string.Format(FwUtilsStrings.ConvertBytesToMp3_BadWavFile, file, string.Empty, string.Empty)));
            }
        }
Exemple #13
0
 public void ReadWavFile_WrongExtension()
 {
     Assert.That(() => WavConverter.ReadWavFile(Path.GetTempFileName()),
                 Throws.TypeOf <Exception>().With.Message.EqualTo("SaveFile is not a .wav file."), "ReadWavFile didn't break when the SaveFile was not a .wav file.");
 }
Exemple #14
0
 public void ReadWavFile_ConvertSingleFile()
 {
     byte[] result = WavConverter.ReadWavFile(_goodWavFile);
     Assert.IsNotEmpty(result, "ReadWavFile did not read the bytes of a file into a byte array.");
 }