예제 #1
0
        public void TextSetter_EnabledSetter_Change()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "test";
            var    textSetter = new TextSetter(TextSetterType.Note)
            {
                IsChecked = true, Value = targetText
            };
            var command  = TextSetterCommand.Create(textSetter);
            var expected = Mapper.Map <Transaction[]>(Mapper.Map <CashManager.Data.DTO.Transaction[]>(_transactions));

            foreach (var transaction in expected)
            {
                transaction.Notes = new TrulyObservableCollection <Note> {
                    new Note(targetText)
                }
            }
            ;

            //when
            var result = command.Execute(_transactions);

            //then
            Assert.Equal(expected.Select(x => x.Notes), result.Select(x => x.Notes));
        }
예제 #2
0
        public void TextSetter_DisabledSetter_NoChange()
        {
            //given
            var textSetter = new TextSetter(TextSetterType.Title);
            var command    = TextSetterCommand.Create(textSetter);

            //when
            var result = command.Execute(_transactions);

            //then
            Assert.Equal(_transactions.Select(x => x.Title), result.Select(x => x.Title));
        }
예제 #3
0
        public void TextSetter_DisabledSetter_NoChange()
        {
            //given
            var textSetter = new TextSetter(TextSetterType.Note);
            var command    = TextSetterCommand.Create(textSetter);

            //when
            var result = command.Execute(_positions);

            //then
            Assert.Equal(_positions.Select(x => x.Parent.Notes), result.Select(x => x.Parent.Notes));
        }
예제 #4
0
        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));
        }
예제 #5
0
        public void TextSetter_EnabledSetter_Change()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "title";
            var    textSetter = new TextSetter(TextSetterType.Title)
            {
                IsChecked = true, Value = targetText
            };
            var command  = TextSetterCommand.Create(textSetter);
            var expected = new[] { targetText, targetText, targetText, targetText };

            //when
            var result = command.Execute(GetPositions());

            //then
            Assert.Equal(expected, result.Select(x => x.Parent.Title));
        }
        public void TextSetter_EnabledSetterAppend_Appended()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "test";
            var    textSetter = new TextSetter(TextSetterType.PositionTitle)
            {
                IsChecked = true, Value = targetText, AppendMode = true
            };
            var command  = TextSetterCommand.Create(textSetter);
            var expected = new[] { _positions[0].Title + targetText, _positions[1].Title + targetText, _positions[2].Title + targetText };

            //when
            var result = command.Execute(_positions);

            //then
            Assert.Equal(expected, result.Select(x => x.Title));
        }
예제 #7
0
        public void TextSetter_EnabledSetterAppend_Appended()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "test";
            var    textSetter = new TextSetter(TextSetterType.Note)
            {
                IsChecked = true, Value = targetText, AppendMode = true
            };
            var command  = TextSetterCommand.Create(textSetter);
            var expected = new[] { "Note 1test", "Note 2test", "Note 3test" };

            //when
            var result = command.Execute(_positions);

            //then
            Assert.Equal(expected, result.SelectMany(x => x.Parent.Notes.Select(y => y.Value)));
        }
예제 #8
0
        public void TextSetter_EnabledSetterAppend_Appended()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "title";
            var    textSetter = new TextSetter(TextSetterType.Title)
            {
                IsChecked = true, Value = targetText, AppendMode = true
            };
            var command   = TextSetterCommand.Create(textSetter);
            var positions = GetPositions();
            var expected  = positions.Select(x => $"{x.Parent.Title}{targetText}").ToArray();

            //when
            var result = command.Execute(positions);

            //then
            Assert.Equal(expected, result.Select(x => x.Parent.Title));
        }
예제 #9
0
        public void TextSetter_EnabledSetterReplaceMatch_OnlyMatchReplaced()
        {
            //given
            MapperConfiguration.Configure();
            string targetText   = "title";
            var    textSelector = new TextSelector(TextSelectorType.Title)
            {
                IsChecked = true, Value = "it"
            };
            var textSetter = new TextSetter(TextSetterType.Title)
            {
                IsChecked = true, Value = targetText, ReplaceMatch = true
            };
            var command  = TextSetterCommand.Create(textSetter, textSelector);
            var expected = new[] { "Ttitlele 1", "Ttitlele 2", "Ttitlele 3" };

            //when
            var result = command.Execute(_transactions);

            //then
            Assert.Equal(expected, result.Select(x => x.Title));
        }
예제 #10
0
        public void TextSetter_EnabledSetterReplaceRegexMatch_OnlyMatchReplaced()
        {
            //given
            MapperConfiguration.Configure();
            string targetText   = "X";
            var    textSelector = new TextSelector(TextSelectorType.Note)
            {
                IsChecked = true, Value = @"\d", IsRegex = true
            };
            var textSetter = new TextSetter(TextSetterType.Note)
            {
                IsChecked = true, Value = targetText, ReplaceMatch = true
            };
            var command  = TextSetterCommand.Create(textSetter, textSelector);
            var expected = new[] { "Note X", "Note X", "Note X" };

            //when
            var result = command.Execute(_transactions);

            //then
            Assert.Equal(expected, result.SelectMany(x => x.Notes.Select(y => y.Value)));
        }
예제 #11
0
        public void TextSetter_EnabledSetterAppend_Appended()
        {
            //given
            MapperConfiguration.Configure();
            string targetText = "title";
            var    textSetter = new TextSetter(TextSetterType.Title)
            {
                IsChecked = true, Value = targetText, AppendMode = true
            };
            var command  = TextSetterCommand.Create(textSetter);
            var expected = Mapper.Map <Transaction[]>(Mapper.Map <CashManager.Data.DTO.Transaction[]>(_transactions));

            foreach (var transaction in expected)
            {
                transaction.Title += targetText;
            }

            //when
            var result = command.Execute(_transactions);

            //then
            Assert.Equal(expected.Select(x => x.Title), result.Select(x => x.Title));
        }