Exemple #1
0
        public async Task <ActionResult <Customer> > GetCustomerAsync(long id)
        {
            var result = await context.FindAsync <Customer>(id);

            if (result == null)
            {
                return(NotFound());
            }
            return(new JsonResult(result));
        }
Exemple #2
0
        public async Task TestCreateCustomer()
        {
            using var context = new CustomersDbContext(dbContextOptions);
            var newCustomerDTO = new CustomerInput {
                Name = "Petya", Surname = "Ivanov", Email = "*****@*****.**"
            };
            var newCustomer = new Customer(newCustomerDTO)
            {
                Id = 3
            };

            var result = (await customersController.CreateCustomerAsync(newCustomerDTO)).Result as CreatedAtActionResult;

            Assert.That(result.ActionName, Is.EqualTo("GetCustomer"));
            Assert.That(result.RouteValues["id"], Is.EqualTo(3));
            Assert.That(result.Value, Is.EqualTo(newCustomer));
            var addedCustomer = await context.FindAsync <Customer>((long)3);

            Assert.That(addedCustomer, Is.EqualTo(newCustomer));
        }