public async void Delete_EntryNotFound()
        {
            // Arrange
            var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator);
            var accountRepository          = new AccountRepository(ambientDbContextLocator);

            AccountEntity testAccount;

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                testAccount = new AccountEntity {
                    Name = "testAccount"
                };
                accountRepository.Add(testAccount);
                await dbContextScope.SaveChangesAsync();
            }

            var testEntry = new RecurringPaymentEntity {
                ChargedAccount = testAccount
            };

            // Act / Assert
            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                recurringPaymentRepository.Delete(testEntry);
                await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() => await dbContextScope.SaveChangesAsync());
            }
        }
Ejemplo n.º 2
0
        public void Save_ExistingEntryUpdated()
        {
            var recPaymentRepository =
                new RecurringPaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                                                                   new MvxWpfFileStore(FILE_ROOT)));
            var testRecurringPayment = new Fixture().Create <RecurringPaymentViewModel>();

            testRecurringPayment.Id = 0;

            try
            {
                recPaymentRepository.Save(testRecurringPayment);
                recPaymentRepository.FindById(testRecurringPayment.Id).ShouldNotBeNull();

                const string updatedNote = "FOOOOOOOOOO";
                testRecurringPayment.Note = updatedNote;

                recPaymentRepository.Save(testRecurringPayment);
                recPaymentRepository.FindById(testRecurringPayment.Id).Note.ShouldBe(updatedNote);
            }
            finally
            {
                recPaymentRepository.Delete(testRecurringPayment);
            }
        }
        public async void Delete_EntryMatchedFilterDeleted()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var filterText = "Text";
            var repository = new RecurringPaymentRepository(dbFactory);
            var testEntry1 = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = filterText
            };
            var testEntry2 = new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            };

            repository.Add(testEntry1);
            repository.Add(testEntry2);
            await unitOfWork.Commit();

            // Act
            repository.Delete(x => x.Note == filterText);
            await unitOfWork.Commit();

            // Assert
            Assert.Equal(1, repository.GetAll().Count());
        }
        public async void Delete_RelatedPaymentSetNull()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var recurringPaymentRepository = new RecurringPaymentRepository(dbFactory);
            var paymentRepository          = new PaymentRepository(dbFactory);

            var recurringPaymentEntity = new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            };
            var payment = new PaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                RecurringPayment = recurringPaymentEntity
            };

            paymentRepository.Add(payment);
            await unitOfWork.Commit();

            // Act
            recurringPaymentRepository.Delete(recurringPaymentEntity);
            await unitOfWork.Commit();

            // Assert
            Assert.Null(payment.RecurringPayment);
            Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment);
        }
Ejemplo n.º 5
0
        public void Delete_PaymentDeleted()
        {
            var recurringPaymentRepository =
                new RecurringPaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                                                                   new MvxWpfFileStore(FILE_ROOT)));
            var testRecurringPayment = new Fixture().Create <RecurringPaymentViewModel>();

            testRecurringPayment.Id = 0;

            recurringPaymentRepository.Save(testRecurringPayment);
            recurringPaymentRepository.FindById(testRecurringPayment.Id).ShouldNotBeNull();

            recurringPaymentRepository.Delete(testRecurringPayment);
            recurringPaymentRepository.FindById(testRecurringPayment.Id).ShouldBeNull();
        }
        public async void Delete_RelatedPaymentSetNull()
        {
            // Arrange
            var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator);
            var paymentRepository          = new PaymentRepository(ambientDbContextLocator);
            var accountRepository          = new AccountRepository(ambientDbContextLocator);

            AccountEntity testAccount;

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                testAccount = new AccountEntity {
                    Name = "testAccount"
                };
                accountRepository.Add(testAccount);
                await dbContextScope.SaveChangesAsync();
            }

            var recurringPaymentEntity = new RecurringPaymentEntity {
                ChargedAccount = testAccount
            };
            var payment = new PaymentEntity
            {
                ChargedAccount   = testAccount,
                RecurringPayment = recurringPaymentEntity
            };

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                paymentRepository.Add(payment);
                await dbContextScope.SaveChangesAsync();
            }

            // Act
            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                recurringPaymentRepository.Delete(recurringPaymentEntity);
                await dbContextScope.SaveChangesAsync();
            }

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                Assert.Null(payment.RecurringPayment);
                Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment);
            }
        }
        public async void Delete_EntryMatchedFilterDeleted()
        {
            // Arrange
            var filterText = "Text";
            var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator);
            var accountRepository          = new AccountRepository(ambientDbContextLocator);

            AccountEntity testAccount;

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                testAccount = new AccountEntity {
                    Name = "testAccount"
                };
                accountRepository.Add(testAccount);
                await dbContextScope.SaveChangesAsync();
            }

            var testEntry1 = new RecurringPaymentEntity
            {
                ChargedAccount = testAccount,
                Note           = filterText
            };

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                var testEntry2 = new RecurringPaymentEntity {
                    ChargedAccount = testAccount
                };
                recurringPaymentRepository.Add(testEntry1);
                recurringPaymentRepository.Add(testEntry2);
                await dbContextScope.SaveChangesAsync();
            }

            // Act
            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                recurringPaymentRepository.Delete(x => x.Note == filterText);
                await dbContextScope.SaveChangesAsync();
            }

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                Assert.Equal(1, recurringPaymentRepository.GetAll().Count());
            }
        }
        public async void Delete_EntryNotFound()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);
            var testEntry  = new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            };

            // Act
            repository.Delete(testEntry);

            // Assert
            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() => await unitOfWork.Commit());
        }
