public async Task Activities_controller_post_should_return_accepted()
        {
            var busClientMock          = new Mock <IBusClient>();
            var activityRepositoryMock = new Mock <IActivityRepository>();
            var controller             = new ActivitiesController(busClientMock.Object,
                                                                  activityRepositoryMock.Object);
            Guid userId = Guid.NewGuid();

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(
                                                   new Claim[] { new Claim(ClaimTypes.Name, userId.ToString()) }
                                                   , "test"))
                }
            };

            var command = new CreateActivity {
                Id     = Guid.NewGuid(),
                UserId = userId
            };

            var result = await controller.Post(command);

            var contentResult = result as AcceptedResult;

            contentResult.Should().NotBeNull();
            contentResult.Location.Should().BeEquivalentTo($"Activities/{command.Id}");
        }
Exemple #2
0
        public async Task ActivityController_PatchActivityStatus_BadRequest()
        {
            // Arrange
            Activity toBeUpdated = new Activity
            {
                Id          = 1,
                Amount      = 10,
                DateTime    = DateTime.Now,
                Description = "Test",
                Status      = "Pending"
            };

            string newStatus = "Completed";

            PatchActivityStatusDto patchDto = null;

            var mockActivityService = new MockActivityService().MockPatchActivityStatus(toBeUpdated, newStatus);
            var controller          = new ActivitiesController(mockActivityService.Object, AutoMapperSingleton.Mapper);

            // Act
            var actionResult = await controller.PatchActivityStatus(1, patchDto);

            //Assert
            Assert.IsType <BadRequestResult>(actionResult);
        }
Exemple #3
0
        public void GetActivities()
        {
            var ActivitiesRepo    = new Mock <IActivitiesRepository>();
            var ActivitiesControl = new ActivitiesController(ActivitiesRepo.Object);

            Assert.IsAssignableFrom <IEnumerable <ActivitiesAC> >(ActivitiesControl.GetActivities());
        }
 public ActivitiesViewModel()
 {
     eventsControllerObject = new ActivitiesController();
     Title            = "events";
     Items            = new ObservableCollection <ActivitiesModel>();
     LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());
 }
Exemple #5
0
        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 void Arrange()
        {
            _mediator.Setup(m => m.SendAsync(_query)).ReturnsAsync(_response);
            _mapper.Setup(m => m.Map <LatestActivitiesViewModel>(_response)).Returns(_viewModel);

            _controller = new ActivitiesController(_mapper.Object, _mediator.Object, _logger.Object);
        }
