public async Task When_ModelStateIsNotValid_Then_ReturnBadRequest() { var companyService = new Mock <ICompanyService>(MockBehavior.Strict); var companyExample = new Company() { Name = "Firma", Address = "Firmowa 10" }; WC.CompanyController companyController = new WC.CompanyController(companyService.Object); companyController.ModelState.AddModelError("company", "Model not valid"); var result = await companyController.SetCompany(companyExample); Assert.That(result, Is.TypeOf <BadRequestResult>()); companyService.VerifyAll(); }
public async Task When_ModelStateIsValid_Then_ReturnCreatedObject() { var companyService = new Mock <ICompanyService>(MockBehavior.Strict); var companyExample = new Company() { Name = "Firma", Address = "Firmowa 10" }; companyService.Setup(p => p.AddCompany(companyExample)).Returns(Task.FromResult <Company>(companyExample)); WC.CompanyController companyController = new WC.CompanyController(companyService.Object); var result = await companyController.SetCompany(companyExample); Assert.That(result, Is.TypeOf <OkObjectResult>()); Assert.AreEqual((((result as OkObjectResult)?.Value as Company)?.Name ?? "Firma"), companyExample.Name); companyService.VerifyAll(); }
public void When_RunWithoutService_Then_GetNullReferenceException() { var controller = new WC.CompanyController(null); Assert.That(() => controller.GetCompanies(), Throws.TypeOf <NullReferenceException>()); }