Exemple #1
0
        public void PlaylistChangedEventHandler_IfPlaylistIsSelected_RaisesActiveDiscChangedEventForCurrentPlaylistDisc()
        {
            // Arrange

            var currentDisc = new DiscModel();

            var mocker = new AutoMocker();
            var target = mocker.CreateInstance <SongListTabViewModel>();

            target.SwitchToPlaylistCommand.Execute(null);

            // We mock CurrentDisc property after switching to Playlist.
            // Otherwise value of ActiveDisc will be the same and no event will be sent.
            mocker.GetMock <IPlaylistViewModel>()
            .Setup(x => x.CurrentDisc).Returns(currentDisc);

            ActiveDiscChangedEventArgs activeDiscChangedEventArgs = null;

            Messenger.Default.Register <ActiveDiscChangedEventArgs>(this, e => e.RegisterEvent(ref activeDiscChangedEventArgs));

            // Act

            Messenger.Default.Send(new PlaylistChangedEventArgs(Enumerable.Empty <SongModel>(), null, null));

            // Assert

            activeDiscChangedEventArgs.Should().NotBeNull();
            activeDiscChangedEventArgs.Disc.Should().Be(currentDisc);
        }
Exemple #2
0
        public void SwitchToDiscSongListCommand_IfSongListIsChanged_RaisesActiveDiscChangedEventForSelectedDisc()
        {
            // Arrange

            var selectedDisc = new DiscModel();

            var mocker = new AutoMocker();

            mocker.GetMock <ILibraryExplorerViewModel>()
            .Setup(x => x.SelectedDisc).Returns(selectedDisc);

            var target = mocker.CreateInstance <SongListTabViewModel>();

            target.SwitchToPlaylistCommand.Execute(null);

            ActiveDiscChangedEventArgs activeDiscChangedEventArgs = null;

            Messenger.Default.Register <ActiveDiscChangedEventArgs>(this, e => e.RegisterEvent(ref activeDiscChangedEventArgs));

            // Act

            target.SwitchToDiscSongListCommand.Execute(null);

            // Assert

            activeDiscChangedEventArgs.Should().NotBeNull();
            activeDiscChangedEventArgs.Disc.Should().Be(selectedDisc);
        }
Exemple #3
0
        public async Task Delete_ForDisc_DeletesDiscCorrectly()
        {
            // Arrange

            var disc = new DiscModel
            {
                Id    = new ItemId("Disc Id"),
                Title = "Some Disc",
            };

            var mocker = new AutoMocker();
            var target = mocker.CreateInstance <DeleteContentViewModel>();

            target.LoadForDisc(disc);

            LibraryExplorerDiscChangedEventArgs libraryExplorerDiscChangedEvent = null;

            Messenger.Default.Register <LibraryExplorerDiscChangedEventArgs>(this, e => e.RegisterEvent(ref libraryExplorerDiscChangedEvent));

            // Act

            target.DeleteComment = "Some Delete Comment";
            await target.Delete(CancellationToken.None);

            // Assert

            libraryExplorerDiscChangedEvent.Should().NotBeNull();
            libraryExplorerDiscChangedEvent.Disc.Should().BeNull();

            var discServiceMock = mocker.GetMock <IDiscsService>();

            discServiceMock.Verify(x => x.DeleteDisc(It.IsAny <ItemId>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once);
            discServiceMock.Verify(x => x.DeleteDisc(new ItemId("Disc Id"), "Some Delete Comment", It.IsAny <CancellationToken>()), Times.Once);
        }
        public void ShowDiscPropertiesView(DiscModel disc)
        {
            var viewModel = viewModelHolder.EditDiscPropertiesViewModel;

            viewModel.Load(disc);
            ShowDialog <EditDiscPropertiesView>(viewModel);
        }
 public static DiscModel MakeDeleted(this DiscModel disc)
 {
     disc.AddSong(new SongModel {
         DeleteDate = DateTimeOffset.Now
     });
     return(disc);
 }
Exemple #6
0
        public void ForAdviseSetFromFavoriteAdviseGroup_IfAdviseSetContainsDeletedSongs_FillsPlaylistOnlyWithActiveSongs()
        {
            // Arrange

            var deletedSong = new SongModel {
                Id = new ItemId("1"), DeleteDate = new DateTime(2017, 10, 06)
            };
            var activeSong1 = new SongModel {
                Id = new ItemId("2")
            };
            var activeSong2 = new SongModel {
                Id = new ItemId("3")
            };

            var adviseSetContent = new DiscModel
            {
                Id = new ItemId("1"),
            }
            .AddSongs(deletedSong, activeSong1, activeSong2)
            .AddToFolder(new FolderModel {
                Name = "Some Artist"
            })
            .ToAdviseSet();

            // Act

            var target = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetContent);

            // Assert

            target.Songs.Should().BeEquivalentTo(new[] { activeSong1, activeSong2 }, x => x.WithStrictOrdering());
        }
