public void Should_ReturnSpecifiedPersonWithRelatedMailSortedByDate_WhenRequested() { // arrange var person = Builder<Person>. CreateNew(). With(x => x.Id = 7777). With(x => x.RelatedMails = Builder<MailMessage>. CreateListOfSize(10). All(). With(d => d.Date = new RandomGenerator().DateTime()). Build()). Build(); var repository = Substitute.For<IRepository>(); repository.Get<Person>(7777).Returns(person); var clientController = new ClientsController(repository); // act var viewResult = clientController.MailingHistory(7777).Model as Person; // assert for (int i = 1; i < viewResult.RelatedMails.Count; i++) Assert.That(viewResult.RelatedMails[i].Date >= viewResult.RelatedMails[i - 1].Date); }
public void Should_ReturnMailingHistoryOfSpecifiedPerson_WhenRequested() { // arrange var person = Builder<Person>.CreateNew() .With(x => x.Id = 7777).Build(); var mails = Builder<MailMessage>.CreateListOfSize(25) .All().With(x => x.Date = GetRandom.DateTime()) .With(x => x.Sender = Builder<Person>.CreateNew().Build()) .With(x => x.Receivers = Builder<Person>.CreateListOfSize(3).Build()) .TheFirst(7).With(x => x.Sender = person) .TheLast(7).With(x => x.Receivers = new List<Person> {person}) .Build(); var repository = Substitute.For<IRepository>(); repository.Query<MailMessage>().ReturnsForAnyArgs(mails.AsQueryable()); var clientController = new ClientsController(repository); // act var viewResult = (IList<MailMessage>)clientController.MailingHistory(7777).Model; // assert viewResult.Count().Should().Be(14); for (int i = 1; i < viewResult.Count; i++) viewResult[i].Date.Should().BeOnOrAfter(viewResult[i - 1].Date); }