public async Task CanEditPostStep() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip = new Trip { TripId = 111, TripOwner = "ABC123" }; tc.Trips.Add(trip); Step step = new Step { StepId = 123, TripId = 111, Trip = trip }; tc.Steps.Add(step); StepViewModel stepVm = new StepViewModel { StepId = 123, SequenceNo = 2, From = "B", To = "C", WalkingDistance = 0, WalkingTimeHours = 2, WalkingTimeMinutes = 30, TripId = 111 }; var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); var result = await controller.Edit(stepVm) as RedirectToRouteResult; Assert.AreEqual("Details", result.RouteValues["action"]); }
public async Task CannotEditStepWithModelErrors() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step step = new Step { StepId = 123, Trip = new Trip { TripId = 111, TripOwner = "ABC123" } }; tc.Steps.Add(step); StepViewModel stepVm = new StepViewModel { StepId = 123, TripId = 111 }; var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); controller.ModelState.AddModelError("", "Error"); var result = await controller.Edit(stepVm) as ViewResult; Assert.AreEqual("", result.ViewName); Assert.AreEqual(false, result.ViewData.ModelState.IsValid); Assert.IsNotNull(result.ViewData.ModelState[""].Errors); }
public async Task EditStepReturnsCorrectStepVm() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step step = new Step { StepId = 123, SequenceNo = 2, From = "B", To = "C", WalkingDistance = 0, WalkingTime = 3.5, Trip = new Trip { TripOwner = "ABC123" } }; tc.Steps.Add(step); var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); var result = await controller.Edit(123) as ViewResult; var resultStep = (StepViewModel)result.ViewData.Model; Assert.AreEqual(123, resultStep.StepId); Assert.AreEqual(3, resultStep.WalkingTimeHours); Assert.AreEqual(30, resultStep.WalkingTimeMinutes); }