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); }
public void ShouldReturnOkObjectResultForMultipleCustomers() { var sut = new Controllers.CustomerController(_mockCustomerService.Object); var result = sut.Get().Result; Assert.IsType <OkObjectResult>(result); }
public async Task ShouldCallCustomerServiceToGetAllCustomers() { var sut = new Controllers.CustomerController(_mockCustomerService.Object); await sut.Get(); _mockCustomerService.Verify(s => s.GetAll(), Times.Once); }
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); }
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); }
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); }
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); }
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); }