Exemple #7
0
        public void CoverImageSourceGetter_IfCoverImageIsMissing_ReturnsImageSourceForMissingImage()
        {
            // Arrange

            var disc = new DiscModel().MakeActive();

            disc.AddImage(new DiscImageModel {
                ImageType = DiscImageType.Cover, ContentUri = new Uri("file://Some-Missing-Image.jpg")
            });

            var fileSystemFacade = new Mock <IFileSystemFacade>();

            fileSystemFacade.Setup(x => x.FileExists("file://Some-Missing-Image.jpg")).Returns(false);

            var mocker = new AutoMocker();

            mocker.Use(fileSystemFacade);

            var target = mocker.CreateInstance <DiscImageViewModel>();

            Messenger.Default.Send(new ActiveDiscChangedEventArgs(disc));

            // Act

            var currentImageUri = target.CoverImageSource;

            // Assert

            currentImageUri.Should().Be(DiscImageSource.ForMissingImage);
        }
Exemple #8
0
        public DiscViewModel Create(DiscModel Disc)
        {
            var vm = _creator();

            vm.Initialize(Disc);
            return(vm);
        }
Exemple #9
0
        public void CurrentAdviseGroup_ReturnsDiscAdviseGroup()
        {
            // Arrange

            var adviseGroup = new AdviseGroupModel
            {
                Id   = new ItemId("Advise Group Id"),
                Name = "Advise Group Name",
            };

            var disc = new DiscModel
            {
                AdviseGroup = adviseGroup,
            };

            var target = new DiscAdviseGroupHolder(disc);

            // Act

            var currentAdviseGroup = target.CurrentAdviseGroup;

            // Assert

            currentAdviseGroup.Should().Be(adviseGroup);
        }
        public void Load_ForDeletedDiscWithVariousDeleteCommentsForSongs_LoadsDeleteCommentCorrectly()
        {
            // Arrange

            var disc = new DiscModel
            {
                Title     = "Some Title",
                TreeTitle = "Some Tree Title",
            };

            disc.AddSongs(new SongModel {
                DeleteDate = new DateTime(2021, 10, 25), DeleteComment = "Boring"
            });
            disc.AddSongs(new SongModel {
                DeleteDate = new DateTime(2021, 10, 25), DeleteComment = "Boring too"
            });

            var mocker = new AutoMocker();
            var target = mocker.CreateInstance <EditDiscPropertiesViewModel>();

            // Act

            target.Load(disc);

            // Assert

            target.IsDeleted.Should().BeTrue();
            target.DeleteComment.Should().Be("<Songs have various delete comments>");
        }
Exemple #11
0
 private static ArtistModel GetDiscArtist(DiscModel disc)
 {
     return(disc.ActiveSongs
            .Select(song => song.Artist)
            .Where(artist => artist != null)
            .UniqueOrDefault(new ArtistEqualityComparer()));
 }
        DiscViewModel GetDiscViewModel(DiscModel disc)
        {
            DiscViewModel vm;

            _discLookup.TryGetValue(disc, out vm);
            return(vm);
        }
        public bool ShowDeleteDiscView(DiscModel disc)
        {
            var viewModel = viewModelHolder.DeleteContentViewModel;

            viewModel.LoadForDisc(disc);
            return(ShowDialog <DeleteContentView>(viewModel));
        }
Exemple #14
0
        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();
        }
Exemple #15
0
        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 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);
        }
Exemple #18
0
        private void OnExplorerDiscChanged(DiscModel newDisc, bool deletedContentIsShown)
        {
            CurrentDisc           = newDisc;
            DeletedContentIsShown = deletedContentIsShown;

            LoadSongs();
        }
        public async Task DeleteDisc_IfDiscIsNotDeleted_DoesNotInvokesOnDiscDeleted()
        {
            // Arrange

            var disc = new DiscModel {
                Id = new ItemId("Some Disc")
            };

            var mocker = new AutoMocker();

            mocker.GetMock <IViewNavigator>()
            .Setup(x => x.ShowDeleteDiscView(It.IsAny <DiscModel>())).Returns(false);

            var target = mocker.CreateInstance <LibraryExplorerViewModel>();

            // Act

            await target.DeleteDisc(disc, CancellationToken.None);

            // Assert

            var itemListViewModelMock = mocker.GetMock <ILibraryExplorerItemListViewModel>();

            itemListViewModelMock.Verify(x => x.OnDiscDeleted(It.IsAny <ItemId>()), Times.Never);
        }
Exemple #20
0
        public void DiscExplorerItem_WhenDiscTreeTitleIsChanged_SendsPropertyChangedEventForTitle()
        {
            // Arrange

            var disc = new DiscModel
            {
                TreeTitle = "Old Tree Title",
            };

            var target = new DiscExplorerItem(disc);

            var propertyChangedEvents = new List <PropertyChangedEventArgs>();

            target.PropertyChanged += (_, e) => propertyChangedEvents.Add(e);

            // Act

            disc.TreeTitle = "New Tree Title";

            // Assert

            var expectedProperties = new[]
            {
                nameof(DiscExplorerItem.Title),
            };

            propertyChangedEvents.Select(e => e.PropertyName).Should().BeEquivalentTo(expectedProperties);
        }
