public async void GetAll_AllDataReturned() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Act var resultList = repository.GetAll().ToList(); // Assert Assert.NotNull(resultList); Assert.Equal(3, resultList.Count); }
public async void Add_AddMultipleEntries() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); // Act repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); repository.Add(new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" } }); await unitOfWork.Commit(); // Assert Assert.Equal(3, repository.GetAll().Count()); }
public async void Delete_EntryMatchedFilterDeleted() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var filterText = "Text"; var repository = new PaymentRepository(dbFactory); var testEntry1 = new PaymentEntity { ChargedAccount = new AccountEntity { Name = "testAccount" }, Note = filterText }; var testEntry2 = new PaymentEntity { 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 Add_AddNewEntryOnEveryCall() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); var testEntry = new PaymentEntity { 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()); }
public async void Update_NoNewEntryAdded() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); var testEntry = new PaymentEntity { 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 void Import(IEnumerable <P.Payment> payments) { var dbPayments = PaymentRepository.GetAll(); var paymentsById = RemoveDuplicate(payments, dbPayments); OnImport(paymentsById, dbPayments); }
public void UpdatePayment() { using (var uow = new CapriconContext()) { var paymentRep = new PaymentRepository(uow); var existingPayments = paymentRep.GetAll().ToList(); var existingPayment = existingPayments.Find(p => p.PaymentId == 3); Assert.IsNotNull(existingPayment); var messageRepository = new MessageRepository(uow); var existingMessage = messageRepository.GetAll().FirstOrDefault(); Assert.IsNotNull(existingMessage); existingPayment.PaymentDate = DateTime.Now; existingPayment.Amount = 350; existingPayment.Message = existingMessage; //check for validation rules //existingPayment.PaymentDate = DateTime.Now; paymentRep.Attach(existingPayment); uow.Entry(existingPayment).State = EntityState.Modified; try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); Assert.Fail("Test failed"); } }; //retrieve saved object var uow1 = new CapriconContext(); var repository = new PaymentRepository(uow1); var savedPayments = repository.GetAll().ToList(); Assert.AreEqual(savedPayments[0].Amount, 350); }
public void AddPayment() { using (CapriconContext context = new CapriconContext()) { var messageRepository = new MessageRepository(context); var existingMessage = messageRepository.GetAll().LastOrDefault(); Assert.IsNotNull(existingMessage); var newPayment = new Payment() { PaymentDate = DateTime.Now, Amount = 750, Message = existingMessage }; var paymentRep = new PaymentRepository(context); paymentRep.Add(newPayment); try { context.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); Assert.Fail("Test failed"); } //retrieve saved object var context1 = new CapriconContext(); var repository = new PaymentRepository(context1); var savedPayments = repository.GetAll().ToList(); Assert.AreEqual(savedPayments.Count(), 3, "returns 20 records"); var savedPaymentsList = savedPayments; savedPaymentsList.ForEach ( p => { Debug.WriteLine(p.PaymentId + " - " + p.Amount + " " + p.Message.MessageId); } ); }; }
public async void DeleteAccount_RelatedChargedPaymentsRemoved() { // Arrange var accountRepository = new AccountRepository(ambientDbContextLocator); var paymentRepository = new PaymentRepository(ambientDbContextLocator); var account = new AccountEntity { Name = "Testtext" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var payment = new PaymentEntity { Note = "Foo", ChargedAccount = account }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(payment); await dbContextScope.SaveChangesAsync(); Assert.Equal(1, await accountRepository.GetAll().CountAsync()); Assert.Equal(1, await paymentRepository.GetAll().CountAsync()); } using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Delete(account); await dbContextScope.SaveChangesAsync(); } // Assert using (var dbContextScope = dbContextScopeFactory.Create()) { Assert.False(await accountRepository.GetAll().AnyAsync()); Assert.False(await paymentRepository.GetAll().AnyAsync()); } }
public List <PaymentView> GetAllPayments() { using (var paymentrepo = new PaymentRepository()) { return(paymentrepo.GetAll().Select(x => new PaymentView() { PaymentId = x.PaymentId, PolicyHolderIdNo = x.IDNumber, PaymentMethod = x.PaymentMethod, AmountPaid = x.AmountPaid, PaymentFor = x.PaymentFor, Date = x.Date }).ToList()); } }
public void GetAll_NoData() { // Arrange var repository = new PaymentRepository(new DbFactory()); // Act var emptyList = repository.GetAll().ToList(); // Assert Assert.NotNull(emptyList); Assert.False(emptyList.Any()); }
public async void Test_GenericRepository_Update() { var options = new DbContextOptionsBuilder <AccountContext>() .UseInMemoryDatabase(databaseName: "Test2G") .Options; using (var ctx = new AccountContext(options)) { var profiles = new ProfileRepository(ctx); var payment = new PaymentRepository(ctx); var newProfile = new ProfileModel() { Id = 0, Email = "*****@*****.**", Name = null, Phone = "1234567897", Age = "Adult", AccountId = 1, Account = null }; var updateProfile = new ProfileModel() { Id = 1, Email = "*****@*****.**", Name = null, Phone = "2222222222", Age = "Child", AccountId = 1, Account = null }; await profiles.Add(newProfile); await ctx.SaveChangesAsync(); ctx.Entry <ProfileModel>(newProfile).State = EntityState.Detached; await profiles.Update(updateProfile); await ctx.SaveChangesAsync(); var actual = await profiles.GetAll(); var payments = await payment.GetAll(); var payments2 = await payment.Find(payment => payment.AccountId == 1); var phone = actual.First().Phone; Assert.Equal("2222222222", phone); Assert.Empty(payments); Assert.Empty(payments2); } }
public async void DeleteAccount_RelatedTargetPaymentSetNull() { // Arrange var accountRepository = new AccountRepository(ambientDbContextLocator); var paymentRepository = new PaymentRepository(ambientDbContextLocator); var chargedAccount = new AccountEntity { Name = "Charged" }; var targetAccount = new AccountEntity { Name = "Target" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(chargedAccount); accountRepository.Add(targetAccount); await dbContextScope.SaveChangesAsync(); } var payment = new PaymentEntity { Note = "Foo", ChargedAccount = chargedAccount, TargetAccount = targetAccount }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(payment); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { Assert.Equal(2, await accountRepository.GetAll().CountAsync()); Assert.Equal(1, await paymentRepository.GetAll().CountAsync()); accountRepository.Delete(targetAccount); await dbContextScope.SaveChangesAsync(); } // Assert Assert.Null(payment.TargetAccount); Assert.NotNull(payment.ChargedAccount); }
public void GetAll_NoData() { // Arrange var repository = new PaymentRepository(ambientDbContextLocator); List <PaymentEntity> resultList; // Act using (dbContextScopeFactory.CreateReadOnly()) { resultList = repository.GetAll().ToList(); } // Assert Assert.NotNull(resultList); Assert.False(resultList.Any()); }
public async void Delete_EntryMatchedFilterDeleted() { // Arrange var filterText = "Text"; var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var testAccount = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry1 = new PaymentEntity { ChargedAccount = testAccount, Note = filterText }; var testEntry2 = new PaymentEntity { ChargedAccount = testAccount }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry1); paymentRepository.Add(testEntry2); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Delete(x => x.Note == filterText); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(1, paymentRepository.GetAll().Count()); } }
public async void DeleteAccount_RelatedTargetPaymentSetNull() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var accountRepository = new AccountRepository(factory); var paymentRepository = new PaymentRepository(factory); var chargedAccount = new AccountEntity { Name = "Charged" }; var targetAccount = new AccountEntity { Name = "Target" }; var payment = new PaymentEntity { Note = "Foo", ChargedAccount = chargedAccount, TargetAccount = targetAccount }; accountRepository.Add(chargedAccount); accountRepository.Add(targetAccount); paymentRepository.Add(payment); await unitOfWork.Commit(); Assert.Equal(2, await accountRepository.GetAll().CountAsync()); Assert.Equal(1, await paymentRepository.GetAll().CountAsync()); // Act accountRepository.Delete(targetAccount); await unitOfWork.Commit(); // Assert Assert.Null(payment.TargetAccount); Assert.NotNull(payment.ChargedAccount); }
public async void Add_AddNewEntryOnEveryCall() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var account = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentEntity { ChargedAccount = account, Note = "Testtext" }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { testEntry.Id = 0; paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(2, paymentRepository.GetAll().Count()); } }
public async void Delete_EntryDeleted() { // Arrange var unitOfWork = new UnitOfWork(dbFactory); var repository = new PaymentRepository(dbFactory); var testEntry = new PaymentEntity { 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 GetAll_AllDataReturned() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var testAccount = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } List <PaymentEntity> resultList; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); paymentRepository.Add(new PaymentEntity { ChargedAccount = testAccount }); await dbContextScope.SaveChangesAsync(); resultList = paymentRepository.GetAll().ToList(); } // Assert Assert.NotNull(resultList); Assert.Equal(3, resultList.Count); }
public async void Delete_EntryDeleted() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); var testAccount = new AccountEntity { Name = "testAccount" }; using (var dbContextScope = dbContextScopeFactory.Create()) { accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentEntity { ChargedAccount = testAccount }; // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(testEntry); await dbContextScope.SaveChangesAsync(); } using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Delete(testEntry); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(0, paymentRepository.GetAll().Count()); } }
public async void Add_AddMultipleEntries() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity account; using (var dbContextScope = dbContextScopeFactory.Create()) { account = new AccountEntity { Name = "testAccount" }; accountRepository.Add(account); await dbContextScope.SaveChangesAsync(); } // Act using (var dbContextScope = dbContextScopeFactory.Create()) { paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); paymentRepository.Add(new PaymentEntity { ChargedAccount = account }); await dbContextScope.SaveChangesAsync(); } // Assert using (dbContextScopeFactory.CreateReadOnly()) { Assert.Equal(3, paymentRepository.GetAll().Count()); } }
public HttpResponseMessage UpatePaymentStatus(object Paymentobj1) { JavaScriptSerializer js = new JavaScriptSerializer(); var json = Paymentobj1; Payment Payment = js.Deserialize <Payment>(json.ToString()); Payment paymentobj = PaymentRepository.GetAll(t => t.Invoice == Payment.Invoice).FirstOrDefault(); paymentobj.TransactionId = Payment.TransactionId; paymentobj.Status = Payment.Status; paymentobj.Response = Payment.Response; if (ModelState.IsValid) { PaymentRepository.Attach(Payment); unitOfWork.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, Payment); response.Content = new StringContent(Payment.PaymentId.ToString()); return(response); } else { var errors = ModelState.Values.SelectMany(v => v.Errors); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public P.Payments GetAll() { return(PaymentRepository.GetAll()); }
public List <Payment> GetAll() { var payments = _paymentRepository.GetAll().OrderByDescending(c => c.Id).Take(100).ToList(); return(payments); }
public IEnumerable <Payment> GetPaymentsbyUserId(int id) { return(PaymentRepository.GetAll(t => t.UserId == id)); }
public List <Payment> GetAllPayment() { return(pRepo.GetAll()); }
public IHttpActionResult GetPaymentMethods() { return(Ok(paymentRepository.GetAll())); }
public List <Payment> Get() { return(_repository.GetAll()); }