Exemplo n.º 1
0
        public MovieViewModel(IMovieMetadataService metadataService,
                              IMovieViewModelFactory viewModelFactory,
                              IFileSystemService fileSystemService,
                              IProgressManagerViewModel progressManager,
                              IBusyProvider busyProvider,
                              IDialogViewer dialogViewer,
                              IKeyDataStore keyDataStore,
                              string path)
            : base(busyProvider, dialogViewer)
        {
            _metadataService   = metadataService;
            _viewModelFactory  = viewModelFactory;
            _fileSystemService = fileSystemService;
            _busyProvider      = busyProvider;
            RefreshCommand     = new RefreshMetadataCommand(this);
            UpdateCommand      = new UpdateMetadataCommand(this, progressManager, busyProvider);
            SaveCommand        = new SaveMetadataCommand(this);
            DeleteCommand      = new DeleteMetadataCommand(this);

            Title = new RequiredPropertyDecorator <string>(new StringCachedPropertyDecorator(keyDataStore, path + "?title"));
            Title.PropertyChanged += TitlePropertyChanged;
            SetName = new StringCachedPropertyDecorator(keyDataStore, path + "?setName");
            SetName.PropertyChanged += TitlePropertyChanged;
            Path         = path;
            Selection    = viewModelFactory.GetSelection(this);
            Poster       = viewModelFactory.GetImage(new PosterImageStrategy(metadataService, this));
            Fanart       = viewModelFactory.GetImage(new FanartImageStrategy(metadataService, this));
            Credits      = new DashDelimitedCollectionViewModel <string>(s => s);
            Directors    = new DashDelimitedCollectionViewModel <string>(s => s);
            Genres       = new DashDelimitedCollectionViewModel <string>(s => s);
            ActorManager = viewModelFactory.GetActorManager(path, () => OnPropertyChanged("ActorManager"));
        }
        public void Constructor_WhenValueIsntCached_DoesNothing()
        {
            // Act
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);

            // Assert
            Assert.True(string.IsNullOrEmpty(viewModel.Value));
            Assert.True(string.IsNullOrEmpty(viewModel.OriginalValue));
        }
        public void SetValue_Never_ChangesCachedValue()
        {
            // Arrange
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);

            // Act
            viewModel.Value = "Game of Thrones";

            // Assert
            Assert.True(string.IsNullOrEmpty(viewModel.OriginalValue));
        }
        public void Save_Always_SetsValueToCachedValue()
        {
            // Arrange
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);
            viewModel.Value = "Game of Thrones";

            // Act
            viewModel.Save();

            // Assert
            Assert.Equal("Game of Thrones", viewModel.OriginalValue);
        }
        public void Save_Always_SavesTheValueInTheCache()
        {
            // Arrange
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);
            viewModel.Value = "Game of Thrones";

            // Act
            viewModel.Save();

            // Assert
            _keyDataStore.Received()
                .SetValue(_key, "Game of Thrones");
        }
        public void Constructor_WhenValueIsCached_SetsValue()
        {
            // Arrange
            _keyDataStore.GetValue(_key)
                .Returns("Game of Thrones");

            // Act
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);

            // Assert
            Assert.Equal("Game of Thrones", viewModel.Value);
            Assert.Equal("Game of Thrones", viewModel.OriginalValue);
        }
        public void HasErrors_WhenPropertyIsntRequiredAndMissing_ReturnsFalse()
        {
            // Arrange
            var viewModel = new StringCachedPropertyDecorator(_keyDataStore, _key);
            viewModel.Value = string.Empty;

            // Act
            bool hasErrors = viewModel.HasErrors;

            // Assert
            Assert.False(hasErrors);
        }