public async void Add_AddNewEntryOnEveryCall()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);

            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

            testEntry.Id = 0;
            repository.Add(testEntry);
            await unitOfWork.Commit();

            // Assert
            Assert.Equal(2, repository.GetAll().Count());
        }
Esempio n. 2
0
        public async void Add_AddedAndRead()
        {
            // Arrange
            var factory    = new DbFactory();
            var unitOfWork = new UnitOfWork(factory);

            var repository = new RecurringPaymentRepository(factory);

            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

            // Assert
            var loadedEntry = await repository.GetById(testEntry.Id);

            Assert.Equal(testEntry.Note, loadedEntry.Note);
        }
        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_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());
            }
        }
Esempio n. 5
0
        public void CheckIfRepeatable_ValidatedRecurrenceMonthly_False()
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentEntity
            {
                Id               = 4,
                Recurrence       = PaymentRecurrence.Monthly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(new Payment
            {
                Data =
                {
                    Date             = DateTime.Today.GetFirstDayOfMonth(),
                    IsCleared        = true,
                    RecurringPayment = recurringPayment
                }
            })
            .ShouldBeFalse();
        }
Esempio n. 6
0
        [InlineData(PaymentRecurrence.Quarterly, 355, true)]  // with year change
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed,
                                                          bool expectedResult)
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentEntity
            {
                Id               = 4,
                Recurrence       = recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(
                new Payment
            {
                Data =
                {
                    Date             = DateTime.Today.AddDays(-amountOfDaysPassed),
                    IsCleared        = true,
                    RecurringPayment = recurringPayment
                }
            })
            .ShouldBe(expectedResult);
        }
Esempio n. 7
0
        public void CheckIfRepeatable_UnclearedPayment_ReturnFalse(
            PaymentRecurrence recurrence, int amountOfDaysUntilRepeat)
        {
            var account = new AccountEntity {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentEntity
            {
                Id               = 4,
                Recurrence       = PaymentRecurrence.Weekly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(new Payment
            {
                Data =
                {
                    Date             = DateTime.Today.AddDays(amountOfDaysUntilRepeat),
                    RecurringPayment = recurringPayment
                }
            })
            .ShouldBeFalse();
        }
        public async void Update_EntryUpdated()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);

            var newValue  = "newText";
            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

            testEntry.Note = newValue;
            repository.Update(testEntry);
            await unitOfWork.Commit();

            // Assert
            var loadedEntry = await repository.GetById(testEntry.Id);

            Assert.Equal(newValue, loadedEntry.Note);
        }
        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);
        }
        public async void Get_MatchedDataReturned()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

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

            repository.Add(testEntry);
            repository.Add(new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            });
            repository.Add(new RecurringPaymentEntity {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                }
            });
            await unitOfWork.Commit();

            // Act
            var result = await repository.Get(x => x.Note == filterText);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(testEntry.Id, result.Id);
        }
        public async void Update_NoNewEntryAdded()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);

            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

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

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

            var repository = new RecurringPaymentRepository(dbFactory);

            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

            var idBeforeUpdate = testEntry.Id;

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

            // Assert
            Assert.Equal(idBeforeUpdate, testEntry.Id);
        }
        public async void Add_IdSet()
        {
            // 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,
                Note           = "Testtext"
            };

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

            // Assert
            Assert.NotNull(testEntry.Id);
            Assert.NotEqual(0, testEntry.Id);
        }
Esempio n. 14
0
        public async void Delete_AssignedRelatedPaymentsSetNull()
        {
            // Arrange
            var categoryRepository = new CategoryRepository(ambientDbContextLocator);
            var accountRepository  = new AccountRepository(ambientDbContextLocator);
            var paymentRepository  = new PaymentRepository(ambientDbContextLocator);

            var category = new CategoryEntity {
                Name = "TestCategory"
            };
            var account = new AccountEntity {
                Name = "testAccount"
            };
            var recurringPayment = new RecurringPaymentEntity
            {
                ChargedAccount = account,
                Category       = category
            };

            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                categoryRepository.Add(category);
                accountRepository.Add(account);
                await dbContextScope.SaveChangesAsync();
            }

            var payment = new PaymentEntity
            {
                ChargedAccount   = account,
                Category         = category,
                RecurringPayment = recurringPayment
            };

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

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

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                Assert.Null(recurringPayment.Category);
                Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment.Category);
            }
        }
