Ejemplo n.º 1
0
        public async Task EditAsync_InvalidActivityID_ThrowsException()
        {
            var tpService      = _mockRepo.Create <ITravelPlanService>();
            var tpActivityRepo = _mockRepo.Create <ITravelPlanActivityRepository>();

            Models.TravelPlanActivity nullTPActivity = null;

            //arrange
            tpActivityRepo.Setup((tpa) => tpa.GetAsync(It.IsAny <Guid>())).ReturnsAsync(nullTPActivity);
            //act
            using (var context = new AppDbContext(_dbOptions))
            {
                var tpActivityService = new TPActivityService(context, tpService.Object, tpActivityRepo.Object);
                var result            = await tpActivityService.EditAsync(_genericActivityDTO, _emptyUserId);

                //verify
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteAsync_UserNotHost_ThrowsInsufficientRightsException()
        {
            var tpService          = _mockRepo.Create <ITravelPlanService>();
            var tpActivityRepo     = _mockRepo.Create <ITravelPlanActivityRepository>();
            var tpActivityToDelete = new Models.TravelPlanActivity
            {
                HostId = Guid.NewGuid()
            };

            //arrange
            tpActivityRepo.Setup((tpa) => tpa.GetAsync(It.IsAny <Guid>())).ReturnsAsync(tpActivityToDelete);
            //act
            using (var context = new AppDbContext(_dbOptions))
            {
                var tpActivityService = new TPActivityService(context, tpService.Object, tpActivityRepo.Object);
                var result            = await tpActivityService.EditAsync(_genericActivityDTO, _emptyUserId);

                //verify
            }
        }
Ejemplo n.º 3
0
        public async Task CreateAsync_ValidActivity_ReturnsActivity()
        {
            var newActivity = new Models.TravelPlanActivity
            {
                Name      = _genericActivityDTO.Name,
                StartTime = _genericActivityDTO.StartTime,
                EndTime   = _genericActivityDTO.EndTime,
                Category  = _genericActivityDTO.Category,
                Location  = new Models.Location
                {
                    Address   = _genericActivityDTO.Location.Address,
                    Latitude  = _genericActivityDTO.Location.Latitude,
                    Longitude = _genericActivityDTO.Location.Longitude,
                },
                HostId       = _emptyUserId,
                TravelPlanId = _genericActivityDTO.TravelPlanId
            };

            var travelPlanDto = new DTOs.TravelPlanDto();

            var tpService      = _mockRepo.Create <ITravelPlanService>();
            var tpActivityRepo = _mockRepo.Create <ITravelPlanActivityRepository>();

            //arrange
            tpService.Setup((tps) => tps.GetAsync(_emptyTPID, false, false)).ReturnsAsync(travelPlanDto);
            tpActivityRepo.Setup((tpa) => tpa.CreateAsync(It.IsAny <Models.TravelPlanActivity>())).ReturnsAsync(newActivity);

            //act
            using (var context = new AppDbContext(_dbOptions))
            {
                var tpActivityService = new TPActivityService(context, tpService.Object, tpActivityRepo.Object);
                var result            = await tpActivityService.CreateAsync(_genericActivityDTO, _emptyUserId);

                //verify
                Assert.IsNotNull(result);
                Assert.IsTrue(result is DTOs.TravelPlanActivityDto);
            }
        }