using System; using System.Collections.Generic; using System.Linq; using System.Text; using Domain.Repositories; using Domain.Entities; using FilmsRUsOnline.Controllers; using NUnit.Framework; namespace UnitTests { [TestFixture] public class FilmUnitTests { [Test] public void Film_RequestPage_ReturnsPageOfFilms() { // Arrange: If there are 5 films in the repository... IFilmsRepository repository = UnitTestUtils.MockFilmsRepository( new Film { Title = "Airplane", Blurb = "Classic spoof airline disaster movie", Genre = "Comedy", RentalPrice = 1.50m }, new Film { Title = "Jaws", Blurb = "Shark-fest film that spooked a generation", Genre = "Thriller", RentalPrice = 1.99m }, new Film { Title = "Love Actually", Blurb = "Feel-good family entertainment", Genre = "RomCom", RentalPrice = 2.99m }, new Film { Title = "Apollo 13", Blurb = "Real-life space drama", Genre = "Entertainment", RentalPrice = 2.99m }, new Film { Title = "Dr. No", Blurb = "First appearance for Bond, James Bond", Genre = "Entertainment", RentalPrice = 1.50m } ); // Create var controller = new FilmsController(repository); controller.PageSize = 3; // Act: ... then when the user asks for the second page (PageSize=3)... var result = controller.List(2); // Assert: ... they'll just see the last two films. var displayedFilms = (IList)result.ViewData.Model; displayedFilms.Count.AssertEqual(2); displayedFilms[0].Title.AssertEqual("Apollo 13"); displayedFilms[1].Title.AssertEqual("Dr. No"); } } }