コード例 #1
0
        public void AllByJournal_ShouldReturnValidPublications()
        {
            // Arrange
            StarStuffDbContext db = this.Database;
            PublicationService publicationService = new PublicationService(db);

            const int page      = 2;
            const int pageSize  = 5;
            const int journalId = 1;

            Journal journal = new Journal
            {
                Id           = journalId,
                Publications = GetFakePublications()
                               .OrderBy(p => p.Id)
                               .ToList()
            };

            db.Journals.Add(journal);
            db.SaveChanges();

            List <Publication> fakePublications = this.GetFakePublications()
                                                  .Skip((page - 1) * pageSize)
                                                  .Take(pageSize)
                                                  .ToList();

            int i = -1;

            // Act
            IEnumerable <ListPublicationsServiceModel> publications = publicationService
                                                                      .AllByJournal(journalId, page, pageSize);

            // Assert
            foreach (var actual in publications)
            {
                Publication expected = fakePublications[++i];

                this.ComparePublications(expected, actual);
            }
        }