Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public async Task CanCreateStepForTrip()
        {
            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 StepController(tc).WithAuthenticatedUser("ABC123");
            var result     = await controller.Create(1, 1) as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
        }
Example #4
0
        public async Task CanCreateStep()
        {
            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);
            StepViewModel stepViewModel = new StepViewModel
            {
                SequenceNo         = 1,
                From               = "A",
                To                 = "B",
                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) as RedirectToRouteResult;

            Step created = tc.Steps.First();

            Assert.AreEqual("Details", result.RouteValues["action"]);
            Assert.AreEqual("A", created.From);
            Assert.AreEqual(2.5, created.WalkingTime);
            Assert.AreEqual(12, created.WalkingDistance);
        }
Example #5
0
        public async Task CannotCreateStepWithModelErrors()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            Trip newTrip = new Trip
            {
                TripId       = 1,
                Title        = "Test Trip",
                Country      = "Ireland",
                TripCategory = TripCategory.forest,
                StartDate    = new DateTime(2015, 4, 12),
                TripOwner    = "ABC123"
            };

            tc.Trips.Add(newTrip);
            StepViewModel stepViewModel = new StepViewModel
            {
                SequenceNo         = 1,
                From               = "",
                To                 = "",
                WalkingTimeHours   = 2,
                WalkingTimeMinutes = 30,
                WalkingDistance    = 12,
                Ascent             = 630,
                Description        = "A lovely walk",
                Notes              = null,
                TripId             = 1
            };

            var controller = new StepController(tc).WithAuthenticatedUser("ABC123");

            controller.ModelState.AddModelError("", "Error");
            var result = await controller.Create(stepViewModel) as ViewResult;

            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
            Assert.IsNotNull(result.ViewData.ModelState[""].Errors);
        }
Example #6
0
        public async Task CannotCreateStepForNonexistentTrip()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();

            StepViewModel stepViewModel = new StepViewModel
            {
                SequenceNo         = 1,
                From               = "A",
                To                 = "B",
                WalkingTimeHours   = 2,
                WalkingTimeMinutes = 30,
                WalkingDistance    = 12,
                Ascent             = 630,
                Description        = "A lovely walk",
                Notes              = null,
                TripId             = 2
            };

            var controller = new StepController(tc);

            var badResult = await controller.Create(stepViewModel) as ViewResult;

            Assert.AreEqual("CustomisedError", badResult.ViewName);
        }