コード例 #1
0
        public async Task Get_customer_by_id_not_found_result()
        {
            var context = new CustomerContext(_dbFixture.DbOptions);

            var customerController = new CustomersController(context);
            var actionResult       = await customerController.GetCustomerByIdAsync(int.MaxValue);

            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
コード例 #2
0
        public async Task Get_customer_by_id_success()
        {
            var expectedFirstName = "David";
            var expectedLastName  = "Robinson";

            var context = new CustomerContext(_dbFixture.DbOptions);

            var customerController = new CustomersController(context);
            var actionResult       = await customerController.GetCustomerByIdAsync(2);

            Assert.Equal(expectedFirstName, actionResult.Value.FirstName);
            Assert.Equal(expectedLastName, actionResult.Value.LastName);
        }
コード例 #3
0
        public async Task Delete_customer_success()
        {
            var newCustomer        = GetTestCustomer();
            var context            = new CustomerContext(_dbFixture.DbOptions);
            var customerController = new CustomersController(context);
            var createResult       = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(createResult.RouteValues["id"].ToString());

            var deleteResult = await customerController.DeleteCustomerByIdAsync(id);

            var actionResult = await customerController.GetCustomerByIdAsync(id);

            Assert.Null(actionResult.Value);
        }
コード例 #4
0
        public async Task Update_customer_success()
        {
            var newCustomer        = GetTestCustomer();
            var context            = new CustomerContext(_dbFixture.DbOptions);
            var customerController = new CustomersController(context);
            var createResult       = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(createResult.RouteValues["id"].ToString());

            newCustomer.LastName = "Persons";
            var updateResult = await customerController.UpdateCustomerAsync(id, newCustomer);

            var actionResult = await customerController.GetCustomerByIdAsync(id);

            Assert.Equal(newCustomer.LastName, actionResult.Value.LastName);
        }
コード例 #5
0
        public async Task Create_customer_success()
        {
            var newCustomer = GetTestCustomer();

            var context = new CustomerContext(_dbFixture.DbOptions);

            var customerController = new CustomersController(context);

            var actionResult = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(actionResult.RouteValues["id"].ToString());

            var customer = await customerController.GetCustomerByIdAsync(id);

            Assert.Equal(newCustomer.FirstName, customer.Value.FirstName);
            Assert.Equal(newCustomer.LastName, customer.Value.LastName);
            Assert.Equal(newCustomer.DateOfBirth, customer.Value.DateOfBirth);
        }
コード例 #6
0
        public async Task GetByIdAsync_GetCustomerPreviewQuery_Has_Correct_Data()
        {
            // Arrange
            var mockMediator        = new Mock <IMediator>();
            var mockMapper          = new Mock <IMapper>();
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut        = new CustomersController(mockMediator.Object, mockMapper.Object, mockResponseFactory.Object, mockApiSettings.Object);
            var customerId = 1;

            // Act
            await sut.GetCustomerByIdAsync(customerId, default(CancellationToken));

            // Assert
            mockMediator.Verify(x => x.Send(It.Is <GetCustomerPreviewQuery>(d => d.Id == customerId), It.IsAny <CancellationToken>()));
        }
コード例 #7
0
        public async Task GetByIdAsync_Returns_OK_200_Result()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.Send(It.IsAny <GetCustomerPreviewQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(Customer);
            var mapper = Mapper;
            var mockResponseFactory = new Mock <IResponseFactory>();
            var mockApiSettings     = new Mock <IOptionsSnapshot <ApiSettings> >();

            mockApiSettings.SetupGet(x => x.Value).Returns(ApiSettings);
            var sut        = new CustomersController(mockMediator.Object, mapper, mockResponseFactory.Object, mockApiSettings.Object);
            var customerId = 1;

            // Act
            var result = await sut.GetCustomerByIdAsync(customerId, default(CancellationToken));

            // Assert
            var response = result.Should().BeOfType <OkObjectResult>().Subject;

            response.StatusCode.Should().Equals(200);
        }