public void Activity_Edit_HttpGet()
        {
            ActionResult actionResult = controller.Edit(ACTIVITY_ID_TO_USE);
            var          model        = (actionResult as ViewResult).Model;

            Assert.IsNotNull(model);
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
        }
示例#2
0
        public void EditActivity_Succeeds()
        {
            ActivityDTO activityDTO = new ActivityDTO()
            {
                ActivityId   = 2,
                ActivityType = ActivityType.ATELIER,
                Name         = "Zwemmen",
                Description  = "",
                Pictogram    = null
            };

            _activityRepository.Setup(m => m.GetById(activityDTO.ActivityId)).Returns(_dummyDBContext.Activity2);

            ActionResult <Activity> actionResult  = _controller.Edit(activityDTO);
            OkObjectResult          actionResult2 = actionResult.Result as OkObjectResult;
            Activity activity = actionResult2.Value as Activity;

            Assert.Equal("Zwemmen", activity.Name);
            Assert.Equal("", activity.Description);
            _activityRepository.Verify(a => a.SaveChanges(), Times.Once());
        }
示例#3
0
        public async Task CanEditLeisure()
        {
            // Arrange - create the mock repository with leisure activities
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            Step step1 = new Step {
                StepId = 1, From = "A", To = "B"
            };
            Step step2 = new Step {
                StepId = 2, From = "B", To = "C"
            };
            LeisureActivity leisure1 = new LeisureActivity()
            {
                ID = 1, Name = "Boat Trip", StepId = 1, Step = step1
            };
            LeisureActivity leisure2 = new LeisureActivity()
            {
                ID = 2, Name = "Museum Visit", StepId = 2, Step = step2
            };

            tc.Steps.Add(step1);
            tc.Steps.Add(step2);
            tc.Activities.Add(leisure1);
            tc.Activities.Add(leisure2);
            // Arrange - create the controller
            ActivitiesController controller = new ActivitiesController(tc);
            // Act
            var result1 = await controller.Edit(1) as ViewResult;

            var l1      = (LeisureActivity)result1.ViewData.Model;
            var result2 = await controller.Edit(2) as ViewResult;

            var l2 = (LeisureActivity)result2.ViewData.Model;

            // Assert
            Assert.AreEqual(1, l1.ID);
            Assert.AreEqual(2, l2.ID);
            Assert.AreEqual("Boat Trip", l1.Name);
        }
示例#4
0
        public async Task CanEditTransport()
        {
            // Arrange - create the mock repository with leisure activities
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            Step step1 = new Step {
                StepId = 1, From = "A", To = "B"
            };
            Step step2 = new Step {
                StepId = 2, From = "B", To = "C"
            };
            Transport transport1 = new Transport()
            {
                ID = 1, Name = "Train", StepId = 1, Step = step1
            };
            Transport transport2 = new Transport()
            {
                ID = 2, Name = "Bus", StepId = 2, Step = step2
            };

            tc.Steps.Add(step1);
            tc.Steps.Add(step2);
            tc.Activities.Add(transport1);
            tc.Activities.Add(transport2);
            // Arrange - create the controller
            ActivitiesController controller = new ActivitiesController(tc);
            // Act
            var result1 = await controller.Edit(1) as ViewResult;

            var t1      = (Transport)result1.ViewData.Model;
            var result2 = await controller.Edit(2) as ViewResult;

            var t2 = (Transport)result2.ViewData.Model;

            // Assert
            Assert.AreEqual(1, t1.ID);
            Assert.AreEqual(2, t2.ID);
            Assert.AreEqual("Train", t1.Name);
        }
示例#5
0
        public async Task CannotEditNonexistentLeisure()
        {
            // Arrange - create the mock repository
            TestTrekStoriesContext tc       = new TestTrekStoriesContext();
            LeisureActivity        leisure1 = new LeisureActivity()
            {
                ID = 1, Name = "Boat Trip"
            };

            tc.Activities.Add(leisure1);
            // Arrange - create the controller
            ActivitiesController controller = new ActivitiesController(tc);
            // Act
            var badResult = await controller.Edit(4) as ViewResult;

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