Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }