Exemple #1
0
        public void TestUpdateDetails()
        {
            using (var mock = AutoMock.GetStrict()) {
                var settings = mock.Mock <ISettings>();
                settings.SetupGet(m => m.DataFilename).Returns("song.xml");

                var fileSystem = mock.Mock <IFileSystem>();
                fileSystem.Setup(m => m.Path.Combine(@"C:\test\bla", "song.xml")).Returns(@"C:\test\bla\song.xml");

                var song = new SongModel {
                    Path = @"C:\test\bla"
                };
                var data = new DirectoryData {
                    Status = DirectoryStatus.SONG, Song = song
                };

                var exporter = mock.Mock <IExporter>();
                exporter.Setup(m => m.Write(@"C:\test\bla\song.xml", data));

                var songService = mock.Create <Song>();

                songService.UpdateDetails(song);

                settings.VerifyGet(m => m.DataFilename, Times.Once);
                fileSystem.Verify(m => m.Path.Combine(@"C:\test\bla", "song.xml"), Times.Once);
                exporter.Verify(m => m.Write(@"C:\test\bla\song.xml", data), Times.Once);
            }
        }
        public void TestAddSong()
        {
            using (var mock = AutoMock.GetStrict()) {
                var collection = new ObservableCollection <IDirectoryListItem>();
                var song       = new SongModel {
                    Name = "Lied"
                };

                var songViewModel = mock.Mock <ISongViewModel>();
                songViewModel.SetupSet(m => m.Song = song);

                var dispatcher = mock.Mock <IDispatcher>();
                dispatcher.Setup(m => m.Invoke(It.IsAny <Action>())).Callback <Action>(action => action());

                var model = mock.Mock <IDirectoryCollectionProperty>();
                model.SetupGet(m => m.Directories).Returns(collection);

                var directoriesService = mock.Create <Directories>();

                directoriesService.AddSong(song);

                Assert.AreEqual(1, collection.Count);
                Assert.IsTrue(collection.Contains(songViewModel.Object));

                songViewModel.VerifySet(m => m.Song = song, Times.Once);
                dispatcher.Verify(m => m.Invoke(It.IsAny <Action>()), Times.Once);
                model.VerifyGet(m => m.Directories, Times.Once);
            }
        }
Exemple #3
0
        public void UpdateDetails(SongModel song)
        {
            var path = fileSystem.Path.Combine(song.Path, settings.DataFilename);
            var data = new DirectoryData {
                Status = DirectoryStatus.SONG, Song = song
            };

            exporter.Write(path, data);
        }
Exemple #4
0
        public void TestSaveDetailsExecute()
        {
            using (var mock = AutoMock.GetStrict()) {
                var song = new Song {
                    Name = "test"
                };

                var songService = mock.Mock <ISong>();
                songService.Setup(m => m.UpdateDetails(song));

                var viewModel   = mock.Create <SongViewModel>();
                var saveDetails = viewModel.SaveDetails;

                viewModel.Song = song;
                viewModel.SaveDetails.Execute(null);

                Assert.IsInstanceOfType(saveDetails, typeof(RelayCommand));

                songService.Verify(m => m.UpdateDetails(song), Times.Once);
            }
        }
Exemple #5
0
        public void TestStartWithSubFolderWithSongObject()
        {
            using (var mock = AutoMock.GetStrict()) {
                var fileSystem = new MockFileSystem(
                    new Dictionary <string, MockFileData> {
                    { @"C:\root\", new MockDirectoryData() },
                    { @"C:\root\bla\", new MockDirectoryData() },
                    { @"C:\root\bla\song.xml", new MockFileData("xml")
                      {
                          Attributes = FileAttributes.Hidden
                      } }
                });
                mock.Provide <IFileSystem>(fileSystem);

                var settings = mock.Mock <ISettings>();
                settings.SetupGet(m => m.DataPath).Returns(@"C:\root");
                settings.SetupGet(m => m.DataFilename).Returns("song.xml");

                var expectedDirectoryData = new DirectoryData {
                    Status = DirectoryStatus.SONG, Song = new SongModel()
                };
                var importer = mock.Mock <IImporter>();
                importer.Setup(m => m.Read <DirectoryData>(@"C:\root\bla\song.xml")).Returns(expectedDirectoryData);

                var expectedSong = new SongModel {
                    Path = @"C:\root\bla"
                };
                var directoriesService = mock.Mock <IDirectories>();
                directoriesService.Setup(m => m.AddSong(expectedSong));

                var checker = mock.Create <Checker>();

                checker.Start();

                settings.VerifyGet(m => m.DataPath, Times.Once);
                settings.VerifyGet(m => m.DataFilename, Times.Once);
                importer.Verify(m => m.Read <DirectoryData>(@"C:\root\bla\song.xml"), Times.Once);
                directoriesService.Verify(m => m.AddSong(expectedSong), Times.Once);
            }
        }