public async Task Playlist_ShouldRunConstructorWithoutErrors() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var model = _context.CreateModelPlaylist(); var playlist = container.CreatePlaylist(model); Assert.AreEqual(_context.FullyQualifiedTestClassName, playlist.CreatedBy); Assert.AreEqual(_context.FullyQualifiedTestClassName, playlist.UpdatedBy); Assert.AreEqual(4, playlist.Count); Assert.AreEqual($"Description for {_context.FullyQualifiedTestClassName} Playlist", playlist.Description); Assert.AreEqual(false, playlist.HasErrors); Assert.AreEqual(1, playlist.Id); Assert.AreEqual(false, playlist.IsBusy); Assert.AreEqual(false, playlist.IsChanged); Assert.AreEqual(false, playlist.IsDeleted); Assert.AreEqual(false, playlist.IsNew); Assert.AreEqual(false, playlist.IsSelected); Assert.AreEqual(false, playlist.IsShuffeling); Assert.AreEqual(4, playlist.Items.Count); Assert.AreEqual(model, playlist.Model); Assert.AreEqual(PrivacyStatus.None, playlist.PrivacyStatus); Assert.AreEqual(RepeatMode.None, playlist.RepeatMode); Assert.AreEqual(playlist[0], playlist.SelectedItem); Assert.AreEqual(1, playlist.Sequence); Assert.AreEqual($"Title for {_context.FullyQualifiedTestClassName} Playlist", playlist.Title); Assert.IsNotNull(playlist.View); Assert.IsNotNull(playlist.ClearCommand); Assert.IsNotNull(playlist.LoadFromFileCommand); Assert.IsNotNull(playlist.LoadFromFolderCommand); Assert.IsNotNull(playlist.LoadFromUrlCommand); Assert.IsNotNull(playlist.RemoveCommand); Assert.IsNotNull(playlist.RemoveRangeCommand); }
public async Task Playlist_ShouldRunPrevious() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); var messenger = container.Resolve <IMessenger>(); messenger.Publish(new PlayingMediaItemMessage(this, playlist[0], playlist.Id)); messenger.Publish(new PlayingMediaItemMessage(this, playlist[1], playlist.Id)); messenger.Publish(new PlayingMediaItemMessage(this, playlist[2], playlist.Id)); var previous = playlist.Previous(); Assert.AreEqual(playlist[2], previous); Assert.AreEqual(true, previous.IsSelected); Assert.AreEqual(1, playlist.Items.Where(p => p.IsSelected).Count()); previous = playlist.Previous(); Assert.AreEqual(playlist[1], previous); Assert.AreEqual(true, previous.IsSelected); Assert.AreEqual(1, playlist.Items.Where(p => p.IsSelected).Count()); previous = playlist.Previous(); Assert.AreEqual(playlist[0], previous); Assert.AreEqual(true, previous.IsSelected); Assert.AreEqual(1, playlist.Items.Where(p => p.IsSelected).Count()); previous = playlist.Previous(); Assert.AreEqual(null, previous); Assert.AreEqual(0, playlist.Items.Where(p => p.IsSelected).Count()); previous = playlist.Previous(); Assert.AreEqual(null, previous); Assert.AreEqual(0, playlist.Items.Where(p => p.IsSelected).Count()); }
public async Task Playlist_ShouldAddItemsFromUrlDialog() { var tokenSource = new CancellationTokenSource(1000); var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var mediaItems = new[] { container.CreateMediaItem(new MediaItemModel()), container.CreateMediaItem(new MediaItemModel()), container.CreateMediaItem(new MediaItemModel()), }; var dialogViewModel = Substitute.For <IDialogViewModel>(); dialogViewModel.ShowUrlParseDialog(NSubstitute.Arg.Any <CancellationToken>()).Returns((mediaItems)); container.UseInstance(typeof(IDialogViewModel), dialogViewModel, IfAlreadyRegistered: IfAlreadyRegistered.Replace); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); foreach (var item in mediaItems) { Assert.AreEqual(false, playlist.Items.Contains(item)); } await playlist.LoadFromUrlCommand.ExecuteAsync(tokenSource.Token).ConfigureAwait(false); foreach (var item in mediaItems) { Assert.AreEqual(true, playlist.Items.Contains(item)); } }
public async Task Playlists_ShouldLoad() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var dummyPlaylists = new List <Playlist> { container.CreatePlaylist(_context.CreateModelPlaylist()), }; var repository = ContainerContextExtensions.CreateRepository(); repository.GetPlaylistsAsync().ReturnsForAnyArgs(dummyPlaylists); container.UseInstance(repository); var playlists = (Playlists)container.Resolve <IPlaylistsViewModel>(); repository.ClearReceivedCalls(); await playlists.LoadAsync().ConfigureAwait(false); await repository.Received(1).GetPlaylistsAsync().ConfigureAwait(false); repository.Received(1).Dispose(); Assert.AreEqual(dummyPlaylists[0], playlists.SelectedItem); Assert.AreEqual(1, playlists.Count); }
public async Task Playlist_ShouldThrowAddForNull() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = CreatePlaylist(CreateModelPlaylist(), container); Assert.ThrowsException <ArgumentNullException>(() => playlist.Add(null)); }
public async Task Playlist_ShouldThrowRemoveRangeForNull() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); Assert.ThrowsException <ArgumentNullException>(() => playlist.RemoveRange(null)); }
public async Task ResolveMessengerTest() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var messenger = Substitute.For <IMessenger>(); container.UseInstance(typeof(IMessenger), messenger, IfAlreadyRegistered: IfAlreadyRegistered.Replace); Assert.AreEqual(messenger, container.Resolve <IMessenger>()); }
public async Task Playlist_ShouldRemove() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); Assert.AreEqual(4, playlist.Count); playlist.Remove(playlist[0]); Assert.AreEqual(3, playlist.Count); }
public async Task Playlist_ShouldRunClear() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = CreatePlaylist(CreateModelPlaylist(), container); Assert.AreEqual(4, playlist.Count); playlist.Clear(); Assert.AreEqual(0, playlist.Count); }
public async Task Playlist_ShouldRunNext() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = CreatePlaylist(CreateModelPlaylist(), container); playlist.RepeatMode = RepeatMode.None; var mediaItem = playlist.Next(); Assert.IsNotNull(mediaItem); Assert.AreEqual(playlist[1], mediaItem); Assert.AreNotEqual(playlist.SelectedItem, mediaItem); }
public async Task Playlist_ShouldRunNextWithRepeatModeNone() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); playlist.RepeatMode = RepeatMode.None; playlist.SelectedItem = playlist[3]; var mediaItem = playlist.Next(); Assert.IsNull(mediaItem); }
public async Task Playlist_ShouldHandleRemoveRangeForEmptyCollection() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); var mediaItems = new List <MediaItem>(); Assert.AreEqual(4, playlist.Count); playlist.RemoveRange(mediaItems); Assert.AreEqual(4, playlist.Count); }
public async Task Playlist_ShouldAdd() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var mediaItem = container.CreateMediaItem(_context.CreateModelMediaItem()); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); Assert.AreEqual(4, playlist.Count); playlist.Add(mediaItem); Assert.AreEqual(5, playlist.Count); }
public async Task ResolveManyLoadablesAsList() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var factory = Substitute.For <IWavePlayerFactory>(); container.UseInstance(factory); var loadables = container.ResolveMany <ILoadableViewModel>().ToList(); Assert.IsNotNull(loadables); Assert.IsTrue(loadables?.Count > 3, $"Only {loadables.Count} instance(s) found"); }
public async Task Playlist_ShouldRunNextWithRepeatModeSingleWhileShuffeling() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); playlist.RepeatMode = RepeatMode.Single; playlist.IsShuffeling = true; var mediaItem = playlist.Next(); Assert.IsNotNull(mediaItem); Assert.AreEqual(playlist[0], mediaItem); Assert.AreEqual(playlist.SelectedItem, mediaItem); }
public async Task Playlist_ShouldHandleRemoveRangeForUnknownItem() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = CreatePlaylist(CreateModelPlaylist(), container); var mediaItems = new List <MediaItem>() { CreateMediaItem(new MediaItemModel(), container), }; Assert.AreEqual(4, playlist.Count); playlist.RemoveRange(mediaItems); Assert.AreEqual(4, playlist.Count); }
public async Task Playlist_ShouldRaiseSelectionChanged() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var messenger = Substitute.For <IMessenger>(); container.UseInstance(typeof(IMessenger), messenger, IfAlreadyRegistered: IfAlreadyRegistered.Replace); Assert.AreEqual(messenger, container.Resolve <IMessenger>()); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); messenger.ClearReceivedCalls(); playlist.SelectedItem = playlist[1]; messenger.Received(1).Publish(NSubstitute.Arg.Any <ViewModelSelectionChangedMessage <MediaItem> >()); }
public async Task Playlists_ShouldSave() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var repository = ContainerContextExtensions.CreateRepository(); container.UseInstance(repository); var playlists = container.Resolve <IPlaylistsViewModel>(); repository.ClearReceivedCalls(); playlists.Save(); repository.Received(1).Save(NSubstitute.Arg.Any <Playlists>()); repository.Received(1).Dispose(); }
public async Task Playlist_ShouldSynchronizeItemsWithModelWhenRemovingSelectedItem() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var model = _context.CreateModelPlaylist(); var playlist = container.CreatePlaylist(model); var selectedModel = playlist.SelectedItem.Model; var next = playlist.Next(); Assert.AreEqual(model.MediaItems.Count, playlist.Count); playlist.Remove(playlist.SelectedItem); Assert.AreEqual(3, playlist.Count); Assert.AreEqual(true, selectedModel.IsDeleted); Assert.AreEqual(next, playlist.SelectedItem); }
public async Task Playlist_ShouldRemoveRange() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); var mediaItems = new[] { playlist[0], playlist[1], playlist[2], }; Assert.AreEqual(4, playlist.Count); playlist.RemoveRange(mediaItems); Assert.AreEqual(1, playlist.Count); }
public async Task Playlist_ShouldAddRange() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var mediaItems = new[] { CreateMediaItem(CreateModelMediaItem(), container), CreateMediaItem(CreateModelMediaItem(), container), CreateMediaItem(CreateModelMediaItem(), container), }; var playlist = CreatePlaylist(CreateModelPlaylist(), container); Assert.AreEqual(4, playlist.Count); playlist.AddRange(mediaItems); Assert.AreEqual(7, playlist.Count); }
public async Task Playlist_ShouldHandleRemoveRangeForSameItem() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlist = CreatePlaylist(CreateModelPlaylist(), container); var mediaItems = new[] { playlist[0], playlist[0], playlist[0], }; Assert.AreEqual(4, playlist.Count); playlist.RemoveRange(mediaItems); Assert.AreEqual(3, playlist.Count); }
public async Task Playlist_ShouldHandleAddRangeForDuplicateEntries() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var mediaItem = container.CreateMediaItem(_context.CreateModelMediaItem()); var mediaItems = new[] { mediaItem, mediaItem, mediaItem, }; var playlist = container.CreatePlaylist(_context.CreateModelPlaylist()); Assert.AreEqual(4, playlist.Count); playlist.AddRange(mediaItems); Assert.AreEqual(7, playlist.Count); }
public async Task Playlists_ShouldAdd() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var sequenceProvider = ContainerContextExtensions.CreateSequenceService(); sequenceProvider.Get(default(List <ISequence>)).ReturnsForAnyArgs(5); container.UseInstance(sequenceProvider); var playlists = (Playlists)container.Resolve <IPlaylistsViewModel>(); Assert.AreEqual(0, playlists.Count); sequenceProvider.ClearReceivedCalls(); playlists.Add(); sequenceProvider.Received(1).Get(NSubstitute.Arg.Any <IList <ISequence> >()); Assert.AreEqual(1, playlists.Count); Assert.AreEqual(5, playlists.Items.First().Sequence); }
public async Task Playlists_ShouldRunConstructorWithErrors() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var playlists = container.CreatePlaylists(); Assert.AreEqual(false, playlists.IsBusy); Assert.AreEqual(false, playlists.IsLoaded); Assert.AreEqual(0, playlists.Count); Assert.AreEqual(null, playlists.SelectedItem); Assert.AreNotEqual(null, playlists.View); Assert.AreNotEqual(null, playlists.Items); Assert.AreNotEqual(null, playlists.AddCommand); Assert.AreNotEqual(null, playlists.ClearCommand); Assert.AreNotEqual(null, playlists.LoadCommand); Assert.AreNotEqual(null, playlists.RefreshCommand); Assert.AreNotEqual(null, playlists.RemoveCommand); Assert.AreNotEqual(null, playlists.RemoveRangeCommand); Assert.AreNotEqual(null, playlists.SaveCommand); }
public async Task Playlist_ShouldSynchronizeItemsWithModelWhenRemoving() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); var model = _context.CreateModelPlaylist(); var playlist = container.CreatePlaylist(model); var mediaItem1 = playlist[1]; var mediaItem2 = playlist[2]; var mediaItem3 = playlist[3]; Assert.AreEqual(model.MediaItems.Count, playlist.Count); playlist.Remove(mediaItem1); Assert.AreEqual(3, playlist.Count); Assert.AreEqual(true, mediaItem1.IsDeleted); playlist.RemoveRange(new[] { mediaItem2, mediaItem3 }); Assert.AreEqual(1, playlist.Count); Assert.AreEqual(true, mediaItem2.IsDeleted); Assert.AreEqual(true, mediaItem3.IsDeleted); }
public async Task Playlist_ShouldThrowForEmptyMediaItemMapper() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); Assert.ThrowsException <ArgumentNullException>(() => new Playlist(container.Resolve <ViewModelServiceContainer>(), container.Resolve <IValidator <Playlist> >(), container.Resolve <IDialogViewModel>(), null, _context.CreateModelPlaylist())); }
public async Task Playlist_ShouldThrowForEmptyModel() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); Assert.ThrowsException <ArgumentNullException>(() => container.CreatePlaylist(default(PlaylistModel))); }
public static void ClassInitialize(TestContext context) { _container = DependencyInjectionFactory.Get(); }
public async Task SanityMapleGetContainerTest() { var container = await DependencyInjectionFactory.Get().ConfigureAwait(false); container.VerifyResolutions(); }