Exemple #7
0
        public async Task ActivityController_GetActivityById_Sucess()
        {
            // Arrange
            Activity newActivity = new Activity
            {
                Id          = 1,
                Amount      = 10,
                DateTime    = DateTime.Now,
                Description = "Test",
                Status      = "Pending"
            };

            var mockActivityService = new MockActivityService().MockGetActivityById(newActivity);
            var controller          = new ActivitiesController(mockActivityService.Object, AutoMapperSingleton.Mapper);

            // Act
            var actionResult = await controller.GetActivity(1);

            var resultObject = Utils.GetObjectResultContent <Activity>(actionResult);

            //Assert
            Assert.IsType <OkObjectResult>(actionResult.Result);
            Assert.Equal(1, resultObject.Id);
            Assert.Equal(10, resultObject.Amount);
            Assert.Equal("Test", resultObject.Description);
            Assert.Equal("Pending", resultObject.Status);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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 ActivityControllerTests()
        {
            SeedData();
            var fakeGenericRepo = MockGenericRepository.GetUserInformationMock(_fakeActivities);

            FakeController = new ActivitiesController(fakeGenericRepo.Object);
            SetUser(_fakeIdentityUsers[0]);
        }
Exemple #11
0
        public void GetActivity_NotFound()
        {
            var ActivitiesRepo    = new Mock <IActivitiesRepository>();
            var ActivitiesControl = new ActivitiesController(ActivitiesRepo.Object);
            var result            = ActivitiesControl.GetActivities(0);

            Assert.IsType <NotFoundResult>(result.Result);
        }
Exemple #12
0
        private async Task CreateActivitiesAsync()
        {
            var c = new ActivitiesController(_context);

            foreach (var activity in activities)
            {
                var result = await c.Create(activity);
            }
        }
        public void ApiGetActivities()
        {
            var acc = Mock.Of <IActivityService>(a => a.GetActivities() == _manyActivities);
            var uow = Mock.Of <IUnitOfWork>(u => u.ActivityService == acc);
            ActivitiesController controller = new ActivitiesController(uow);
            var activities = controller.GetActivities();

            Assert.IsTrue(activities.EqualValues(_manyActivities));
        }
        public void GetErgWorkoutsTest()
        {
            var controller = new ActivitiesController(
                new NullLogger <ActivitiesController>());

            var workouts = controller.GetErgWorkouts(
                page: 0,
                pageSize: 10);

            Assert.AreEqual(10, workouts.Count());
        }
        public void ApiGetActivityById()
        {
            long id  = 15;
            var  acc = Mock.Of <IActivityService>(a => a.GetActivity(id) == _sampleActivity1);
            var  uow = Mock.Of <IUnitOfWork>(u => u.ActivityService == acc);
            ActivitiesController controller = new ActivitiesController(uow);
            var response = controller.GetActivity(id);
            var result   = response as OkNegotiatedContentResult <ActivityDto>;
            var activity = result.Content;

            Assert.IsTrue(activity.EqualValues(_sampleActivity1));
        }
Exemple #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivitiesControllerTest" /> class.
        /// </summary>
        public ActivitiesControllerTest()
        {
            this.entitiesForTest = new EntitiesForTest();
            this.periodProvider  = new Mock <IPeriodProvider>();
            this.repositoryMock  = new Mock <IRepository <Activity> >();
            this.mapperMock      = new Mock <IMapper>();

            this.target = new ActivitiesController(
                this.periodProvider.Object,
                this.repositoryMock.Object,
                this.mapperMock.Object);
        }
Exemple #17
0
        public void SetUp()
        {
            _activitiesRepository = new Mock <IActivitiesRepository>();
            _clientsRepository    = new Mock <IClientsRepository>();
            _unitWork             = new Mock <IUnitWork>();

            _activitiesController = new ActivitiesController(_activitiesRepository.Object, _clientsRepository.Object,
                                                             _unitWork.Object, ServiceProvider.GetService <IMapper>());

            SetUpActivitiesRepository();
            SetUpClientsRepository();
            SetUpUnitWork();
        }
Exemple #18
0
        public async Task ActivityController_GetById_NotFound()
        {
            // Arrange
            Activity newActivity         = null;
            var      mockActivityService = new MockActivityService().MockGetActivityById(newActivity);
            var      controller          = new ActivitiesController(mockActivityService.Object, AutoMapperSingleton.Mapper);

            // Act
            var actionResult = await controller.GetActivity(2);

            //Assert
            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
Exemple #19
0
        private async Task DeleteAllActivitiesAsync()
        {
            var c     = new ActivitiesController(_context);
            var index = await c.Index();

            var list = (Microsoft.AspNetCore.Mvc.ViewResult)index;
            var IndexActivityViewModel = (IndexActivityViewModel)list.Model;

            foreach (var activity in IndexActivityViewModel.ActivityModels)
            {
                var result = await c.DeleteConfirmed(activity.ActivityID);
            }
        }
        public void ActivityController_Get()
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                Mock <IActivity> actionMock = new Mock <IActivity>();
                actionMock.Setup(a => a.GetById(It.IsAny <IUnitOfWork>(), It.IsAny <Guid>()));
                actionMock.Setup(x => x.Exists(It.IsAny <Guid>())).Returns(true);

                ActivityDO activityDO = new FixtureData(uow).TestActivity3();
                var        controller = new ActivitiesController(actionMock.Object, ObjectFactory.GetInstance <IActivityTemplate>(), ObjectFactory.GetInstance <IPlan>(), ObjectFactory.GetInstance <IUnitOfWorkFactory>());
                controller.Get(activityDO.Id);
                actionMock.Verify(a => a.GetById(It.IsAny <IUnitOfWork>(), activityDO.Id));
            }
        }
        public async Task ActivityController_Delete()
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var activityMock = new Mock <IActivity>();

                activityMock.Setup(a => a.Delete(It.IsAny <Guid>())).Returns(Task.FromResult(0));

                ActivityDO activityDO = new FixtureData(uow).TestActivity3();
                var        controller = new ActivitiesController(activityMock.Object, ObjectFactory.GetInstance <IActivityTemplate>(), ObjectFactory.GetInstance <IPlan>(), ObjectFactory.GetInstance <IUnitOfWorkFactory>());
                await controller.Delete(activityDO.Id);

                activityMock.Verify(a => a.Delete(activityDO.Id));
            }
        }
        public void ApiDeleteActivity()
        {
            long id       = 17;
            var  activity = _sampleActivity2;
            var  mock     = new Mock <IActivityService>();
            var  uowMock  = new Mock <IUnitOfWork>();

            uowMock.Setup(u => u.ActivityService)
            .Returns(mock.Object);
            var con      = new ActivitiesController(uowMock.Object);
            var response = con.DeleteActivity(id);

            Assert.IsInstanceOfType(response, typeof(OkResult));
            mock.Verify(s => s.DeleteActivity(activity.ID));
            uowMock.Verify(u => u.Save());
        }
        public async Task ActivitiesController_Post_Should_Return_Accepted_StatusCode()
        {
            //arrange
            var busClient          = new Mock <IBusClient>();
            var activityRepository = new Mock <IActivityRepository>();
            var userId             = Guid.NewGuid();
            var command            = new CreateActivityCommandModel
            {
                Id          = Guid.NewGuid(),
                Name        = "Test",
                Category    = "TestCategory",
                Description = "Description Category"
            };

            var sut = new ActivitiesController(busClient.Object, activityRepository.Object);

            sut.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(
                        new ClaimsIdentity
                        (
                            new Claim[]
                    {
                        new Claim(ClaimTypes.Name, userId.ToString())
                    },
                            "test"
                        )
                        )
                }
            };

            var routeValues = new Dictionary <string, object>
            {
                { "id", command.Id }
            };
            //act

            var result = await sut.Post(command) as AcceptedAtRouteResult;

            //assert
            result.Should().NotBeNull();
            result.StatusCode?.Should().Be(StatusCodes.Status202Accepted);
            result.RouteName.Should().Be("Get");
            result.RouteValues.Should().BeEquivalentTo(routeValues);
        }
