public void AutoFillFromFileNameTest()
        {
            var viewModel = Container.GetExportedValue<MusicPropertiesViewModel>();

            Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null));

            var musicFile = MockMusicFile.CreateEmpty(@"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3");            
            viewModel.MusicFile = musicFile;

            Assert.IsTrue(viewModel.AutoFillFromFileNameCommand.CanExecute(null));
            viewModel.AutoFillFromFileNameCommand.Execute(null);
            Assert.AreEqual("Culture Beat", musicFile.Metadata.Artists.First());
            Assert.AreEqual("Serenity", musicFile.Metadata.Title);
            Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null));

            musicFile = MockMusicFile.CreateEmpty(@"\\server\share\Culture Beat Serenity.wma");
            viewModel.MusicFile = musicFile;
            viewModel.AutoFillFromFileNameCommand.Execute(null);
            Assert.IsFalse(musicFile.Metadata.Artists.Any());
            Assert.AreEqual("Culture Beat Serenity", musicFile.Metadata.Title);

            musicFile = MockMusicFile.CreateEmpty(@"C:\Culture Beat - Serenity - Epilog.wma");
            viewModel.MusicFile = musicFile;
            viewModel.AutoFillFromFileNameCommand.Execute(null);
            Assert.AreEqual("Culture Beat", musicFile.Metadata.Artists.First());
            Assert.AreEqual("Serenity - Epilog", musicFile.Metadata.Title);

            // CanExecute returns false when metadata are not supported.
            musicFile = new MockMusicFile(MusicMetadata.CreateUnsupported(TimeSpan.FromSeconds(55), 1411000), @"C:\Test.wav");
            viewModel.MusicFile = musicFile;
            Assert.IsFalse(viewModel.AutoFillFromFileNameCommand.CanExecute(null));
        }
Example #2
0
        public void TotalDurationWithMetadataLoading()
        {
            var manager = new PlaylistManager();

            Assert.AreEqual(TimeSpan.Zero, manager.TotalDuration);
            var firstFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(10), 0), "");

            manager.AddAndReplaceItems(new[] { new PlaylistItem(firstFile) });

            var secondMetadata = new MusicMetadata(TimeSpan.FromSeconds(20), 0);
            var secondFile     = new MusicFile(async x =>
            {
                await Task.Delay(10);
                return(secondMetadata);
            }, "");

            manager.AddItems(new[] { new PlaylistItem(secondFile) });
            Assert.IsTrue(manager.IsTotalDurationEstimated);
            Assert.AreEqual(TimeSpan.FromSeconds(20), manager.TotalDuration);
            AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => secondFile.GetMetadataAsync().GetResult());
            Assert.IsFalse(manager.IsTotalDurationEstimated);
            Assert.AreEqual(TimeSpan.FromSeconds(30), manager.TotalDuration);

            var thirdFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(30), 0), "");

            AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => manager.AddItems(new[] { new PlaylistItem(thirdFile) }));
            Assert.AreEqual(TimeSpan.FromSeconds(60), manager.TotalDuration);
        }
 public static MusicFile CreateEmpty(string fileName)
 {
     var musicFile = new MockMusicFile(new MusicMetadata(new TimeSpan(0, 3, 33), 320000)
     {
         Artists = new string[0],
         Title = ""
     }, fileName);
     return musicFile;
 }
