public void Index_WhenCalled_ShouldReturnTopicsInViewModel() { _context.AddTestTopicToDatabase(); var result = _controller.Index(); Assert.That((result.Model as TopicIndexViewModel).Topics.Count(), Is.EqualTo(1)); }
public async Task GivenNavigateToTopicReturnsTopicWithExpectedProperties() { var subItems = Enumerable.Range(0, 1).Select(CreateASubItem).ToList(); var topic = new Topic("Name", "slug", "Summary", "Teaser", "metaDescription", "Icon", "Image", "Image", subItems, null, null, new List <Crumb>(), new List <Alert>(), true, "test-id", _eventBanner, "expandingLinkText", new List <ExpandingLinkBox> { new ExpandingLinkBox("title", subItems) }, string.Empty, string.Empty, true); const string slug = "healthy-living"; _repository.Setup(o => o.Get <Topic>(slug, null)).ReturnsAsync(new HttpResponse(200, topic, string.Empty)); var indexPage = await _controller.Index(slug) as ViewResult; var viewModel = indexPage.ViewData.Model as TopicViewModel; var result = viewModel.Topic; Assert.Equal("Name", result.Name); Assert.Equal("slug", result.Slug); Assert.Equal("<p>Summary</p>\n", result.Summary); Assert.Equal("Teaser", result.Teaser); Assert.Equal("Icon", result.Icon); Assert.Equal("Image", result.BackgroundImage); Assert.Equal("Image", result.Image); Assert.True(result.DisplayContactUs); result.EmailAlerts.Should().Be(true); result.EmailAlertsTopicId.Should().Be("test-id"); result.EventBanner.Title.Should().Be(_eventBanner.Title); result.EventBanner.Teaser.Should().Be(_eventBanner.Teaser); result.MetaDescription.Should().Be("metaDescription"); result.EventBanner.Icon.Should().Be(_eventBanner.Icon); result.EventBanner.Link.Should().Be(_eventBanner.Link); result.ExpandingLinkTitle.Should().Be("expandingLinkText"); result.ExpandingLinkBoxes.First().Title.Should().Be("title"); result.ExpandingLinkBoxes.First().Links[0].Type.Should().Be("topic"); }
public void Return_Model_Index_Method() { //Arrange var testValue = new TopicViewModel() { Id = 1 }; var service = Substitute.For <ITopicService>(); service.GetTopic(1).Returns(testValue); TopicController controller = new TopicController(service); //Act var expected = controller.Index(1) as ViewResult; //Assert Assert.Equal(expected.Model, testValue); Assert.NotNull(expected); }
public void IndexShouldReturnViewWithTopics() { //Arrange var model = new List <TopicEntity>(); var logic = new Mock <ITopicLogic>(); logic .Setup(x => x.GetAll()) .Returns(model) .Verifiable("should get topics to display"); var controller = new TopicController(logic.Object, null, null, null); //ACT var result = controller.Index() as ViewResult; //ASSERT logic.Verify(); Assert.NotNull(result); Assert.That(result.ViewName, Is.EqualTo("Index")); Assert.That(result.Model, Is.EqualTo(model)); }
public void Index_WhenCalled_ReturnViewResult() { var result = _controller.Index(); Assert.That(result, Is.TypeOf <ViewResult>()); }