public async Task CanSaveValidLeisureActivityChanges() { // Arrange - create mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); // Arrange - create the controller ActivitiesController controller = new ActivitiesController(tc).WithAuthenticatedUser("ABC123"); // Arrange - create a leisure activity LeisureActivity leisure = new LeisureActivity() { ID = 1, Name = "Boat Trip" }; leisure.Step = new Step { StepId = 123, Trip = new Trip { TripId = 321, TotalCost = 100, TripOwner = "ABC123" } }; tc.Activities.Add(leisure); LeisureActivity updatedLeisure = new LeisureActivity() { ID = 1, Name = "Name Changed", StartTime = new DateTime(2018, 8, 1, 14, 30, 0) }; // Act - try to save the activity ActionResult result = await controller.EditLeisure(leisure); // Assert - check the method result type Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }
public async Task CannotSaveInvalidChanges() { // Arrange - create mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); // Arrange - create the controller ActivitiesController controller = new ActivitiesController(tc); // Arrange - create a leisure activity LeisureActivity leisure = new LeisureActivity() { ID = 1, Name = "Boat Trip" }; // Arrange - add an error to the model state controller.ModelState.AddModelError("error", "error"); // Act - try to save the activity ActionResult result = await controller.EditLeisure(leisure); // Assert - check the method result type Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public async Task CanCreateLeisureWithEditMethodAndUpdateBudget() { //Arrange TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step step = new Step { StepId = 2, Trip = new Trip { TripId = 321, TotalCost = 100, TripOwner = "ABC123" } }; tc.Steps.Add(step); LeisureActivity leisureToCreate = new LeisureActivity() { Name = "Boat Trip", StartTime = new DateTime(2018, 7, 16, 9, 30, 0), LeisureCategory = LeisureCategory.aquatic, Price = 20, StepId = 2 }; ActivitiesController controller = new ActivitiesController(tc).WithAuthenticatedUser("ABC123"); // Act var result = await controller.EditLeisure(leisureToCreate) as RedirectToRouteResult; // Assert Assert.AreEqual("Details", result.RouteValues["action"]); Assert.AreEqual("Step", result.RouteValues["controller"]); Assert.AreEqual(120, step.Trip.TotalCost); }