public void Save_IdSet() { var accountRepo = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var testAccount = new Fixture().Create<AccountViewModel>(); testAccount.Id = 0; try { accountRepo.Save(testAccount); testAccount.Id.ShouldBeGreaterThan(0); } finally { accountRepo.Delete(testAccount); } }
public void Save_ExistingEntryUpdated() { var accountRepo = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var testAccount = new Fixture().Create<AccountViewModel>(); testAccount.Id = 0; try { accountRepo.Save(testAccount); accountRepo.FindById(testAccount.Id).ShouldNotBeNull(); const string updatedName = "FOOOOOOOOOO"; testAccount.Name = updatedName; accountRepo.Save(testAccount); accountRepo.FindById(testAccount.Id).Name.ShouldBe(updatedName); } finally { accountRepo.Delete(testAccount); } }
public void GetList_WithoutFilter() { var accountRepo = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var testAccount = new Fixture().Create<AccountViewModel>(); testAccount.Id = 0; try { accountRepo.Save(testAccount); var selectedAccount = accountRepo.GetList().First(); selectedAccount.Id.ShouldBe(testAccount.Id); selectedAccount.Name.ShouldBe(testAccount.Name); } finally { accountRepo.Delete(testAccount); } }
public void FindById_AccountDeleted() { var accountRepo = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var testAccount = new Fixture().Create<AccountViewModel>(); testAccount.Id = 0; accountRepo.Save(testAccount); var selected = accountRepo.FindById(testAccount.Id); selected.ShouldNotBeNull(); selected.ShouldBeInstanceOf<AccountViewModel>(); accountRepo.Delete(testAccount); accountRepo.FindById(testAccount.Id).ShouldBeNull(); }
public void GetList_WithFilter() { var accountRepo = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var testAccount = new Fixture().Create<AccountViewModel>(); testAccount.Id = 0; try { accountRepo.Save(testAccount); accountRepo.GetList(x => x.Id == testAccount.Id).First().Id.ShouldBe(testAccount.Id); accountRepo.GetList(x => x.Id == 99).FirstOrDefault().ShouldBeNull(); } finally { accountRepo.Delete(testAccount); } }
public void GetList_WithRecurringPayment_RecPaymentDependenciesLoaded() { var paymentRepository = new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var accountRepository = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var fixture = new Fixture(); var account = fixture.Create<AccountViewModel>(); account.Id = 0; accountRepository.Save(account); var testPayment = fixture.Create<PaymentViewModel>(); testPayment.Id = 0; testPayment.RecurringPaymentId = 0; testPayment.RecurringPayment.Id = 0; testPayment.IsRecurring = true; testPayment.ChargedAccount = account; testPayment.RecurringPayment.ChargedAccount = account; paymentRepository.Save(testPayment); paymentRepository.ReloadCache(); var selected = paymentRepository.GetList(x => x.Id == testPayment.Id).First(); selected.ShouldNotBeNull(); selected.ShouldBeInstanceOf<PaymentViewModel>(); selected.RecurringPayment.ShouldNotBeNull(); selected.RecurringPayment.Id.ShouldBe(selected.RecurringPaymentId); selected.RecurringPayment.Id.ShouldBe(testPayment.RecurringPayment.Id); selected.RecurringPayment.ChargedAccount.ShouldNotBeNull(); paymentRepository.Delete(testPayment); paymentRepository.FindById(testPayment.Id).ShouldBeNull(); }
public void Save_WithTargetAccount_FkSet() { var paymentRepository = new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var accountRepository = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var fixture = new Fixture(); var account = fixture.Create<AccountViewModel>(); accountRepository.Save(account); paymentRepository.ReloadCache(); account.Id.ShouldBeGreaterThan(0); var testPayment = new Fixture().Create<PaymentViewModel>(); testPayment.Id = 0; testPayment.TargetAccount = account; paymentRepository.Save(testPayment); paymentRepository.FindById(testPayment.Id).TargetAccountId.ShouldBe(account.Id); }
public void SaveAndUpdate_WithTargetAccount_NoDuplicates() { var paymentRepository = new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var accountRepository = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var account = new Fixture().Create<AccountViewModel>(); account.Id = 0; accountRepository.Save(account); var testPayment = new Fixture().Create<PaymentViewModel>(); testPayment.Id = 0; testPayment.TargetAccount = account; paymentRepository.Save(testPayment); paymentRepository.Save(testPayment); paymentRepository.ReloadCache(); var selected = paymentRepository.FindById(testPayment.Id); accountRepository.GetList(x => x.Name == testPayment.TargetAccount.Name).Count().ShouldBe(1); }
public void Save_WithTargetAccount() { var paymentRepository = new PaymentRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var accountRepository = new AccountRepository(new DatabaseManager(new WindowsSqliteConnectionFactory(), new MvxWpfFileStore(FILE_ROOT))); var account = new Fixture().Create<AccountViewModel>(); account.Id = 0; accountRepository.Save(account); var testPayment = new Fixture().Create<PaymentViewModel>(); testPayment.Id = 0; testPayment.ChargedAccount = account; testPayment.TargetAccount = null; paymentRepository.Save(testPayment); paymentRepository.ReloadCache(); var selected = paymentRepository.FindById(testPayment.Id); selected.ShouldNotBeNull(); selected.ShouldBeInstanceOf<PaymentViewModel>(); selected.ChargedAccount.ShouldNotBeNull(); selected.ChargedAccount.Id.ShouldBe(selected.ChargedAccountId); selected.ChargedAccount.Id.ShouldBe(testPayment.ChargedAccount.Id); paymentRepository.Delete(testPayment); paymentRepository.FindById(testPayment.Id).ShouldBeNull(); }