public ActionResult PostCustomer([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _cutomerRepository.InsertCustomer(customer); _cutomerRepository.Save(); return(CreatedAtAction("GetCustomer", new { id = customer.Id }, customer)); }
public void Should_Display_Customer_List_Count_As_Two() { optionsBuilder.UseInMemoryDatabase("MySuperTestDb"); // Run the test against one instance of the context using (var context = new MySuperContext(optionsBuilder.Options)) { var customerRepository = new CutomerRepository(context); var customer1 = new Customer { FirstName = "Isuru" }; var customer2 = new Customer { FirstName = "Mahesh" }; customerRepository.InsertCustomer(customer1); customerRepository.InsertCustomer(customer2); var count = context.Customers.Count(); Assert.Equal(2, count); } }
public void Should_Add_New_Customer() { optionsBuilder.UseInMemoryDatabase("MySuperTestDb"); // Run the test against one instance of the context using (var context = new MySuperContext(optionsBuilder.Options)) { var customerRepository = new CutomerRepository(context); var customer = new Customer { FirstName = "Isuru" }; customerRepository.InsertCustomer(customer); Assert.True(customer.Id > 0); } }