public void CustomCsvParserDtoToModelTests()
        {
            //given
            MapperConfiguration.Configure();
            var rules = new[]
            {
                new CashManager.Data.ViewModelState.Parsers.Rule {
                    IsOptional = true, Column = 5, Property = (int)TransactionField.Currency
                }
            };
            string columnSplitter = ";";
            var    parser         = new CashManager.Data.ViewModelState.Parsers.CustomCsvParser
            {
                ColumnSplitter = columnSplitter,
                Rules          = rules,
                Name           = "test"
            };

            //when
            var result = Mapper.Map <CustomCsvParser>(parser);

            //then
            Assert.NotNull(result);
            Assert.NotNull(result.ColumnSplitter);
            Assert.Equal(columnSplitter, result.ColumnSplitter);

            Assert.NotNull(result.Rules);
            Assert.Equal(rules[0].IsOptional, result.Rules[0].IsOptional);
            Assert.Equal(rules[0].Column, result.Rules[0].Column);
            Assert.Equal(rules[0].Property, (int)result.Rules[0].Property);

            Assert.Equal(parser.Name, result.Name);
        }
Пример #2
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));
        }
Пример #3
0
        public void MultiPickerFilter_CheckedValueSetMatchAllOf_MatchingResults()
        {
            //given
            var selectedValues = new[] { _tagA, _tagC };

            MapperConfiguration.Configure();
            var source   = _tags.Select(x => new Selectable(x)).ToArray();
            var selector = new MultiPicker(MultiPickerType.Tag, source)
            {
                IsChecked = true, CanMatchMultipleElements = true, ShouldMatchAllOfTheElements = true
            };

            foreach (var result in selector.ComboBox.InternalDisplayableSearchResults)
            {
                if (selectedValues.Any(x => x.Id == result.Id))
                {
                    result.IsSelected = true;
                }
            }

            var filter   = MultiPickerFilter.Create(selector);
            var expected = new[] { _positions[2] };

            //when
            var results = filter.Execute(_positions);

            //then
            Assert.Equal(expected.Length, results.Count());
            Assert.Equal(expected, results);
        }
Пример #4
0
        internal static IContainer GetContainer()
        {
            MapperConfiguration.Configure();
            var builder = AutofacConfiguration.ContainerBuilder();

            //override db register
            builder.Register(x => new LiteRepository(new LiteDatabase(new MemoryStream()))).SingleInstance().ExternallyOwned();

            builder.RegisterType <ApplicationViewModel>()
            .Named <ViewModelBase>(nameof(ApplicationViewModel))
            .As <ViewModelBase>()
            .As <ApplicationViewModel>()
            .SingleInstance();

            //search should be perform instantly in tests
            builder.Register(x =>
            {
                var vm = new SearchViewModel(
                    x.Resolve <IQueryDispatcher>(),
                    x.Resolve <ICommandDispatcher>(),
                    x.Resolve <ViewModelFactory>(),
                    x.Resolve <TransactionsProvider>())
                {
                    IsDebounceable = false
                };
                return(vm);
            })
            .As <SearchViewModel>()
            .Named <ViewModelBase>(nameof(SearchViewModel));

            return(builder.Build());
        }
        public void CustomCsvParserModelToDtoTests()
        {
            //given
            MapperConfiguration.Configure();
            var rules = new[]
            {
                new Rule {
                    IsOptional = true, Column = 5, Property = TransactionField.Currency
                }
            };
            string columnSplitter = ";";
            var    parser         = new CustomCsvParser(rules, null, columnSplitter)
            {
                Name = "test1"
            };

            //when
            var result = Mapper.Map <CashManager.Data.ViewModelState.Parsers.CustomCsvParser>(parser);

            //then
            Assert.NotNull(result);
            Assert.NotNull(result.ColumnSplitter);
            Assert.Equal(columnSplitter, result.ColumnSplitter);

            Assert.NotNull(result.Rules);
            Assert.Equal(rules[0].IsOptional, result.Rules[0].IsOptional);
            Assert.Equal(rules[0].Column, result.Rules[0].Column);
            Assert.Equal((int)rules[0].Property, result.Rules[0].Property);

            Assert.Equal(parser.Name, result.Name);
            Assert.Equal(parser.Name.GenerateGuid(), result.Id);
        }
        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 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));
        }
Пример #9
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));
        }
Пример #10
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));
        }
        public void AutoMapperMap_Transaction_SameTransactionTypeReference()
        {
            //given
            MapperConfiguration.Configure();
            var type = new CashManager.Data.DTO.TransactionType {
                Name = "refrence test", IsDefault = true
            };
            var transaction = new CashManager.Data.DTO.Transaction {
                Type = type
            };

            //when
            var firstMap  = Mapper.Map <Transaction>(transaction);
            var secondMap = Mapper.Map <Transaction>(transaction);

            //then
            Assert.Equal(type.Id, firstMap.Type.Id);
            Assert.Equal(type.Id, secondMap.Type.Id);

            Assert.Same(firstMap.Type, secondMap.Type);
        }
Пример #12
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));
        }
Пример #13
0
        public void UpsertSearchStateCommandHandler_UpsertOneObjectWithoutNameNonEmptyDb_OneInstanceOfSavedObjectInDb()
        {
            //given
            MapperConfiguration.Configure();
            var searchState = new Features.Search.SearchState();
            var state       = Mapper.Map <SearchState>(searchState);

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertSearchStateCommandHandler(repository);
            var command    = new UpsertSearchStateCommand(state);

            repository.Database.Upsert(Mapper.Map <SearchState>(new Features.Search.SearchState()));

            //when
            handler.Execute(command);

            //then
            var result = repository.Database.Query <SearchState>().ToArray();

            Assert.Single(result);
            Assert.Equal(state, result[0]);
        }
Пример #14
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)));
        }
Пример #15
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));
        }
        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);
        }
 public ModelAndDtoMappingTests()
 {
     MapperConfiguration.Configure();
 }