public void Index() { // Arrange HomeController controller = new HomeController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void About() { Agency agency1 = new Agency { Name = "Agence 1", AdditionalInformation = "Description agence 1" }; Agency agency2 = new Agency { Name = "Agence 2", AdditionalInformation = "Description agence 2" }; Announcement announcement1 = new Announcement { Agency = agency1, Description = "Description de l'annonce 1", IsAvailable = true, Price = 400, Ref = "20151018.1", Surface = 100, Title = "Location Maison" }; Announcement announcement2 = new Announcement { Agency = agency1, Description = "Description de l'annonce 2", IsAvailable = true, Price = 160000, Ref = "20151018.2", Surface = 100, Title = "Venter Maison" }; ICollection<Agency> fakeAgencies = new List<Agency>(new[] { agency1, agency2 }); ICollection<Announcement> fakeAnnouncements = new List<Announcement>(new[] { announcement1, announcement2 }); IUnitOfWork fakeUnitOfWork = new FakeUnitOfWork(fakeAnnouncements, fakeAgencies); IAnnouncementService fakeAnnouncementService = new FakeAnnouncementService(); fakeAnnouncementService.UnitOfWork = fakeUnitOfWork; IAgencyService fakeAgencyService = new FakeAgencyService(); fakeAgencyService.UnitOfWork = fakeUnitOfWork; // Arrange HomeController controller = new HomeController(); controller.AnnouncementService = fakeAnnouncementService; controller.AgencyService = fakeAgencyService; // Act ViewResult result = controller.About() as ViewResult; // Assert Assert.AreEqual("Your application description page.", result.ViewBag.Message); Assert.AreEqual((result.Model as ICollection<Agency>).Count, 2); Assert.AreEqual(typeof(List<Agency>), result.Model.GetType()); Assert.AreEqual(typeof(List<Announcement>), result.ViewData["Announcements"].GetType()); }