示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        public void When_RunWithoutService_Then_GetNullReferenceException()
        {
            var controller = new WC.CompanyController(null);

            Assert.That(() => controller.GetCompanies(), Throws.TypeOf <NullReferenceException>());
        }