Ejemplo n.º 9
0
        public void Save_IdSet()
        {
            var recurringPaymentRepository =
                new RecurringPaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                                                                   new MvxWpfFileStore(FILE_ROOT)));
            var testRecurringPayment = new Fixture().Create <RecurringPaymentViewModel>();

            testRecurringPayment.Id = 0;

            try
            {
                recurringPaymentRepository.Save(testRecurringPayment);
                testRecurringPayment.Id.ShouldBeGreaterThan(0);
            }
            finally
            {
                recurringPaymentRepository.Delete(testRecurringPayment);
            }
        }
Ejemplo n.º 10
0
        public void GetList_WithFilter()
        {
            var recurringPaymentRepository =
                new RecurringPaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                                                                   new MvxWpfFileStore(FILE_ROOT)));
            var testRecurringPayment = new Fixture().Create <RecurringPaymentViewModel>();

            testRecurringPayment.Id = 0;

            try
            {
                recurringPaymentRepository.Save(testRecurringPayment);

                recurringPaymentRepository.GetList(x => x.Id == testRecurringPayment.Id).First().Id.ShouldBe(testRecurringPayment.Id);
                recurringPaymentRepository.GetList(x => x.Id == 99).FirstOrDefault().ShouldBeNull();
            }
            finally
            {
                recurringPaymentRepository.Delete(testRecurringPayment);
            }
        }
        public async void Delete_EntryDeleted()
        {
            // Arrange
            var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator);
            var accountRepository          = new AccountRepository(ambientDbContextLocator);

            AccountEntity testAccount;

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                testAccount = new AccountEntity {
                    Name = "testAccount"
                };
                accountRepository.Add(testAccount);
                await dbContextScope.SaveChangesAsync();
            }

            var testEntry = new RecurringPaymentEntity {
                ChargedAccount = testAccount
            };

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                recurringPaymentRepository.Add(testEntry);
                await dbContextScope.SaveChangesAsync();
            }

            // Act
            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                recurringPaymentRepository.Delete(testEntry);
                await dbContextScope.SaveChangesAsync();
            }

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                Assert.Equal(0, recurringPaymentRepository.GetAll().Count());
            }
        }
        public async void Delete_EntryDeleted()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);
            var testEntry  = new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            };

            repository.Add(testEntry);
            await unitOfWork.Commit();

            // Act
            repository.Delete(testEntry);
            await unitOfWork.Commit();

            // Assert
            Assert.Equal(0, repository.GetAll().Count());
        }
Ejemplo n.º 13
0
        public void GetList_WithoutFilter()
        {
            var recurringPaymentRepository =
                new RecurringPaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(),
                                                                   new MvxWpfFileStore(FILE_ROOT)));
            var testRecurringPayment = new Fixture().Create <RecurringPaymentViewModel>();

            testRecurringPayment.Id = 0;

            try
            {
                recurringPaymentRepository.Save(testRecurringPayment);

                var selectedAccount = recurringPaymentRepository.GetList().First();

                selectedAccount.Id.ShouldBe(testRecurringPayment.Id);
                selectedAccount.Amount.ShouldBe(testRecurringPayment.Amount);
            }
            finally
            {
                recurringPaymentRepository.Delete(testRecurringPayment);
            }
        }