Example #4
0
        public static MusicFile CreateEmpty(string fileName)
        {
            var musicFile = new MockMusicFile(new MusicMetadata(new TimeSpan(0, 3, 33), 320000)
            {
                Artists = new string[0],
                Title   = ""
            }, fileName);

            return(musicFile);
        }
 public void ConvertTest()
 {
     var musicFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(20), 0), "");
     var unsupportedFile = new MockMusicFile(MusicMetadata.CreateUnsupported(TimeSpan.FromSeconds(20), 0), "");
     
     var converter = new MusicPropertiesEnabledConverter();
     Assert.AreEqual(true, converter.Convert(new object[] { musicFile, true }, null, null, null));
     Assert.AreEqual(false, converter.Convert(new object[] { unsupportedFile, true }, null, null, null));
     
     AssertHelper.ExpectedException<NotSupportedException>(() => converter.ConvertBack(null, null, null, null));
 }
        public void PropertiesTest()
        {
            var musicFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile.wma");
            var item = new TranscodeItem(musicFile, "TestFile.mp3");

            Assert.AreEqual(musicFile, item.Source);
            Assert.AreEqual("TestFile.mp3", item.DestinationFileName);

            Assert.AreEqual(0, item.Progress);
            AssertHelper.PropertyChangedEvent(item, x => x.Progress, () => item.Progress = 0.5);
            Assert.AreEqual(0.5, item.Progress);

            Assert.IsNull(item.Error);
            var exception = new InvalidOperationException("Test");
            AssertHelper.PropertyChangedEvent(item, x => x.Error, () => item.Error = exception);
            Assert.AreEqual(exception, item.Error);
        }
        public void AddRemoveTranscodeItemsTest()
        {
            var musicFile1 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile1.wma");
            var musicFile2 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile2.wma");
            var item1 = new TranscodeItem(musicFile1, "TestFile1.mp3");
            var item2 = new TranscodeItem(musicFile1, "TestFile2.mp3");

            var manager = new TranscodingManager();
            Assert.IsFalse(manager.TranscodeItems.Any());

            manager.AddTranscodeItem(item1);
            manager.AddTranscodeItem(item2);

            Assert.IsTrue(new[] { item1, item2 }.SequenceEqual(manager.TranscodeItems));

            manager.RemoveTranscodeItem(item1);

            Assert.AreEqual(item2, manager.TranscodeItems.Single());
        }
        public void TranscodeStatusTest()
        {
            var musicFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile.wma");
            var item = new TranscodeItem(musicFile, "TestFile.mp3");

            Assert.AreEqual(TranscodeStatus.Pending, item.TranscodeStatus);

            AssertHelper.PropertyChangedEvent(item, x => x.TranscodeStatus, () =>
                item.Progress = 0.01);
            Assert.AreEqual(TranscodeStatus.InProgress, item.TranscodeStatus);

            AssertHelper.PropertyChangedEvent(item, x => x.TranscodeStatus, () =>
                item.Progress = 1);
            Assert.AreEqual(TranscodeStatus.Completed, item.TranscodeStatus);

            AssertHelper.PropertyChangedEvent(item, x => x.TranscodeStatus, () =>
                item.Error = new InvalidOperationException());
            Assert.AreEqual(TranscodeStatus.Error, item.TranscodeStatus);
        }
        public void RaisePropertyChangedTest()
        {
            var ls = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
            
            var musicFile = new MockMusicFile(new MusicMetadata(new TimeSpan(0, 3, 33), 320)
            {
                Artists = new string[0],
                Title = ""
            }, @"C:\Users\Public\Music\Dancefloor\Culture Beat - Serenity.mp3");
            var dataModel = new MusicFileDataModel(musicFile);

            Assert.AreEqual("", dataModel.ArtistsString);

            AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata.Artists = new[] { "Culture Beat" });
            Assert.AreEqual("Culture Beat", dataModel.ArtistsString);
  
            AssertHelper.PropertyChangedEvent(dataModel, x => x.ArtistsString, () => musicFile.Metadata.Artists = new[] { "Culture Beat", "Second artist" });
            Assert.AreEqual("Culture Beat" + ls + " Second artist", dataModel.ArtistsString);
        }
        public void TotalDurationWithMetadataLoading()
        {
            var manager = new PlaylistManager();
            Assert.AreEqual(TimeSpan.Zero, manager.TotalDuration);
            var firstFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(10), 0), "");
            manager.AddAndReplaceItems(new[] { new PlaylistItem(firstFile) });
            
            var secondMetadata = new MusicMetadata(TimeSpan.FromSeconds(20), 0);
            var secondFile = new MusicFile(async x =>
            {
                await Task.Delay(10);
                return secondMetadata;
            }, "");

            manager.AddItems(new[] { new PlaylistItem(secondFile) });
            Assert.IsTrue(manager.IsTotalDurationEstimated);
            Assert.AreEqual(TimeSpan.FromSeconds(20), manager.TotalDuration);
            AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => secondFile.GetMetadataAsync().GetResult());
            Assert.IsFalse(manager.IsTotalDurationEstimated);
            Assert.AreEqual(TimeSpan.FromSeconds(30), manager.TotalDuration);

            var thirdFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(30), 0), "");
            AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => manager.AddItems(new[] { new PlaylistItem(thirdFile) }));
            Assert.AreEqual(TimeSpan.FromSeconds(60), manager.TotalDuration);
        }