Esempio n. 15
0
        private void SaveOrUpdateRecurringPayment(ApplicationContext dbContext, RecurringPaymentEntity recurringPayment)
        {
            if (recurringPayment.Id != 0)
            {
                recurringPayment.ChargedAccountId = recurringPayment.ChargedAccount.Id;
                recurringPayment.TargetAccountId  = recurringPayment.TargetAccount?.Id;
                recurringPayment.CategoryId       = recurringPayment.Category?.Id;
            }

            var recurringPaymentEntry = dbContext.Entry(recurringPayment);

            recurringPaymentEntry.State = recurringPayment.Id == 0 ? EntityState.Added : EntityState.Modified;
        }
        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_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 Update_EntryUpdated()
        {
            // 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 newValue  = "newText";
            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = testAccount,
                Note           = "Testtext"
            };

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

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

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                var loadedEntry = await recurringPaymentRepository.GetById(testEntry.Id);

                Assert.Equal(newValue, loadedEntry.Note);
            }
        }
        public async void Add_WithoutAccount()
        {
            // Arrange
            var factory    = new DbFactory();
            var unitOfWork = new UnitOfWork(factory);

            var repository = new RecurringPaymentRepository(factory);

            var testEntry = new RecurringPaymentEntity()
            {
                Note = "Testtext"
            };

            // Act / Assert
            repository.Add(testEntry);
            await Assert.ThrowsAsync <DbUpdateException>(async() => await unitOfWork.Commit());
        }
        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());
        }
        public async void Get_MatchedDataReturned()
        {
            // Arrange
            var repository        = 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 filterText = "Text";
            var testEntry  = new RecurringPaymentEntity
            {
                ChargedAccount = testAccount,
                Note           = filterText
            };
            RecurringPaymentEntity result;

            // Act
            using (var dbContextScope = dbContextScopeFactory.Create())
            {
                repository.Add(testEntry);
                repository.Add(new RecurringPaymentEntity {
                    ChargedAccount = testAccount
                });
                repository.Add(new RecurringPaymentEntity {
                    ChargedAccount = testAccount
                });
                await dbContextScope.SaveChangesAsync();

                result = await repository.Get(x => x.Note == filterText);
            }

            // Assert
            Assert.NotNull(result);
            Assert.Equal(testEntry.Id, result.Id);
        }
        public async void Add_AddNewEntryOnEveryCall()
        {
            // 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,
                Note           = "Testtext"
            };

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

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

            // Assert
            using (dbContextScopeFactory.CreateReadOnly())
            {
                Assert.Equal(2, recurringPaymentRepository.GetAll().Count());
            }
        }
        public async void Update_IdUnchanged()
        {
            // 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,
                Note           = "Testtext"
            };

            int idBeforeUpdate;

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

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

            // Assert
            Assert.Equal(idBeforeUpdate, testEntry.Id);
        }
Esempio n. 24
0
        public async void Delete_AssignedRelatedPaymentsSetNull()
        {
            // Arrange
            var factory    = new DbFactory();
            var unitOfWork = new UnitOfWork(factory);

            var categoryRepository = new CategoryRepository(factory);
            var paymentRepository  = new PaymentRepository(factory);

            var category = new CategoryEntity {
                Name = "TestCategory"
            };
            var recurringPayment = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Category = category
            };
            var payment = new PaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Category         = category,
                RecurringPayment = recurringPayment
            };

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

            // Act
            categoryRepository.Delete(category);
            await unitOfWork.Commit();

            // Assert
            Assert.Null(recurringPayment.Category);
            Assert.Null(paymentRepository.GetById(payment.Id).Result.RecurringPayment.Category);
        }
        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());
        }
        public async void Add_IdSet()
        {
            // Arrange
            var unitOfWork = new UnitOfWork(dbFactory);

            var repository = new RecurringPaymentRepository(dbFactory);

            var testEntry = new RecurringPaymentEntity
            {
                ChargedAccount = new AccountEntity {
                    Name = "testAccount"
                },
                Note = "Testtext"
            };

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

            // Assert
            Assert.NotNull(testEntry.Id);
            Assert.NotEqual(0, testEntry.Id);
        }
Esempio n. 27
0
 /// <summary>
 ///     Set the data for this object.
 /// </summary>
 /// <param name="recurringPayment">Payment data to wrap.</param>
 public RecurringPayment(RecurringPaymentEntity recurringPayment)
 {
     Data = recurringPayment;
 }
Esempio n. 28
0
 /// <summary>
 ///     Default constructor. Will Create a new RecurringPaymentEntity
 /// </summary>
 public RecurringPayment()
 {
     Data = new RecurringPaymentEntity();
 }