Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
            }
        }