public void Activity_Details() { var activity = activities.Where(a => a.ActivityID == ACTIVITY_ID_TO_USE).FirstOrDefault(); ViewResult viewResult = controller.Details(ACTIVITY_ID_TO_USE) as ViewResult; var model = viewResult.Model as Activity; Assert.IsNotNull(model); Assert.AreEqual(model.ActivityID, ACTIVITY_ID_TO_USE); Assert.AreEqual(model.ActivityID, activity.ActivityID); Assert.AreEqual(model.Description, activity.Description); }
public async Task DetailsReturnsCorrectView() { // Arrange - create the mock repository with leisure activities TestTrekStoriesContext tc = new TestTrekStoriesContext(); Transport transport1 = new Transport() { ID = 1, Name = "Train" }; LeisureActivity leisure1 = new LeisureActivity() { ID = 2, Name = "Boat Trip" }; LeisureActivity leisure2 = new LeisureActivity() { ID = 3, Name = "Museum Visit" }; tc.Activities.Add(transport1); tc.Activities.Add(leisure1); tc.Activities.Add(leisure2); // Arrange - create the controller ActivitiesController controller = new ActivitiesController(tc); // Act var result1 = await controller.Details(1) as ViewResult; var t1 = (Transport)result1.ViewData.Model; var result2 = await controller.Details(3) as ViewResult; var l2 = (LeisureActivity)result2.ViewData.Model; // Assert Assert.AreEqual("DetailsTransport", result1.ViewName); Assert.AreEqual(1, t1.ID); Assert.AreEqual("DetailsLeisure", result2.ViewName); Assert.AreEqual("Museum Visit", l2.Name); }