Beispiel #1
0
        public void AddNewSkillTest()
        {
            _skillRepository.Setup(repo => repo.Insert(It.IsAny <Skill>())).Returns((EntityEntry <Skill>)FormatterServices.GetUninitializedObject(typeof(EntityEntry <Skill>)));
            _skillRepository.Setup(repo => repo.Save()).Returns(1);

            var projectService = new ProjectsService(_projectRepository.Object, _interestedInProjectRepository.Object, _applicationUserRepository.Object, _userSkillRepository.Object, _skillRepository.Object);
            var skillsService  = new SkillsService(_skillRepository.Object, _projectSkillRepository.Object, _userSkillRepository.Object);

            var postsController = new PostsController(projectService, skillsService);

            postsController.ControllerContext = this.controllerContext;

            var result     = postsController.AddNewSkill(new Skill());
            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(viewResult.ControllerName);
            Assert.Equal("Post", viewResult.ActionName);
            _skillRepository.Reset();

            _skillRepository.Setup(repo => repo.Insert(It.IsAny <Skill>())).Returns((EntityEntry <Skill>)FormatterServices.GetUninitializedObject(typeof(EntityEntry <Skill>)));
            _skillRepository.Setup(repo => repo.Save()).Returns(0);

            projectService = new ProjectsService(_projectRepository.Object, _interestedInProjectRepository.Object, _applicationUserRepository.Object, _userSkillRepository.Object, _skillRepository.Object);
            skillsService  = new SkillsService(_skillRepository.Object, _projectSkillRepository.Object, _userSkillRepository.Object);

            postsController = new PostsController(projectService, skillsService);
            postsController.ControllerContext = this.controllerContext;

            Assert.Throws <Exception>(() => postsController.AddNewSkill(new Skill()));
            _skillRepository.Reset();
        }
Beispiel #2
0
        public void AddNewSkillTest()
        {
            mockSkillService.Setup(service => service.AddSkill(It.IsAny <Skill>())).Returns(true);
            var controller = new PostsController(mockProjectService.Object, mockSkillService.Object);
            var result     = controller.AddNewSkill(new Skill());
            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(viewResult.ControllerName);
            Assert.Equal("Post", viewResult.ActionName);

            mockSkillService.Reset();
            mockProjectService.Reset();

            mockSkillService.Setup(service => service.AddSkill(It.IsAny <Skill>())).Returns(false);
            controller = new PostsController(mockProjectService.Object, mockSkillService.Object);
            var ex = Assert.Throws <Exception>(() => controller.AddNewSkill(new Skill()));

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

            mockSkillService.Reset();
            mockProjectService.Reset();
        }