public void SelectDisc_IfDiscPresentsInList_SelectsThisDisc() { // Arrange var folder = new FolderModel(); // Using the same id as for requested disc, just in case. folder.AddSubfolders(new FolderModel { Id = new ItemId("2"), Name = "Some Subfolder" }); folder.AddDiscs(new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1" }.MakeActive()); folder.AddDiscs(new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2" }.MakeActive()); folder.AddDiscs(new DiscModel { Id = new ItemId("3"), TreeTitle = "Disc 3" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); // Act target.SelectDisc(new ItemId("2")); // Assert target.SelectedItem.Should().BeOfType <DiscExplorerItem>(); target.SelectedItem.Title.Should().Be("Disc 2"); }
public void SelectedDisc_IfDiscIsSelected_ReturnsThisDisc() { // Arrange var folder = new FolderModel(); folder.AddSubfolders(new FolderModel { Name = "Some Folder" }); folder.AddDiscs(new DiscModel { TreeTitle = "Disc 1" }.MakeActive()); folder.AddDiscs(new DiscModel { TreeTitle = "Disc 2" }.MakeActive()); folder.AddDiscs(new DiscModel { TreeTitle = "Disc 3" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.SelectedItem = target.Items[2]; target.SelectedItem.Should().BeOfType <DiscExplorerItem>(); // Act var selectedDisc = target.SelectedDisc; // Assert selectedDisc.Should().Be(folder.Discs.ToList()[1]); }
public async Task OnDiscDeleted_IfDeletedContentIsShown_ReloadsCurrentFolder() { // Arrange var oldDisc = new DiscModel { Id = new ItemId("Old Disc Id"), TreeTitle = "Old Disc" }.AddSongs(new SongModel { Id = new ItemId("1") }); var folder = new FolderModel(); folder.AddDiscs(oldDisc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.ShowDeletedContent = true; // We add new items to the current folder for checking that LoadFolderItems() was called once again for the current folder. var newSubfolder = new FolderModel { Id = new ItemId("New Subfolder Id"), Name = "New Subfolder" }; var newDisc = new DiscModel { Id = new ItemId("New Disc Id"), TreeTitle = "New Disc" }.AddSongs(new SongModel { Id = new ItemId("2") }); folder.AddSubfolders(newSubfolder); folder.AddDiscs(newDisc); // Act await target.OnDiscDeleted(new ItemId("Old Disc Id")); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(newSubfolder), new DiscExplorerItem(newDisc), new DiscExplorerItem(oldDisc), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); }
public void LoadFolderItems_ForNonRootFolder_AddsParentFolderExplorerItem() { // Arrange var nonRootFolder = new FolderModel(); nonRootFolder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var rootFolder = new FolderModel { Id = new ItemId("Parent Folder") }; rootFolder.AddSubfolders(nonRootFolder); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(nonRootFolder); // Assert var firstItem = target.Items.First(); firstItem.Should().BeOfType <ParentFolderExplorerItem>(); target.SelectedItem.Should().Be(firstItem); }
public void SelectDisc_IfDiscDoesNotPresentInList_ClearsSelection() { // Arrange var folder = new FolderModel(); // Using the same id as for requested disc, just in case. folder.AddSubfolders(new FolderModel { Id = new ItemId("1"), Name = "Some Subfolder" }); folder.AddDiscs(new DiscModel { Id = new ItemId("Disc Id"), TreeTitle = "Some Disc" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); // Act target.SelectDisc(new ItemId("1")); // Assert target.SelectedItem.Should().BeNull(); }
public void SelectedDisc_IfNoItemIsSelected_ReturnsNull() { // Arrange var folder = new FolderModel(); folder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.SelectedItem = null; // Act var selectedDisc = target.SelectedDisc; // Assert selectedDisc.Should().BeNull(); }
public void JumpToLastItemCommandHandler_SelectsLastListItem() { // Arrange var folder = new FolderModel(); folder.AddSubfolders(new FolderModel { Id = new ItemId("Subfolder Id") }); folder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var parentFolder = new FolderModel { Id = new ItemId("Parent Folder Id") }; parentFolder.AddSubfolders(folder); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); // Act target.JumpToLastItemCommand.Execute(null); // Assert target.SelectedItem.Should().Be(target.Items.Last()); }
public void PlaylistLoadedEventHandler_AllSongsBelongToSingleDisc_SwitchesToThisDisc() { // Arrange var discFolder = new FolderModel { Id = new ItemId("Some Folder") }; var disc = new DiscModel { Id = new ItemId("Some Disc") }; discFolder.AddDiscs(disc); var song1 = new SongModel { Id = new ItemId("1") }.AddToDisc(disc); var song2 = new SongModel { Id = new ItemId("2") }.AddToDisc(disc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerViewModel>(); // Act Messenger.Default.Send(new PlaylistLoadedEventArgs(new[] { song1, song2 }, song2, 1)); // Assert var itemListViewModelMock = mocker.GetMock <ILibraryExplorerItemListViewModel>(); itemListViewModelMock.Verify(x => x.LoadFolderItems(discFolder), Times.Once); itemListViewModelMock.Verify(x => x.SelectDisc(new ItemId("Some Disc")), Times.Once); }
public void NavigateLibraryExplorerToDiscEvent_SwitchesToThisDisc() { // Arrange var discFolder = new FolderModel { Id = new ItemId("Some Folder") }; var disc = new DiscModel { Id = new ItemId("Some Disc") }; discFolder.AddDiscs(disc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerViewModel>(); // Act Messenger.Default.Send(new NavigateLibraryExplorerToDiscEventArgs(disc)); // Assert var itemListViewModelMock = mocker.GetMock <ILibraryExplorerItemListViewModel>(); itemListViewModelMock.Verify(x => x.LoadFolderItems(discFolder), Times.Once); itemListViewModelMock.Verify(x => x.SelectDisc(new ItemId("Some Disc")), Times.Once); }
public async Task SelectedDiscsCanBeAddedToAdviseSet_ForDiscsFromSameFolderAndAdviseGroup_ReturnsTrue() { // Arrange var discs = new[] { new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1" }, new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2" }, }; var folder = new FolderModel { Id = new ItemId("0"), Name = "<ROOT" }; folder.AddDiscs(discs); var mocker = new AutoMocker(); var target = mocker.CreateInstance <AvailableDiscsViewModel>(); await target.LoadDiscs(discs, CancellationToken.None); target.SelectedItems = target.AvailableDiscs; // Act var result = target.SelectedDiscsCanBeAddedToAdviseSet(Array.Empty <DiscModel>()); // Assert result.Should().BeTrue(); }
public async Task SelectedDiscsCanBeAddedToAdviseSet_IfNoDiscsSelected_ReturnsFalse() { // Arrange var disc = new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1" }; var folder = new FolderModel { Id = new ItemId("0"), Name = "<ROOT" }; folder.AddDiscs(disc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <AvailableDiscsViewModel>(); await target.LoadDiscs(new[] { disc }, CancellationToken.None); target.SelectedItems = new List <AvailableDiscViewModel>(); // Act var result = target.SelectedDiscsCanBeAddedToAdviseSet(Array.Empty <DiscModel>()); // Assert result.Should().BeFalse(); }
public void ForAdviseSet_ForExplicitAdviseSet_FillsTitleCorrectly() { // Arrange var adviseSet = new AdviseSetModel { Id = new ItemId("Advise Set Id"), Name = "Some Advise Set" }; var disc1 = new DiscModel { Id = new ItemId("1"), AdviseSetInfo = new AdviseSetInfo(adviseSet, 1), Title = "Disc 1" }; var disc2 = new DiscModel { Id = new ItemId("2"), AdviseSetInfo = new AdviseSetInfo(adviseSet, 2), Title = "Disc 2" }; var folder = new FolderModel { Name = "Some Artist" }; folder.AddDiscs(disc1, disc2); var adviseSetContent = new AdviseSetContent("AdviseSetContent Id"); adviseSetContent.AddDisc(disc1); adviseSetContent.AddDisc(disc2); // Act var target = AdvisedPlaylist.ForAdviseSet(adviseSetContent); // Assert target.Title.Should().Be("Some Advise Set"); }
public void SelectedFolder_IfFolderIsSelected_ReturnsThisFolder() { // Arrange var folder = new FolderModel(); folder.AddSubfolders(new FolderModel { Name = "Folder 1" }); folder.AddSubfolders(new FolderModel { Name = "Folder 2" }); folder.AddSubfolders(new FolderModel { Name = "Folder 3" }); folder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.SelectedItem = target.Items[1]; target.SelectedItem.Should().BeOfType <FolderExplorerItem>(); // Act var selectedFolder = target.SelectedFolder; // Assert selectedFolder.Should().Be(folder.Subfolders.ToList()[1]); }
public async Task GroupLibraryDiscs_IfNoFolderBelongsToAssignedGroupUpToRoot_AssignsDiscsFromSameFolderToOneAdviseGroupContent() { // Arrange var rootFolder = new FolderModel { Id = new ItemId("Root Folder") }; var folder1 = new FolderModel { Id = new ItemId("Folder 1"), Name = "Folder 1" }; var folder2 = new FolderModel { Id = new ItemId("Folder 2"), Name = "Folder 2" }; rootFolder.AddSubfolders(folder1, folder2); var folder11 = new FolderModel { Id = new ItemId("Folder 11") }; var folder21 = new FolderModel { Id = new ItemId("Folder 21") }; folder1.AddSubfolders(folder11); folder2.AddSubfolders(folder21); var disc11 = new DiscModel(); var disc12 = new DiscModel(); var disc21 = new DiscModel(); folder11.AddDiscs(disc11, disc12); folder21.AddDiscs(disc21); var mocker = new AutoMocker(); var target = mocker.CreateInstance <DiscGrouper>(); // Act var adviseGroups = await target.GroupLibraryDiscs(new[] { disc11, disc21, disc12 }, CancellationToken.None); // Assert var expectedAdviseGroup1 = new AdviseGroupContent("Folder Group: Folder 11", isFavorite: false); expectedAdviseGroup1.AddDisc(disc11); expectedAdviseGroup1.AddDisc(disc12); var expectedAdviseGroup2 = new AdviseGroupContent("Folder Group: Folder 21", isFavorite: false); expectedAdviseGroup2.AddDisc(disc21); var expectedAdviseGroups = new[] { expectedAdviseGroup1, expectedAdviseGroup2, }; adviseGroups.Should().BeEquivalentTo(expectedAdviseGroups, x => x.WithoutStrictOrdering()); }
public async Task LoadAvailableDiscsForAdviseSet_IfDiscBelongsToAnotherFolder_DoesNotAddSuchDiscsToList() { // Arrange var adviseSet = new AdviseSetModel { Id = new ItemId("1") }; var discs = new[] { new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1", AdviseSetInfo = new AdviseSetInfo(adviseSet, 1) }, new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2" }, new DiscModel { Id = new ItemId("3"), TreeTitle = "Disc 3" }, }; var folder1 = new FolderModel { Id = new ItemId("0"), Name = "<ROOT" }; var folder2 = new FolderModel { Id = new ItemId("1"), Name = "Folder 1" }; var folder3 = new FolderModel { Id = new ItemId("2"), Name = "Folder 2" }; folder1.AddSubfolders(folder2); folder2.AddSubfolders(folder3); folder2.AddDiscs(discs[0], discs[2]); folder3.AddDiscs(discs[1]); var adviseSetDiscs = new[] { discs[0], }; var mocker = new AutoMocker(); var target = mocker.CreateInstance <AvailableDiscsViewModel>(); await target.LoadDiscs(discs, CancellationToken.None); // Act target.LoadAvailableDiscsForAdviseSet(adviseSetDiscs); // Assert var expectedAvailableDiscs = new[] { new AvailableDiscViewModel(discs[2], "/Folder 1/Disc 3"), }; target.AvailableDiscs.Should().BeEquivalentTo(expectedAvailableDiscs, x => x.WithStrictOrdering()); }
public async Task CreateAdviseSetCommandHandler_IfDefaultAdviseSetNameIsAlreadyUsed_PicksNextFreeAdviseSetName() { // Arrange var existingAdviseSets = new[] { new AdviseSetModel { Id = new ItemId("1"), Name = "Parent Folder / New Advise Set" }, new AdviseSetModel { Id = new ItemId("2"), Name = "Parent Folder / New Advise Set (2)" }, }; var discs = new[] { new DiscModel { Id = new ItemId("1"), AlbumTitle = "Some Album 1" }.MakeActive(), new DiscModel { Id = new ItemId("2"), AlbumTitle = "Some Album 2" }.MakeActive(), }; var parentFolder = new FolderModel { Id = new ItemId("1"), Name = "Parent Folder" }; parentFolder.AddDiscs(discs); var availableDiscsViewModelStub = new Mock <IAvailableDiscsViewModel>(); availableDiscsViewModelStub.Setup(x => x.SelectedDiscs).Returns(discs); var mocker = StubServices(existingAdviseSets, discs); mocker.Use(availableDiscsViewModelStub); var target = mocker.CreateInstance <AdviseSetsEditorViewModel>(); await target.Load(CancellationToken.None); // Act target.CreateAdviseSetCommand.Execute(null); // Assert var adviseSetServiceMock = mocker.GetMock <IAdviseSetService>(); Func <AdviseSetModel, bool> verifyAdviseSet = x => x.Name == "Parent Folder / New Advise Set (3)"; adviseSetServiceMock.Verify(x => x.CreateAdviseSet(It.Is <AdviseSetModel>(y => verifyAdviseSet(y)), It.IsAny <CancellationToken>()), Times.Once); }
public void LoadFolderItems_IfTitlesContainSpecialLocalCharacters_OrdersItemsCorrectly() { // Arrange var folder1 = new FolderModel { Name = "Елена Никитаева" }; var folder2 = new FolderModel { Name = "Ёлка" }; var folder3 = new FolderModel { Name = "Жанна Агузарова" }; var disc1 = new DiscModel { TreeTitle = "Елена Никитаева" }.MakeActive(); var disc2 = new DiscModel { TreeTitle = "Ёлка" }.MakeActive(); var disc3 = new DiscModel { TreeTitle = "Жанна Агузарова" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(folder3, folder1, folder2); folder.AddDiscs(disc3, disc1, disc2); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(folder); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(folder1), new FolderExplorerItem(folder2), new FolderExplorerItem(folder3), new DiscExplorerItem(disc1), new DiscExplorerItem(disc2), new DiscExplorerItem(disc3), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); target.SelectedItem.Should().Be(target.Items.First()); }
public void LoadFolderItems_ForTitlesInDifferentCase_IgnoresCaseDuringOrdering() { // Arrange var folder1 = new FolderModel { Name = "A Folder" }; var folder2 = new FolderModel { Name = "b Folder" }; var folder3 = new FolderModel { Name = "C Folder" }; var disc1 = new DiscModel { TreeTitle = "A Disc" }.MakeActive(); var disc2 = new DiscModel { TreeTitle = "b Disc" }.MakeActive(); var disc3 = new DiscModel { TreeTitle = "C Disc" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(folder3, folder1, folder2); folder.AddDiscs(disc3, disc1, disc2); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(folder); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(folder1), new FolderExplorerItem(folder2), new FolderExplorerItem(folder3), new DiscExplorerItem(disc1), new DiscExplorerItem(disc2), new DiscExplorerItem(disc3), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); target.SelectedItem.Should().Be(target.Items.First()); }
public void LoadFolderItems_ForFolderWithSubfoldersAndDiscs_OrdersItemsCorrectly() { // Arrange var folder1 = new FolderModel { Name = "21 - Folder 1" }; var folder2 = new FolderModel { Name = "22 - Folder 2" }; var folder3 = new FolderModel { Name = "23 - Folder 3" }; var disc1 = new DiscModel { TreeTitle = "11 - Disc 1" }.MakeActive(); var disc2 = new DiscModel { TreeTitle = "12 - Disc 2" }.MakeActive(); var disc3 = new DiscModel { TreeTitle = "13 - Disc 3" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(folder3, folder1, folder2); folder.AddDiscs(disc3, disc1, disc2); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(folder); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(folder1), new FolderExplorerItem(folder2), new FolderExplorerItem(folder3), new DiscExplorerItem(disc1), new DiscExplorerItem(disc2), new DiscExplorerItem(disc3), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); target.SelectedItem.Should().Be(target.Items.First()); }
public void LoadFolderItems_IfSomeItemsWereLoadedBefore_ClearsPreviousItems() { // Arrange var oldFolder = new FolderModel(); oldFolder.AddSubfolders(new FolderModel { Id = new ItemId("OldSubfolder"), Name = "Old Folder" }); oldFolder.AddDiscs(new DiscModel { Id = new ItemId("OldDisc"), TreeTitle = "Old Disc" }.AddSongs(new SongModel { Id = new ItemId("1") })); var newSubfolder = new FolderModel { Id = new ItemId("NewSubfolder"), Name = "New Folder" }; var newDisc = new DiscModel { Id = new ItemId("NewSubfolder"), TreeTitle = "New Disc" }.AddSongs(new SongModel { Id = new ItemId("2") }); var newFolder = new FolderModel { Id = new ItemId("NewFolder") }; newFolder.AddSubfolders(newSubfolder); newFolder.AddDiscs(newDisc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(oldFolder); target.SelectedItem = target.Items[1]; // Act target.LoadFolderItems(newFolder); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(newSubfolder), new DiscExplorerItem(newDisc), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); target.SelectedItem.Should().Be(target.Items.First()); }
public void LoadFolderItems_ShowDeletedContentIsTrue_LoadsDeletedContent() { // Arrange var subfolder1 = new FolderModel { Name = "Subfolder 1" }; var subfolder2 = new FolderModel { Name = "Subfolder 2", DeleteDate = new DateTime(2021, 07, 25) }; var subfolder3 = new FolderModel { Name = "Subfolder 3" }; var disc1 = new DiscModel { TreeTitle = "Disc 1" }.MakeActive(); var disc2 = new DiscModel { TreeTitle = "Disc 2" }.MakeDeleted(); var disc3 = new DiscModel { TreeTitle = "Disc 3" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(subfolder1, subfolder2, subfolder3); folder.AddDiscs(disc1, disc2, disc3); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(folder); target.ShowDeletedContent = true; // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(subfolder1), new FolderExplorerItem(subfolder2), new FolderExplorerItem(subfolder3), new DiscExplorerItem(disc1), new DiscExplorerItem(disc2), new DiscExplorerItem(disc3), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering().RespectingRuntimeTypes()); }
public void PlayDisc_SendsPlaySongsListEventForActiveDiscSongs() { // Arrange var disc = new DiscModel { Id = new ItemId("Some Disc") }; var discFolder = new FolderModel { Id = new ItemId("Some Folder") }; discFolder.AddDiscs(disc); var activeSong1 = new SongModel { Id = new ItemId("Active Song 1") }; var activeSong2 = new SongModel { Id = new ItemId("Active Song 2") }; var deletedSong = new SongModel { Id = new ItemId("Deleted Songs"), DeleteDate = new DateTime(2021, 07, 25) }; disc.AddSongs(activeSong1, deletedSong, activeSong2); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerViewModel>(); PlaySongsListEventArgs playSongsListEvent = null; Messenger.Default.Register <PlaySongsListEventArgs>(this, e => e.RegisterEvent(ref playSongsListEvent)); // Act target.PlayDisc(disc); // Assert var expectedSongs = new[] { activeSong1, activeSong2, }; playSongsListEvent.Should().NotBeNull(); playSongsListEvent.Songs.Should().BeEquivalentTo(expectedSongs, x => x.WithStrictOrdering()); }
public async Task OnFolderDeleted_IfDeletedContentIsHiddenAndFolderPresentsInList_RemovesThisFolder() { // Arrange var folder1 = new FolderModel { Id = new ItemId("1"), Name = "Folder 1" }; var folder2 = new FolderModel { Id = new ItemId("2"), Name = "Folder 2" }; var folder3 = new FolderModel { Id = new ItemId("3"), Name = "Folder 3" }; // Using the same id as for requested folder, just in case. var disc = new DiscModel { Id = new ItemId("2"), TreeTitle = "Some Disc" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(folder1, folder2, folder3); folder.AddDiscs(disc); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.ShowDeletedContent = false; // Act await target.OnFolderDeleted(new ItemId("2")); // Assert var expectedItems = new BasicExplorerItem[] { new FolderExplorerItem(folder1), new FolderExplorerItem(folder3), new DiscExplorerItem(disc), }; target.Items.Should().BeEquivalentTo(expectedItems, x => x.WithStrictOrdering()); }
public async Task GroupLibraryDiscs_IfDiscsBelongToSameAdviseSet_AssignsDiscsToSameAdviseSetContent() { // Arrange var adviseSet1 = new AdviseSetModel { Id = new ItemId("Advise Set 1") }; var adviseSet2 = new AdviseSetModel { Id = new ItemId("Advise Set 2") }; var disc11 = new DiscModel { AdviseSetInfo = new AdviseSetInfo(adviseSet1, 1) }; var disc12 = new DiscModel { AdviseSetInfo = new AdviseSetInfo(adviseSet1, 2) }; var disc21 = new DiscModel { AdviseSetInfo = new AdviseSetInfo(adviseSet2, 1) }; var rootFolder = new FolderModel { Id = new ItemId("Root Folder") }; rootFolder.AddDiscs(disc11, disc12, disc21); var mocker = new AutoMocker(); var target = mocker.CreateInstance <DiscGrouper>(); // Act var adviseGroups = await target.GroupLibraryDiscs(new[] { disc11, disc21, disc12 }, CancellationToken.None); // Assert adviseGroups.Count.Should().Be(1); var adviseSets = adviseGroups.Single().AdviseSets.ToList(); adviseSets.Count.Should().Be(2); adviseSets[0].Discs.Should().BeEquivalentTo(new[] { disc11, disc12 }, x => x.WithStrictOrdering()); adviseSets[1].Discs.Should().BeEquivalentTo(new[] { disc21 }, x => x.WithStrictOrdering()); }
public async Task CreateAdviseSetCommandHandler_IfAllDiscsBelongToSameAlbum_UsesAdviseSetNameWithAlbumTitle() { // Arrange var discs = new[] { new DiscModel { Id = new ItemId("1"), AlbumTitle = "Some Album" }.MakeActive(), new DiscModel { Id = new ItemId("2"), AlbumTitle = "Some Album" }.MakeActive(), }; var parentFolder = new FolderModel { Id = new ItemId("1"), Name = "Parent Folder" }; parentFolder.AddDiscs(discs); var availableDiscsViewModelStub = new Mock <IAvailableDiscsViewModel>(); availableDiscsViewModelStub.Setup(x => x.SelectedDiscs).Returns(discs); var mocker = StubServices(Array.Empty <AdviseSetModel>(), discs); mocker.Use(availableDiscsViewModelStub); var target = mocker.CreateInstance <AdviseSetsEditorViewModel>(); await target.Load(CancellationToken.None); // Act target.CreateAdviseSetCommand.Execute(null); // Assert var adviseSetServiceMock = mocker.GetMock <IAdviseSetService>(); Func <AdviseSetModel, bool> verifyAdviseSet = x => x.Name == "Parent Folder / Some Album"; adviseSetServiceMock.Verify(x => x.CreateAdviseSet(It.Is <AdviseSetModel>(y => verifyAdviseSet(y)), It.IsAny <CancellationToken>()), Times.Once); }
public void ShowDeletedContentSetter_IfPreviouslySelectedItemIsMissing_SelectsFirstItem() { // Arrange var subfolder1 = new FolderModel { Id = new ItemId("1"), Name = "Subfolder 1" }; var subfolder2 = new FolderModel { Id = new ItemId("2"), Name = "Subfolder 2", DeleteDate = new DateTime(2021, 07, 25) }; var subfolder3 = new FolderModel { Id = new ItemId("3"), Name = "Subfolder 3" }; var disc1 = new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1" }.MakeActive(); var disc2 = new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2" }.MakeDeleted(); var disc3 = new DiscModel { Id = new ItemId("3"), TreeTitle = "Disc 3" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(subfolder1, subfolder2, subfolder3); folder.AddDiscs(disc1, disc2, disc3); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.ShowDeletedContent = true; target.SelectDisc(new ItemId("2")); // Act target.ShowDeletedContent = false; // Assert target.SelectedFolder.Should().Be(subfolder1); }
public void ChangeFolderCommandHandler_IfDiscItemIsSelected_DoesNothing() { // Arrange var folder = new FolderModel(); folder.AddSubfolders(new FolderModel { Id = new ItemId("Subfolder Id") }); folder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var parentFolder = new FolderModel { Id = new ItemId("Parent Folder Id") }; parentFolder.AddSubfolders(folder); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.SelectedItem = target.Items[2]; target.SelectedItem.Should().BeOfType <DiscExplorerItem>(); LoadParentFolderEventArgs loadParentFolderEvent = null; Messenger.Default.Register <LoadParentFolderEventArgs>(this, e => e.RegisterEvent(ref loadParentFolderEvent)); LoadFolderEventArgs loadFolderEvent = null; Messenger.Default.Register <LoadFolderEventArgs>(this, e => e.RegisterEvent(ref loadFolderEvent)); // Act target.ChangeFolderCommand.Execute(null); // Assert loadParentFolderEvent.Should().BeNull(); loadFolderEvent.Should().BeNull(); }
public void ShowDeletedContentSetter_IfDiscWasSelectedBefore_SelectsSameDisc() { // Arrange var subfolder1 = new FolderModel { Id = new ItemId("1"), Name = "Subfolder 1" }; var subfolder2 = new FolderModel { Id = new ItemId("2"), Name = "Subfolder 2" }; var subfolder3 = new FolderModel { Id = new ItemId("3"), Name = "Subfolder 3" }; var disc1 = new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1" }.MakeActive(); var disc2 = new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2" }.MakeActive(); var disc3 = new DiscModel { Id = new ItemId("3"), TreeTitle = "Disc 3" }.MakeActive(); var folder = new FolderModel(); folder.AddSubfolders(subfolder1, subfolder2, subfolder3); folder.AddDiscs(disc1, disc2, disc3); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); target.LoadFolderItems(folder); target.SelectDisc(new ItemId("2")); // Act target.ShowDeletedContent = true; // Assert target.SelectedDisc.Should().Be(disc2); }
public async Task SelectedDiscsCanBeAddedToAdviseSet_IfDiscsBelongsToDifferentFolders_ReturnsFalse() { // Arrange var adviseGroup1 = new AdviseGroupModel { Id = new ItemId("1") }; var adviseGroup2 = new AdviseGroupModel { Id = new ItemId("2") }; var discs = new[] { new DiscModel { Id = new ItemId("1"), TreeTitle = "Disc 1", AdviseGroup = adviseGroup1 }, new DiscModel { Id = new ItemId("2"), TreeTitle = "Disc 2", AdviseGroup = adviseGroup2 }, }; var folder = new FolderModel { Id = new ItemId("0"), Name = "<ROOT" }; folder.AddDiscs(discs); var mocker = new AutoMocker(); var target = mocker.CreateInstance <AvailableDiscsViewModel>(); await target.LoadDiscs(discs, CancellationToken.None); target.SelectedItems = target.AvailableDiscs; // Act var result = target.SelectedDiscsCanBeAddedToAdviseSet(Array.Empty <DiscModel>()); // Assert result.Should().BeFalse(); }
public void LoadFolderItems_ForRootFolder_DoesNotAddParentFolderExplorerItem() { // Arrange var rootFolder = new FolderModel(); rootFolder.AddDiscs(new DiscModel { TreeTitle = "Some Disc" }.MakeActive()); var mocker = new AutoMocker(); var target = mocker.CreateInstance <LibraryExplorerItemListViewModel>(); // Act target.LoadFolderItems(rootFolder); // Assert target.Items.OfType <ParentFolderExplorerItem>().Should().BeEmpty(); }