public void DateSetter_DisabledSetter_NoChange() { //given var dateSetter = new DateSetter(DateSetterType.BookDate); var command = DateSetterCommand.Create(dateSetter); //when var result = command.Execute(_transactions); //then Assert.Equal(_transactions, result); }
public MassReplacerViewModel(IQueryDispatcher queryDispatcher, ICommandDispatcher commandDispatcher, ViewModelFactory factory, IMessagesService messagesService) { _queryDispatcher = queryDispatcher; _commandDispatcher = commandDispatcher; _messagesService = messagesService; State = new ReplacerState(); SearchViewModel = factory.Create <SearchViewModel>(); PerformReplaceCommand = new RelayCommand(ExecutePerformCommand, CanExecutePerformCommand); ApplyReverseReplaceSearchStateCommand = new RelayCommand(() => SearchViewModel.State.ApplyReverseReplaceCriteria(State), () => _transactionSetters.Any(x => x.CanExecute())); _transactionSetters = new ISetter <Model.Transaction>[] { TextSetterCommand.Create(State.TitleSelector, SearchViewModel.State.TitleFilter), TextSetterCommand.Create(State.NoteSelector, SearchViewModel.State.NoteFilter), TextSetterCommand.Create(State.PositionTitleSelector, SearchViewModel.State.PositionTitleFilter), DateSetterCommand.Create(State.BookDateSetter), SingleSetterCommand.Create(State.CategoriesSelector), SingleSetterCommand.Create(State.UserStocksSelector), SingleSetterCommand.Create(State.ExternalStocksSelector), SingleSetterCommand.Create(State.TypesSelector), MultiSetterCommand.Create(State.TagsSelector) }; _positionSetter = _transactionSetters.OfType <ISetter <Model.Position> >().ToArray(); MassReplacerSaveCommand = new RelayCommand <string>(name => { State.Name = name; State.SearchState = SearchViewModel.State; var state = Mapper.Map <MassReplacerState>(State); _commandDispatcher.Execute(new UpsertReplacerStateCommand(state)); var mapped = Mapper.Map <ReplacerState>(state); Patterns.Remove(mapped); Patterns.Add(mapped); }, name => !string.IsNullOrWhiteSpace(name)); MassReplacerLoadCommand = new RelayCommand <BaseObservableObject>(selected => { var state = selected as ReplacerState; ApplyState(state); }, selected => selected != null); ClearMassReplacerStateCommand = new RelayCommand(() => State.Clear()); var patterns = _queryDispatcher.Execute <ReplacerStateQuery, MassReplacerState[]>(new ReplacerStateQuery()) .OrderBy(x => x.Name); Patterns = new ObservableCollection <BaseObservableObject>(Mapper.Map <ReplacerState[]>(patterns)); }
public void DateSetter_EnabledSetter_Change() { //given MapperConfiguration.Configure(); var targetDate = DateTime.Today.AddDays(-1); var dateSetter = new DateSetter(DateSetterType.BookDate) { IsChecked = true, Value = targetDate }; var command = DateSetterCommand.Create(dateSetter); //when var result = command.Execute(_positions); //then Assert.All(result.Select(x => x.BookDate), time => Assert.Equal(targetDate, time)); Assert.All(result.Select(x => x.Parent.BookDate), time => Assert.Equal(targetDate, time)); }
public void DateSetter_EnabledSetter_Change() { //given MapperConfiguration.Configure(); var targetDate = DateTime.Today.AddDays(-1); var dateSetter = new DateSetter(DateSetterType.BookDate) { IsChecked = true, Value = targetDate }; var command = DateSetterCommand.Create(dateSetter); //when var result = command.Execute(_transactions); //then Assert.All(result.Select(x => x.BookDate), time => Assert.Equal(targetDate, time)); var expected = Mapper.Map <Transaction[]>(Mapper.Map <CashManager.Data.DTO.Transaction[]>(_transactions)); foreach (var transaction in expected) { transaction.BookDate = targetDate; } Assert.Equal(expected, result); }