Exemplo n.º 1
0
        public async Task CreateAsync_InvalidTPId_ThrowsException()
        {
            DTOs.TravelPlanDto travelPlanDto = null;

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

            //arrange
            tpService.Setup((tps) => tps.GetAsync(_emptyTPID, false, false)).ReturnsAsync(travelPlanDto);

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

                //verify
            }
        }
Exemplo n.º 2
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);
            }
        }