public All ( ) : System.Web.Mvc.ViewResult | ||
Результат | System.Web.Mvc.ViewResult |
public void Should_ReturnFullListOfInquiriesSortedByTag_WhenCalledAllFunction() { // arrange var repository = Substitute.For<IRepository>(); repository.Query<Inquiry>().ReturnsForAnyArgs(inquiries.AsQueryable()); repository.Query<Tag>().ReturnsForAnyArgs(tags.AsQueryable()); var inquiriesController = new InquiriesController(repository).MockHttpContext(); // act var viewResult = (AllInquiriesViewModel) inquiriesController.All().Model; var categories = viewResult.Categories.ToList(); // assert categories.Count.Should().Be(2); categories[1].Tag.Name.Should().Be(""); categories[1].Inquiries.Count().Should().Be(20); categories[0].Tag.Name.Should().Be("tag2"); categories[0].Inquiries.Count().Should().Be(10); }
public void Should_ReturnSingleInquiryInEveryCategory_WhenSeveralTagsAreAssignedAndAllViewIsRequested() { // arrange var tags = Builder<Tag>.CreateListOfSize(2).Build(); var inquiries = Builder<Inquiry>.CreateListOfSize(10) .All() .With(x => x.Client = Builder<Person>.CreateNew().Build()) .With(x => x.ReferenceDate = July.The14th) .With(x => x.Tags = tags.Take(1).ToList()) .TheLast(3) .With(x => x.Tags = tags) .Build(); tags.ForEach(x => x.Inquiries = inquiries.Where(z => z.Tags.Any(y => y.Name == x.Name)).ToList()); var repository = Substitute.For<IRepository>(); repository.Query<Tag>().ReturnsForAnyArgs(tags.AsQueryable()); repository.Query<Inquiry>().ReturnsForAnyArgs(inquiries.AsQueryable()); var inquiriesController = new InquiriesController(repository).MockHttpContext(); // act var viewResult = (AllInquiriesViewModel) inquiriesController.All().Model; var categories = viewResult.Categories.ToList(); // assert categories.Count.Should().Be(2); categories[0].Tag.Name.Should().Be("Name1"); categories[0].Inquiries.Count().Should().Be(10); categories[1].Tag.Name.Should().Be("Name2"); categories[1].Inquiries.Count().Should().Be(3); categories[0].Inquiries.Should().Contain(x => x.Id == 9); categories[1].Inquiries.Should().Contain(x => x.Id == 9); categories[0].Inquiries.Should().Contain(x => x.Id == 1); categories[1].Inquiries.Should().NotContain(x => x.Id == 1); }
public void ShouldNot_ReturnCategoriesWithEmptyInquiries_WhenAllRequested() { // arrange var mock = new Mock<IRepository>(); mock.Setup(z => z.Query<Inquiry>(x => x.Client, x => x.Tags)).Returns(new List<Inquiry>().AsQueryable()); mock.Setup(z => z.Query<Tag>(x => x.Inquiries)).Returns(new List<Tag> { new Tag { Inquiries = new List<Inquiry>(), Name = "", Id = 1 } }.AsQueryable()); var inquiriesController = new InquiriesController(mock.Object).MockHttpContext(); //act var viewResult = (AllInquiriesViewModel) inquiriesController.All().Model; //assert viewResult.Categories.Count().Should().Be(0); }