public void Update_ModelIsValid_ReturnsOK() { //Arrange _topicService.Setup(s => s.UpdateEntity(_topic)); //Act var actionResult = _topicController.Update(_topic).Result as OkResult; //Assert actionResult.StatusCode.Should().Be(200); }
public void UpdateShouldSaveTheTopic() { //ARRANGE var id = Guid.NewGuid(); var model = new TopicEntity { Id = id, Description = "Topic one" }; var logic = new Mock <ITopicLogic>(); logic .Setup(x => x.Get(id)) .Returns(new TopicEntity()) .Verifiable("Should get the topic to edit."); logic .Setup(x => x.Update(It.IsAny <TopicEntity>())) .Verifiable("should save topic"); var controller = new TopicController(logic.Object, null, null, null); //ACT var result = controller.Update(model) as RedirectToRouteResult; //ASSERT logic.Verify(); Assert.NotNull(result); Assert.AreEqual("Index", result.RouteValues["Action"]); }
public void UpdateShouldDisplayTheCorrectView() { //ARRANGE var id = Guid.NewGuid(); var logic = new Mock <ITopicLogic>(); logic .Setup(x => x.Get(id)) .Returns(new TopicEntity()) .Verifiable("Should get the topic to edit."); var controller = new TopicController(logic.Object, null, null, null); //ACT var result = controller.Update(id) as ViewResult; //ASSERT logic.Verify(); Assert.NotNull(result); Assert.NotNull(result.Model); Assert.That(result.ViewName, Is.EqualTo("Update")); }