public async Task Can_Update_Customer() { //Arrange var testCustomer = new Customer() { Name = "First Customer" }; using (var context = new AppDbContext(_contextOptions)) { //Act var repository = new EfCoreRepository <Customer>(context); var insertedCustomerId = await repository.InsertAsync(testCustomer); var insertedCustomer = await repository.GetByIdAsync(insertedCustomerId); insertedCustomer.Name = "First Updated Customer"; await repository.UpdateAsync(insertedCustomer); //Assert var updatedCustomer = await repository.GetByIdAsync(insertedCustomerId); Assert.Equal(insertedCustomer.Name, updatedCustomer.Name); } }
public async Task Can_Update_Order() { //Arrange var testCustomer = new Customer() { Name = "Test Customer to Order" }; var testBook = new Book() { Name = "Test Book to Order", Price = 15.50M, }; using (var context = new AppDbContext(_contextOptions)) { var customerRepository = new EfCoreRepository <Customer>(context); await customerRepository.InsertAsync(testCustomer); var bookRepository = new EfCoreRepository <Book>(context); await bookRepository.InsertAsync(testBook); } var testOrder = new Order() { CustomerId = testCustomer.Id, OrderNote = "Test Order", OrderProducts = new List <OrderProduct>() { new OrderProduct() { BookId = testBook.Id, TotalPrice = testBook.Price * 5 } } }; testOrder.OrderTotal = testOrder.OrderProducts.Sum(op => op.TotalPrice); using (var context = new AppDbContext(_contextOptions)) { //Act var repository = new EfCoreRepository <Order>(context); var insertedOrderId = await repository.InsertAsync(testOrder); var insertedOrder = await repository.GetByIdAsync(insertedOrderId); insertedOrder.OrderNote = "Test Updated Order"; await repository.UpdateAsync(insertedOrder); //Assert var updatedOrder = await repository.GetByIdAsync(insertedOrderId); Assert.Equal(insertedOrder.OrderNote, updatedOrder.OrderNote); } }
public async Task Can_Add_Customer() { //Arrange var testCustomer = new Customer() { Name = "First Customer" }; using (var context = new AppDbContext(_contextOptions)) { //Act var repository = new EfCoreRepository <Customer>(context); await repository.InsertAsync(testCustomer); //Assert var customer = await repository.GetByIdAsync(testCustomer.Id); Assert.Equal(testCustomer.Id, customer.Id); Assert.Equal(testCustomer.Name, customer.Name); } }
public async Task Can_Delete_Customer() { //Arrange var testCustomer = new Customer() { Name = "İlk Bölüm" }; using (var context = new AppDbContext(_contextOptions)) { //Act var repository = new EfCoreRepository <Customer>(context); await repository.InsertAsync(testCustomer); await repository.DeleteAsync(testCustomer); //Assert var deletedCustomer = await repository.GetByIdAsync(testCustomer.Id); Assert.Null(deletedCustomer); } }