public async Task TestGetCustomerByIdAsync() { // Arrange var dbContext = CustomerDbContextMocker.GetCustomerDBContext(nameof(TestGetCustomerByIdAsync)); var controller = new CustomerController(dbContext); var id = RandomNumber(int.MaxValue); var request = new Customer { Id = id, FirstName = "Shuman", LastName = "Castellino", DateOfBirth = System.DateTime.Now.AddYears(-20).Date }; //Act var postResponse = await controller.PostCustomer(request); var response = await controller.GetCustomer(id); dbContext.Dispose(); // Assert Assert.NotNull(response.Value); //var actionResult = Assert.IsType<ActionResult<Customer>>(response.Value); //Assert.IsType<NotFoundObjectResult>(actionResult.Result); }
public void TestGetCustomers() { // Arrange var dbContext = CustomerDbContextMocker.GetCustomerDBContext(nameof(TestGetCustomers)); var controller = new CustomerController(dbContext); // Act var response = controller.GetCustomerListAsync(new CustomerFilterModel()); dbContext.Dispose(); // Assert Assert.NotNull(response.Result); }
public void TestGetCustomersFilterFirstAndLastName() { // Arrange var dbContext = CustomerDbContextMocker.GetCustomerDBContext(nameof(TestGetCustomersFilterFirstAndLastName)); var controller = new CustomerController(dbContext); var filter = new CustomerFilterModel { FirstName = "Jo", LastName = "it" }; // Act var response = controller.GetCustomerListAsync(filter); dbContext.Dispose(); // Assert Assert.NotNull(response.Result); }
public async Task TestPostCustomerAsync() { // Arrange var dbContext = CustomerDbContextMocker.GetCustomerDBContext(nameof(TestPostCustomerAsync)); var controller = new CustomerController(dbContext); var id = RandomNumber(int.MaxValue); var request = new Customer { Id = id, FirstName = "Shuman", LastName = "Paul", DateOfBirth = System.DateTime.Now.AddYears(-20).Date }; //Act var response = await controller.PostCustomer(request); dbContext.Dispose(); // Assert Assert.IsType <CreatedAtActionResult>(response.Result); }