Exemple #21
0
        public void DiscExplorerItem_WhenDiscAdviseGroupIsChanged_SendsPropertyChangedEventForIconKind()
        {
            // Arrange

            var disc = new DiscModel
            {
                AdviseGroup = null,
            };

            var target = new DiscExplorerItem(disc);

            var propertyChangedEvents = new List <PropertyChangedEventArgs>();

            target.PropertyChanged += (_, e) => propertyChangedEvents.Add(e);

            // Act

            disc.AdviseGroup = new AdviseGroupModel {
                Id = new ItemId("1"), Name = "New Advise Group"
            };

            // Assert

            var expectedProperties = new[]
            {
                nameof(DiscExplorerItem.IconKind),
            };

            propertyChangedEvents.Select(e => e.PropertyName).Should().BeEquivalentTo(expectedProperties);
        }
        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 void Initialize()
        {
            _board = new CellModel[8 * 8];

            for (int column = 0; column < 8; column++)
            {
                for (int row = 0; row < 8; row++)
                {
                    _board[8 * row + column] = new CellModel(column, row);
                }
            }

            for (int d = 0; d < 64; d++)
            {
                DiscModel disc;
                if (d % 2 == 0)
                {
                    disc = new DiscModel(OthelloColor.White);
                }
                else
                {
                    disc = new DiscModel(OthelloColor.Black);
                }
                _discs.Add(disc);
            }

            GameState = GameStateEnum.NotStarted;
        }
        public void Load_ForDeletedDiscWithSameDeleteCommentForAllSongs_LoadsPropertiesCorrectly()
        {
            // Arrange

            var disc = new DiscModel
            {
                Title      = "Some Title",
                TreeTitle  = "Some Tree Title",
                AlbumTitle = "Some Album Title",
                Year       = 2021,
            };

            disc.AddSongs(new SongModel {
                DeleteDate = new DateTime(2021, 10, 25), DeleteComment = "Boring"
            });
            disc.AddSongs(new SongModel {
                DeleteDate = new DateTime(2021, 10, 25), DeleteComment = "Boring"
            });

            var mocker = new AutoMocker();
            var target = mocker.CreateInstance <EditDiscPropertiesViewModel>();

            // Act

            target.Load(disc);

            // Assert

            target.IsDeleted.Should().BeTrue();
            target.Title.Should().Be("Some Title");
            target.TreeTitle.Should().Be("Some Tree Title");
            target.AlbumTitle.Should().Be("Some Album Title");
            target.Year.Should().Be(2021);
            target.DeleteComment.Should().Be("Boring");
        }
 public static double GetRating(this DiscModel disc)
 {
     return(disc.ActiveSongs
            .Select(song => song.GetRatingOrDefault())
            .Select(rating => rating.GetRatingValueForAdviser())
            .Average());
 }
Exemple #26
0
        public void ForAdviseSetFromFavoriteAdviseGroup_FillsTitleCorrectly()
        {
            // Arrange

            var adviseSetContent = new DiscModel
            {
                Id    = new ItemId("1"),
                Title = "Some Disc",
            }
            .AddSongs(new SongModel {
                Id = new ItemId("12345"), Artist = new ArtistModel {
                    Name = "Another Artist"
                }
            })
            .AddToFolder(new FolderModel {
                Name = "Some Artist"
            })
            .ToAdviseSet();

            // Act

            var target = AdvisedPlaylist.ForAdviseSetFromFavoriteAdviseGroup(adviseSetContent);

            // Assert

            target.Title.Should().Be("*** Some Artist / Some Disc");
        }
        public void ShowEditDiscImageView(DiscModel disc)
        {
            var viewModel = viewModelHolder.EditDiscImageViewModel;

            viewModel.Load(disc);
            ShowDialog <EditDiscImageView>(viewModel);
        }
        public static AdviseSetContent ToAdviseSet(this DiscModel disc)
        {
            var adviseSet = new AdviseSetContent($"Disc: {disc.Id}");

            adviseSet.AddDisc(disc);

            return(adviseSet);
        }
Exemple #29
0
        public async Task RemoveAdviseGroup(DiscModel disc, CancellationToken cancellationToken)
        {
            disc.AdviseGroup = null;

            await discsRepository.UpdateDisc(disc, cancellationToken);

            await DeleteOrphanAdviseGroups(cancellationToken);
        }
Exemple #30
0
    public void Init(Vector2Int pos, PlayerModel player, DiscModel model)
    {
        _model = model;
        _model.Init(pos, player);
        Bind(model);

        transform.position = new Vector3(pos.x, pos.y, 0);
    }
Exemple #31
0
 public DvdTrackInfo(DiscModel model, string deviceNode)
     : base(model)
 {
     Uri = new SafeUri (String.Format ("dvd://{0}", deviceNode));
 }