Ejemplo n.º 1
0
        public void ShouldReturnCreatedResult()
        {
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Post(_validCustomer).Result;

            Assert.IsType <CreatedResult>(result);
        }
Ejemplo n.º 2
0
        public void ShouldCallCustomerServiceToAddCustomer()
        {
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            sut.Post(_validCustomer).Wait();

            _mockCustomerService.Verify(s => s.Add(_validCustomer), Times.Once);
        }
Ejemplo n.º 3
0
        public void ShouldReturnBadRequestIfModelStateIsInvalid()
        {
            _mockCustomerService.Setup(s => s.Add(_validCustomer));
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            sut.ModelState.AddModelError(string.Empty, string.Empty);

            var result = sut.Post(_validCustomer).Result;

            Assert.IsType <BadRequestObjectResult>(result);
        }
Ejemplo n.º 4
0
        public void ShouldReturnCustomerWithTheSameEmailPassedIntoIt()
        {
            _mockCustomerService.Setup(s => s.Add(_validCustomer)).ReturnsAsync(_validCustomer);
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Post(_validCustomer).Result;

            var customer = (Models.Customer)((CreatedResult)result).Value;

            Assert.Equal(ValidEmail, customer.Email);
        }
Ejemplo n.º 5
0
        public void ShouldReturnServerErrorIfExceptionThrown()
        {
            _mockCustomerService.Setup(s => s.Add(_validCustomer)).ThrowsAsync(new Exception());
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result     = sut.Post(_validCustomer).Result;
            var statusCode = ((ObjectResult)result).StatusCode;

            Assert.IsType <ObjectResult>(result);
            Assert.IsType <Exception>(((ObjectResult)result).Value);
            Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode);
        }