Exemple #24
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);
        }
Exemple #25
0
        public async Task CanCreateLeisureOnStep()
        {
            //Arrange
            TestTrekStoriesContext tc         = new TestTrekStoriesContext();
            ActivitiesController   controller = new ActivitiesController(tc);
            Step step = new Step()
            {
                StepId = 2
            };

            tc.Steps.Add(step);
            // Act
            var result = await controller.CreateLeisure(2) as ViewResult;

            // Assert
            Assert.AreEqual("EditLeisure", result.ViewName);
            Assert.AreEqual(2, result.ViewBag.StepId);
        }
        public void ApiPutActivity()
        {
            long id       = 17;
            var  activity = _sampleActivity2;
            var  mock     = new Mock <IActivityService>();

            mock.Setup(acc => acc.UpdateActivity(activity))
            .Returns(activity);
            var uowMock = new Mock <IUnitOfWork>();

            uowMock.Setup(u => u.ActivityService)
            .Returns(mock.Object);
            var con = new ActivitiesController(uowMock.Object);

            con.PutActivity(id, activity);
            mock.Verify(acc => acc.UpdateActivity(activity));
            uowMock.Verify(u => u.Save());
        }
Exemple #27
0
        public async Task CannotSaveInvalidChanges()
        {
            // Arrange - create mock repository
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            // Arrange - create the controller
            ActivitiesController controller = new ActivitiesController(tc);
            // Arrange - create a leisure activity
            LeisureActivity leisure = new LeisureActivity()
            {
                ID = 1, Name = "Boat Trip"
            };

            // Arrange - add an error to the model state
            controller.ModelState.AddModelError("error", "error");
            // Act - try to save the activity
            ActionResult result = await controller.EditLeisure(leisure);

            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #28
0
        public async Task ActivityController_PatchActivityStatus_NotFound()
        {
            // Arrange
            Activity toBeUpdated = null;

            string newStatus = "Completed";

            PatchActivityStatusDto patchDto = new PatchActivityStatusDto
            {
                Status = newStatus
            };

            var mockActivityService = new MockActivityService().MockPatchActivityStatus(toBeUpdated, newStatus);
            var controller          = new ActivitiesController(mockActivityService.Object, AutoMapperSingleton.Mapper);

            // Act
            var actionResult = await controller.PatchActivityStatus(1, patchDto);

            //Assert
            Assert.IsType <NotFoundResult>(actionResult);
        }
Exemple #29
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);
        }
Exemple #30
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);
        }