public async Task DetailsTest() { var skillId = 2; var mockRepo = new Mock <ISkillRepository>(); mockRepo.Setup(repo => repo.GetSkill(skillId)).ReturnsAsync(TestData.Skills().FirstOrDefault(s => s.Id == skillId)); var mockServ = new Mock <ISkillService>(); var controller = new SkillsController(mockServ.Object, mockRepo.Object); // Act var result = await controller.Details(skillId); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); var viewResult = result as ViewResult; var model = viewResult.ViewData.Model; Assert.IsNotNull(model); var skill = model as Skill; Assert.IsNotNull(skill); var testSkill = TestData.Skills().FirstOrDefault(s => s.Id == skillId); Assert.AreEqual(testSkill.Id, skill.Id); Assert.AreEqual(testSkill.Name, skill.Name); Assert.AreEqual(testSkill.XpCost, skill.XpCost); Assert.AreEqual(testSkill.SkillRef, skill.SkillRef); }
public void TestDetailsPageWithParams() { // Arrange SkillsController controller = new SkillsController(); // Act ViewResult result = controller.Details(2) as ViewResult; // Assert Assert.AreEqual(2, ((CandidateSkill)result.Model).CandidateId); }