Пример #1
0
        public void AddNewSkillTest()
        {
            //testing successfull run
            mockSkillService.Setup(service => service.AddSkill(It.IsAny <Skill>())).Returns(true);
            var controller = new SkillsController(mockSkillService.Object);

            controller.ControllerContext = this.controllerContext;
            var result     = controller.AddNewSkill(new Skill());
            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(viewResult.ControllerName);
            Assert.Equal("Index", viewResult.ActionName);
            mockSkillService.Reset();


            //testing exception
            mockSkillService.Setup(service => service.AddSkill(It.IsAny <Skill>())).Returns(false);
            controller = new SkillsController(mockSkillService.Object);
            controller.ControllerContext = this.controllerContext;
            var ex = Assert.Throws <Exception>(() => controller.AddNewSkill(new Skill()));

            Assert.Equal("Could not add skill.", ex.Message);
            mockSkillService.Reset();
        }