public void Add_New_Topic_Route_Test() { Mock <ITopicRepository> topicRepo = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> interRepo = new Mock <IIntermediateCategoryRepository>(); var controllerContext = new Mock <ControllerContext>(); var principal = new Moq.Mock <IPrincipal>(); principal.Setup(p => p.IsInRole("Administrator")).Returns(true); principal.SetupGet(x => x.Identity.Name).Returns("koral2323"); principal.Setup(c => c.Identity.IsAuthenticated).Returns(true); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); TopicController controller = new TopicController(topicRepo.Object, interRepo.Object); controller.ControllerContext = controllerContext.Object; Topic topic = new Topic(); topic.IntermediateCategoryId = 3; RedirectToRouteResult result = controller.Add_New_Topic(topic) as RedirectToRouteResult; Assert.AreEqual(result.RouteValues["action"], "Show_Topics"); Assert.AreEqual(result.RouteValues["controller"], "Topic"); Assert.AreEqual(result.RouteValues["id"], 3); }
public void Add_New_Topic_Test() { Mock <ITopicRepository> topicRepo = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> interRepo = new Mock <IIntermediateCategoryRepository>(); TopicController controller = new TopicController(topicRepo.Object, interRepo.Object, () => "koral2323"); int id = 5; int result = controller.Add_New_Topic(id).ViewBag.InterId; Assert.AreEqual(id, result); Assert.AreNotEqual(1, result); }
public void Add_New_Topic_Dont_Save_Changes_Return_View_Add_New_Topic() { Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>(); TopicController controller = new TopicController(repositoryTopic.Object, repositoryInter.Object, () => "ewa2323"); Topic topic = new Topic() { TopicName = null, TopicData = null }; controller.ModelState.AddModelError("TopicName", "Pole nie może pozostawać puste"); controller.ModelState.AddModelError("TopicData", "Pole nie może pozostawać puste"); ViewResult result = (ViewResult)controller.Add_New_Topic(topic); Assert.AreEqual("Add_New_Topic", result.ViewName); }
public void Add_New_Topic_Dont_Save_InValid_Changes() { Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>(); TopicController controller = new TopicController(repositoryTopic.Object, repositoryInter.Object, () => "ewa2323"); Topic topic = new Topic() { TopicName = null, TopicData = null }; controller.ModelState.AddModelError("TopicName", "Pole nie może pozostawać puste"); controller.ModelState.AddModelError("TopicData", "Pole nie może pozostawać puste"); ActionResult result = controller.Add_New_Topic(topic); repositoryTopic.Verify(x => x.Add_To_Topics_And_User(It.IsAny <Topic>(), It.IsAny <string>()), Times.Never); }