コード例 #1
0
        public void Controller_Customer_Get_Null()
        {
            var logger = new BlitzkriegSoftware.MsTest.MsTestLogger <Controllers.CustomerController>(TestControllers.Context);
            var ctlr   = new Controllers.CustomerController(logger);

            _ = ctlr.Get(null);
        }
コード例 #2
0
        public void ShouldReturnOkObjectResultForMultipleCustomers()
        {
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Get().Result;

            Assert.IsType <OkObjectResult>(result);
        }
コード例 #3
0
        public async Task ShouldCallCustomerServiceToGetAllCustomers()
        {
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            await sut.Get();

            _mockCustomerService.Verify(s => s.GetAll(), Times.Once);
        }
コード例 #4
0
        public async Task ShouldCallCustomerServiceToGetCustomerById()
        {
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            await sut.Get(It.IsAny <string>());

            _mockCustomerService.Verify(s => s.GetById(It.IsAny <string>()), Times.Once);
        }
コード例 #5
0
        public void Controller_Customer_Get_NotFound()
        {
            var logger = new BlitzkriegSoftware.MsTest.MsTestLogger <Controllers.CustomerController>(TestControllers.Context);
            var ctlr   = new Controllers.CustomerController(logger);
            var id     = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";

            _ = ctlr.Get(id);
        }
コード例 #6
0
        public Models.Customer RandomCustomer()
        {
            var id     = this.RandomId();
            var logger = new BlitzkriegSoftware.MsTest.MsTestLogger <Controllers.CustomerController>(TestControllers.Context);
            var ctlr   = new Controllers.CustomerController(logger);
            var entity = ctlr.Get(id);

            return(entity);
        }
        public void ShouldReturnNotFoundIfNoCustomerFound()
        {
            const string nonExistingCustomerId = "123";
            var          sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Get(nonExistingCustomerId).Result;

            Assert.Equal(nonExistingCustomerId, ((NotFoundObjectResult)result).Value);
            Assert.IsType <NotFoundObjectResult>(result);
        }
        public void ShouldReturnBadRequestIfModelStateIsInvalid()
        {
            _mockCustomerService.Setup(s => s.GetById(It.IsAny <string>()));
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

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

            var result = sut.Get(It.IsAny <string>()).Result;

            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #9
0
        public void ShouldReturnOkObjectResultForSingleCustomer()
        {
            var dummyCustomerId = It.IsAny <string>();

            _mockCustomerService.Setup(s => s.GetById(dummyCustomerId))
            .ReturnsAsync(new Models.Customer(string.Empty, string.Empty, string.Empty, string.Empty));
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Get(dummyCustomerId).Result;

            Assert.IsType <OkObjectResult>(result);
        }
        public void ShouldReturnInternalServerErrorIfExceptionThrownForMultipleCustomers()
        {
            _mockCustomerService.Setup(s => s.GetAll()).ThrowsAsync(new Exception());
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

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

            Assert.IsType <ObjectResult>(result);
            Assert.IsType <Exception>(((ObjectResult)result).Value);
            Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode);
        }
コード例 #11
0
        public void ShouldReturnTheSameCustomer()
        {
            var          customerId     = It.IsAny <string>();
            const string validEmail     = "*****@*****.**";
            const string validFirstName = "John";
            const string validSurname   = "Surname";
            const string validPassword  = "******";
            var          validCustomer  = new Models.Customer(validEmail, validFirstName, validSurname, validPassword);

            _mockCustomerService.Setup(s => s.GetById(customerId)).ReturnsAsync(validCustomer);
            var sut = new Controllers.CustomerController(_mockCustomerService.Object);

            var result = sut.Get(customerId).Result;

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

            Assert.Equal(validEmail, customer.Email);
        }