예제 #1
0
        public void UpsertTransactionCommandHandler_EmptyDbUpsertList_ListSaved()
        {
            //given
            var transactionTypes = new[]
            {
                new TransactionType {
                    Name = "t1", Outcome = true
                }
            };

            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertTransactionTypesCommandHandler(repository);
            var command    = new UpsertTransactionTypesCommand(transactionTypes);

            //when
            handler.Execute(command);

            //then
            var orderedTransactionTypesInDatabase = repository.Database.Query <TransactionType>().OrderBy(x => x.Id).ToArray();
            var orderedTransactionTypes           = transactionTypes.OrderBy(x => x.Id).ToArray();

            Assert.Equal(orderedTransactionTypes, orderedTransactionTypesInDatabase);
            Assert.Equal(orderedTransactionTypes.Select(x => x.Name), orderedTransactionTypesInDatabase.Select(x => x.Name));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Id), orderedTransactionTypesInDatabase.Select(x => x.Id));
            Assert.Equal(orderedTransactionTypes.Select(x => x.IsDefault), orderedTransactionTypesInDatabase.Select(x => x.IsDefault));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Income), orderedTransactionTypesInDatabase.Select(x => x.Income));
            Assert.Equal(orderedTransactionTypes.Select(x => x.Outcome), orderedTransactionTypesInDatabase.Select(x => x.Outcome));
        }
예제 #2
0
        public void UpsertTransactionCommandHandler_NullEmptyDb_EmptyDb()
        {
            //given
            var repository = LiteDbHelper.CreateMemoryDb();
            var handler    = new UpsertTransactionTypesCommandHandler(repository);
            var command    = new UpsertTransactionTypesCommand((TransactionType)null);

            //when
            handler.Execute(command);

            //then
            Assert.Empty(repository.Database.Query <Transaction>());
        }