public async Task CreateTransportUpdatesBudget() { //Arrange TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip = new Trip { TripId = 1, TotalCost = 10, StartDate = new DateTime(2018, 7, 15, 9, 30, 0), TripOwner = "User1" }; Step step = new Step { StepId = 2, TripId = 1, Trip = trip, SequenceNo = 1 }; tc.Trips.Add(trip); tc.Steps.Add(step); Transport transportToCreate = new Transport() { Name = "Train to Paris", StartTime = new DateTime(2018, 7, 16, 9, 30, 0), Duration = 120, Price = 23, StepId = 2, Step = step }; ActivitiesController controller = new ActivitiesController(tc).WithAuthenticatedUser("User1"); // Act var result = await controller.EditTransport(transportToCreate) as RedirectToRouteResult; // Assert Assert.AreEqual("Details", result.RouteValues["action"]); Assert.AreEqual("Step", result.RouteValues["controller"]); Assert.AreEqual(33, trip.TotalCost); Assert.AreEqual(new DateTime(2018, 7, 15, 11, 30, 0), transportToCreate.GetArrivalTime()); }
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 CannotSaveInvalidReview() { // Arrange - create mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); // Arrange - create a review Step step = new Step { StepId = 21, Trip = new Trip { TripId = 321, TripOwner = "ABC123" } }; tc.Steps.Add(step); Review review = new Review() { StepId = 21, Step = step, PrivateNotes = "Test" }; // Arrange - create the controller ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("ABC123"); // Arrange - add an error to the model state controller.ModelState.AddModelError("error", "error"); // Act - try to save the review ActionResult result = await controller.Edit(review); // Assert - check the method result type Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public async Task CanDeleteImage() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step step = new Step { StepId = 12, Trip = new Trip { TripId = 214, TripOwner = "User1" } }; Image image1 = new Image { Id = 25, ReviewId = 1, Url = "url1", Review = new Review { ReviewId = 1, Step = step } }; tc.Images.Add(image1); ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("User1"); var UrlHelperMock = new Mock <UrlHelper>(); controller.Url = UrlHelperMock.Object; UrlHelperMock.Setup(x => x.Action("Edit", "Review", new { id = "12#AddPhoto" })).Returns("testUrl"); var result = await controller.DeleteImageAsync(25) as RedirectToRouteResult; Assert.IsNull(tc.Images.Find(25)); }
public async Task CannotEditSomebodyElseReview() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var review = new Review { ReviewId = 1, PrivateNotes = "Test Private", StepId = 1, Rating = 3 }; tc.Reviews.Add(review); Step step = new Step { StepId = 1, Trip = new Trip { TripId = 10, TripOwner = "ABC123" } }; tc.Steps.Add(step); ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("AnotherUser"); // Act var updatedReview = new Review { ReviewId = 1, PrivateNotes = "New notes", StepId = 1, Rating = 4 }; var result = await controller.Edit(updatedReview) as ViewResult; // Assert Assert.AreEqual("CustomisedError", result.ViewName); }
public async Task CanDeleteValidActivityAndUpdateBudget() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip = new Trip { TripId = 1, Title = "Trip Name", TotalCost = 20, TripOwner = "ABC123" }; tc.Trips.Add(trip); Step step = new Step { StepId = 123, TripId = 1 }; tc.Steps.Add(step); tc.Activities.Add(new LeisureActivity() { ID = 1, Name = "Aquapark", StepId = 123 }); LeisureActivity l2 = new LeisureActivity() { ID = 2, Name = "Test", StepId = 123, Price = 15 }; tc.Activities.Add(l2); // Arrange - create the controller ActivitiesController controller = new ActivitiesController(tc).WithAuthenticatedUser("ABC123"); // Act - delete an activity var result = await controller.Delete(2); // Assert - ensure that the activity is deleted from repository Assert.IsNull(tc.Activities.FirstOrDefault(l => l.ID == l2.ID)); // Assert - ensure that the trip budget was updated Assert.AreEqual(5, trip.TotalCost); }
public async Task DetailsReturnsCorrectTrip() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var trip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", TotalWalkingDistance = 45 }; tc.Trips.Add(trip); var controller = new TripController(tc).WithAuthenticatedUser("Whatever"); var result = await controller.Details(1) as ViewResult; Trip t = (Trip)((ViewResult)result).Model; Assert.AreEqual("Test Trip", t.Title); Assert.AreEqual(TripCategory.forest, t.TripCategory); Assert.AreEqual(0, t.Duration); Assert.AreEqual(0, t.TotalCost); Assert.AreEqual(45, t.TotalWalkingDistance); }
public async Task CannotDeleteStepWithAccommodation() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step stepA = new Step { StepId = 11, SequenceNo = 1, TripId = 2, Accommodation = new Accommodation { AccommodationId = 1, Name = "Hotel Zuki" }, Trip = new Trip { TripOwner = "ABC123" } }; tc.Steps.Add(stepA); var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); var result = await controller.Delete(11) as RedirectToRouteResult; Assert.AreEqual("Details", result.RouteValues["action"]); Assert.AreEqual("Step", result.RouteValues["controller"]); Assert.AreEqual( "Step 1 cannot be deleted because it is linked to an accommodation. Please first edit or delete the accommodation for the step.", controller.TempData["message"]); }
public async Task CanEditTrip() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var trip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", }; tc.Trips.Add(trip); TripController controller = new TripController(tc).WithIncomingValues(new FormCollection { { "Title", "Another Title" }, { "TripId", "1" }, { "Country", "Ireland" } }).WithAuthenticatedUser("ABC123"); // Act var result = await controller.EditPost(1); string newTitle = tc.Trips.Find(1).Title; // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); Assert.AreEqual("Another Title", newTitle); }
public async Task EditReviewReturnsCorrectDetails() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var expectedReview = new Review { ReviewId = 1, PrivateNotes = "Test Private", StepId = 1, Rating = 3, Images = new List <Image>() }; tc.Reviews.Add(expectedReview); tc.Steps.Add(new Step { StepId = 1, From = "A", To = "B", Review = expectedReview }); ReviewController controller = new ReviewController(tc); // act var result = await controller.Edit(1) as ViewResult; var resultData = (Review)result.ViewData.Model; // assert Assert.AreEqual(expectedReview.Rating, resultData.Rating); Assert.AreEqual(expectedReview.PrivateNotes, resultData.PrivateNotes); }
public async Task DetailsReturnsCorrectStep() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); StepController controller = new StepController(tc).WithAuthenticatedUser("UserA"); Step step = new Step() { StepId = 123, SequenceNo = 2, From = "B", To = "C", WalkingDistance = 0, WalkingTime = 3.5 }; step.Trip = new Trip { TripId = 1, Steps = new List <Step>() { step }, TripOwner = "UserB" }; tc.Steps.Add(step); ViewResult result = await controller.Details(123) as ViewResult; var step123 = (Step)result.ViewData.Model; Assert.AreEqual(2, step123.SequenceNo); Assert.AreEqual("B", step123.From); Assert.AreEqual(1, controller.ViewBag.Steps.Length); Assert.AreEqual(123, controller.ViewBag.Steps[0]); }
public async Task CanEditAccommodation() { // Arrange - create the mock repository with accommodations TestTrekStoriesContext tc = new TestTrekStoriesContext(); Accommodation acc1 = new Accommodation { AccommodationId = 1, Name = "Hotel A" }; Accommodation acc2 = new Accommodation { AccommodationId = 2, Name = "Hotel B" }; tc.Accommodations.Add(acc1); tc.Accommodations.Add(acc2); // Arrange - create the controller AccommodationController controller = new AccommodationController(tc); // Act var result1 = await controller.Edit(1) as ViewResult; var a1 = (Accommodation)result1.ViewData.Model; var result2 = await controller.Edit(2) as ViewResult; var a2 = (Accommodation)result2.ViewData.Model; // Assert Assert.AreEqual(1, a1.AccommodationId); Assert.AreEqual(2, a2.AccommodationId); Assert.AreEqual("Hotel A", a1.Name); }
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 CannotEditAccommodationIfBeforeTripStartDate() { // Arrange - create mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); // Arrange - create an accommodation and a step linked to it Accommodation acc = new Accommodation { AccommodationId = 1, Name = "Hotel A", CheckIn = new DateTime(2018, 8, 10, 10, 0, 0), CheckOut = new DateTime(2018, 8, 11, 10, 0, 0) }; tc.Accommodations.Add(acc); Trip trip = new Trip { TripId = 11, StartDate = new DateTime(2018, 8, 10), TripOwner = "ABC123" }; Step step = new Step { StepId = 123, Trip = trip, AccommodationId = 1, SequenceNo = 1 }; tc.Steps.Add(step); // Arrange - create the controller with update accommodation data var controller = new AccommodationController(tc).WithIncomingValues(new FormCollection { { "AccommodationId", "1" }, { "Name", "Name Changed" }, { "CheckIn", "09-08-2018 10:00 AM" }, { "CheckOut", "11-08-2018 10:00 AM" } }).WithAuthenticatedUser("ABC123"); // Act - try to save the accommodation var result = await controller.EditPost(1, null) as ViewResult; // Assert - check the method result type Assert.IsFalse(result.ViewData.ModelState.IsValid); }
public async Task CannotCreateTripWithSameTitleForSameUser() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip = new Trip { Title = "Test", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "User1" }; tc.Trips.Add(trip); Trip newTrip = new Trip { Title = "Test", Country = "Spain", TripCategory = TripCategory.coast, StartDate = new DateTime(2015, 4, 12), TripOwner = "User1" }; var controller = new TripController(tc).WithAuthenticatedUser("User1"); var result = await controller.Create(newTrip) as ViewResult; Assert.AreEqual(false, result.ViewData.ModelState.IsValid); Assert.IsTrue(controller.ViewData.ModelState.Count == 1, "You have already created a trip with that title. Please give this trip a different title."); }
public async Task EditTripReturnsCorrectDetails() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var expectedTrip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", TotalWalkingDistance = 45 }; tc.Trips.Add(expectedTrip); TripController controller = new TripController(tc).WithAuthenticatedUser("ABC123"); // act var result = await controller.Edit(1) as ViewResult; var resultData = (Trip)result.ViewData.Model; // assert Assert.AreEqual(expectedTrip.Title, resultData.Title); Assert.AreEqual(expectedTrip.Country, resultData.Country); Assert.AreEqual(expectedTrip.TotalWalkingDistance, resultData.TotalWalkingDistance); }
public async Task CanEditReview() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var review = new Review { ReviewId = 1, PrivateNotes = "Test Private", StepId = 1, Rating = 3 }; tc.Reviews.Add(review); Step step = new Step { StepId = 1, Trip = new Trip { TripId = 10, TripOwner = "ABC123" } }; tc.Steps.Add(step); ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("ABC123"); // Act var updatedReview = new Review { ReviewId = 1, PrivateNotes = "New notes", StepId = 1, Rating = 4 }; var result = await controller.Edit(updatedReview); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
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 CanDeleteAccommodationAndUpdateBudget() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip = new Trip { TripId = 1, Title = "Trip Name", TotalCost = 120, TripOwner = "ABC123" }; tc.Trips.Add(trip); tc.Steps.Add(new Step { StepId = 123, Trip = trip, AccommodationId = 2 }); Accommodation a2 = new Accommodation() { AccommodationId = 2, Name = "Test", Price = 70 }; tc.Accommodations.Add(a2); // Arrange - create the controller AccommodationController controller = new AccommodationController(tc).WithAuthenticatedUser("ABC123"); // Act - delete an accommodation var result = await controller.DeleteConfirmed(2); // Assert - ensure that the accommodation is deleted from repository Assert.IsNull(tc.Accommodations.FirstOrDefault(a => a.AccommodationId == a2.AccommodationId)); // Assert - ensure that the trip budget was updated Assert.AreEqual(trip.TotalCost, 50); }
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); }
public async Task CannotEditSomebodyElseTrip() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var trip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", }; tc.Trips.Add(trip); TripController controller = new TripController(tc).WithIncomingValues(new FormCollection { { "Title", "Another Title" }, { "TripId", "1" }, { "Country", "Ireland" } }).WithAuthenticatedUser("AnotherUser"); // Act var result = await controller.EditPost(1) as ViewResult; // Assert Assert.AreEqual("CustomisedError", result.ViewName); }
public async Task DeleteNonExistingStepReturnsNotFound() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); var controller = new StepController(tc); var badResult = await controller.Delete(12) as ViewResult; Assert.AreEqual("CustomisedError", badResult.ViewName); }
public async Task CannotEditAccommodationIfOneAlreadyExistsForThoseDates() { // Arrange - create mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); // Arrange - create two accommodations linked to 2 different steps Accommodation acc1 = new Accommodation { AccommodationId = 1, Name = "Hotel A", CheckIn = new DateTime(2018, 8, 10, 12, 0, 0), CheckOut = new DateTime(2018, 8, 11, 10, 0, 0), Price = 0 }; Accommodation acc2 = new Accommodation { AccommodationId = 2, Name = "Hotel B", CheckIn = new DateTime(2018, 8, 11, 12, 0, 0), CheckOut = new DateTime(2018, 8, 12, 10, 0, 0), Price = 0 }; tc.Accommodations.Add(acc1); tc.Accommodations.Add(acc2); Trip trip = new Trip { TripId = 11, StartDate = new DateTime(2018, 8, 10), TripOwner = "ABC123", TotalCost = 0, Steps = new List <Step>() { new Step { StepId = 123, TripId = 11, AccommodationId = 1, SequenceNo = 1, Trip = new Trip { StartDate = new DateTime(2018, 8, 10) } }, new Step { StepId = 124, TripId = 11, AccommodationId = 2, SequenceNo = 2, Trip = new Trip { StartDate = new DateTime(2018, 8, 10) } } } }; tc.Trips.Add(trip); Step step1 = new Step { StepId = 123, TripId = 11, Trip = trip, AccommodationId = 1, Accommodation = acc1, SequenceNo = 1 }; Step step2 = new Step { StepId = 124, TripId = 11, Trip = trip, AccommodationId = 2, Accommodation = acc2, SequenceNo = 2 }; tc.Steps.Add(step1); tc.Steps.Add(step2); // Arrange - create the controller with update accommodation data var controller = new AccommodationController(tc).WithIncomingValues(new FormCollection { { "AccommodationId", "1" }, { "Name", "Name Changed" }, { "CheckIn", "11-08-2018 10:00 AM" }, { "CheckOut", "12-08-2018 10:00 AM" }, { "Price", "0" } }).WithAuthenticatedUser("ABC123"); // Act - try to save the activity var result = await controller.EditPost(1, null) as ViewResult; // Assert - check the method result type Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual("An accommodation already exists for Step 2", controller.ViewBag.ErrorMessage); }
public async Task InsertStepReassignsAccommodations() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip newTrip = new Trip { Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123" }; tc.Trips.Add(newTrip); Accommodation acc = new Accommodation { AccommodationId = 122 }; tc.Accommodations.Add(acc); Step stepA = new Step { StepId = 11, SequenceNo = 1 }; Step stepB = new Step { StepId = 12, SequenceNo = 2, AccommodationId = 122 }; Step stepC = new Step { StepId = 10, SequenceNo = 3 }; tc.Steps.Add(stepA); tc.Steps.Add(stepB); tc.Steps.Add(stepC); StepViewModel stepViewModel = new StepViewModel { SequenceNo = 2, From = "B", To = "C", WalkingTimeHours = 2, WalkingTimeMinutes = 30, WalkingDistance = 12, Ascent = 630, Description = "A lovely walk", Notes = null, TripId = newTrip.TripId }; var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); var result = await controller.Create(stepViewModel); var insertedStep = tc.Steps.FirstOrDefault(s => s.SequenceNo == 2); Assert.AreEqual(null, stepB.AccommodationId); Assert.AreEqual(122, insertedStep.AccommodationId); }
public async Task CanSearchTrip() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip1 = new Trip { Title = "Trip 1", StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", TripCategory = TripCategory.architecture }; Trip trip2 = new Trip { Title = "Trip 2", StartDate = new DateTime(2015, 4, 13), TripOwner = "ABC123", TripCategory = TripCategory.forest }; Trip trip3 = new Trip { Title = "Another Title", StartDate = new DateTime(2015, 4, 16), TripOwner = "ABC123" }; Trip trip4 = new Trip { Title = "Trip 4", StartDate = new DateTime(2018, 4, 16), TripOwner = "AnotherUser", TripCategory = TripCategory.architecture }; 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); // Action TripSearchModel searchModel = new TripSearchModel { TripCategory = TripCategory.architecture, TitleKeyword = "Trip" }; var viewResult = await controller.Search(searchModel) as ViewResult; List <Trip> result = (List <Trip>)viewResult.ViewData.Model; // Assert - ordered descending + only show trips from ABC123 Assert.AreEqual(2, result.Count); CollectionAssert.Contains(result, trip1); CollectionAssert.Contains(result, trip4); }
public async Task CannotCreateAccommodationForStepsWhereAccommodationExists() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); //add step with accommodation Step step = new Step { StepId = 11, TripId = 1, SequenceNo = 1, Trip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2018, 11, 28), TotalCost = 80, TripOwner = "ABC123" }, AccommodationId = 12, Accommodation = new Accommodation { AccommodationId = 12, CheckIn = new DateTime(2018, 11, 28, 16, 0, 0) } }; tc.Trips.Add(new Trip { TripId = 1, TripOwner = "ABC123", StartDate = new DateTime(2018, 11, 28), TotalCost = 80, Steps = new List <Step>() { step } }); tc.Steps.Add(step); AccommodationController controller = new AccommodationController(tc).WithAuthenticatedUser("ABC123"); //try to add accommodation for that step with existing acommodation.. Accommodation newAccommodation = new Accommodation() { CheckIn = new DateTime(2018, 11, 28, 14, 0, 0), CheckOut = new DateTime(2018, 11, 29, 10, 0, 0), Price = 80, ConfirmationFileUrl = "1" }; var result = await controller.Create(newAccommodation); Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual("An accommodation already exists for Step 1", controller.ViewBag.ErrorMessage); }
public async Task CreateStepEditsSeqNoOfSubsequentSteps() { TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip newTrip = new Trip { Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123" }; tc.Trips.Add(newTrip); Step stepA = new Step { StepId = 11, SequenceNo = 1 }; Step stepB = new Step { StepId = 12, SequenceNo = 2 }; Step stepC = new Step { StepId = 10, SequenceNo = 3 }; tc.Steps.Add(stepA); tc.Steps.Add(stepB); tc.Steps.Add(stepC); StepViewModel stepViewModel = new StepViewModel { SequenceNo = 2, From = "B", To = "C", WalkingTimeHours = 2, WalkingTimeMinutes = 30, WalkingDistance = 12, Ascent = 630, Description = "A lovely walk", Notes = null, TripId = newTrip.TripId }; var controller = new StepController(tc).WithAuthenticatedUser("ABC123"); var result = await controller.Create(stepViewModel); Assert.AreEqual(1, stepA.SequenceNo); Assert.AreEqual(3, stepB.SequenceNo); Assert.AreEqual(4, stepC.SequenceNo); }
public async Task CannotEditNonexistentAccommodation() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Accommodation acc1 = new Accommodation { AccommodationId = 1, Name = "Hotel A" }; tc.Accommodations.Add(acc1); // Arrange - create the controller AccommodationController controller = new AccommodationController(tc); // Act var badResult = await controller.Edit(4) as ViewResult; // Assert Assert.AreEqual("CustomisedError", badResult.ViewName); }
public async Task CanCreateAccommodationAndUpdateTripBudget() { //Arrange TestTrekStoriesContext tc = new TestTrekStoriesContext(); Step step = new Step { StepId = 11, TripId = 1, SequenceNo = 1, Trip = new Trip { TripId = 1, Title = "Test Trip", Country = "Ireland", TripCategory = TripCategory.forest, StartDate = new DateTime(2018, 11, 28), TotalCost = 80, TripOwner = "ABC123" } }; tc.Trips.Add(new Trip { TripId = 1, TripOwner = "ABC123", StartDate = new DateTime(2018, 11, 28), TotalCost = 80, Steps = new List <Step>() { step } }); tc.Steps.Add(step); Accommodation newAccommodation = new Accommodation() { CheckIn = new DateTime(2018, 11, 28, 14, 0, 0), CheckOut = new DateTime(2018, 11, 29, 10, 0, 0), Price = 80, ConfirmationFileUrl = "1" }; AccommodationController controller = new AccommodationController(tc).WithAuthenticatedUser("ABC123"); // Act var result = await controller.Create(newAccommodation) as RedirectToRouteResult; Trip trip = tc.Trips.Find(1); // Assert Assert.AreEqual("Edit", result.RouteValues["action"]); Assert.AreEqual(160, trip.TotalCost); }
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); }