public void Cannot_Edit_Post_changes_to_other_users_trips() { TripController controller = new TripController(notUserRepository, provider); notUserTrip.description = "Editted Trip"; controller.Edit(notUserTrip); ViewResult result = controller.Index() as ViewResult; IQueryable <Trip> model = result.Model as IQueryable <Trip>; }
public void DeleteConfirmed_deletes_correct_Trip() { TripController controller = new TripController(repository, provider); controller.DeleteConfirmed(userTrip.TripID); ViewResult result = controller.Index() as ViewResult; IQueryable <Trip> model = result.Model as IQueryable <Trip>; Assert.IsFalse(model.Contains(userTrip)); Assert.AreEqual(0, model.Count()); }
public void Index_returns_list_of_correct_Trips() { TripController controller = new TripController(repository, provider); ViewResult result = controller.Index() as ViewResult; Assert.IsNotNull(result); EnumerableQuery <Trip> model = (EnumerableQuery <Trip>)result.ViewData.Model; Assert.IsNotNull(model); Assert.AreEqual(1, model.Count()); Assert.IsTrue(model.Contains(userTrip)); }
public void Edit_edits_correct_Trip() { TripController controller = new TripController(repository, provider); userTrip.description = "My editted trip"; userTrip.destination = "No where"; controller.Edit(userTrip); ViewResult result = controller.Index() as ViewResult; IQueryable <Trip> model = result.Model as IQueryable <Trip>; Assert.AreEqual(1, model.Count()); Assert.IsTrue(model.Contains(userTrip)); }
public void Create_trip_adds_to_repository() { TripController controller = new TripController(repository, provider); Trip newTrip = new Trip(provider.AuthenticatedUser.UserID); newTrip.current_weight = 8; newTrip.description = "London Trip"; newTrip.destination = "London"; newTrip.total_capacity = 12; newTrip.weather = "Cloudy"; controller.Create(newTrip); ViewResult result = controller.Index() as ViewResult; IQueryable <Trip> model = result.Model as IQueryable <Trip>; Assert.IsTrue(model.Contains(newTrip)); Assert.AreEqual(2, model.Count()); }
public async Task IndexContainsOnlyUserTrip() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip1 = new Trip { Title = "Trip 1", StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123" }; Trip trip2 = new Trip { Title = "Trip 2", StartDate = new DateTime(2015, 4, 13), TripOwner = "ABC123" }; Trip trip3 = new Trip { Title = "Trip 3", StartDate = new DateTime(2015, 4, 16), TripOwner = "ABC123" }; Trip trip4 = new Trip { Title = "Trip 4", StartDate = new DateTime(2018, 4, 16), TripOwner = "AnotherUser" }; tc.Trips.Add(trip1); tc.Trips.Add(trip2); tc.Trips.Add(trip3); tc.Trips.Add(trip4); // Arrange - create a controller var controller = new TripController(tc).WithAuthenticatedUser("ABC123"); // Action var viewResult = await controller.Index(null) as ViewResult; Trip[] result = ((IEnumerable <Trip>)viewResult.ViewData.Model).ToArray(); // Assert - ordered descending + only show trips from ABC123 Assert.AreEqual(3, result.Length); Assert.AreEqual("Trip 3", result[0].Title); Assert.AreEqual("Trip 2", result[1].Title); Assert.AreEqual("Trip 1", result[2].Title); }