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