public async Task RemoveTraveler_UserTravelPlanNotExists_ReturnsTrue() { var loggedInUserId = _emptyUserId; var userName = "******"; var tpRepo = _mockRepo.Create <ITravelPlanRepository>(); var userRepo = _mockRepo.Create <IUserRepository>(); var userTPService = _mockRepo.Create <IUserTravelPlanService>(); var tpStatusService = _mockRepo.Create <ITravelPlanStatusService>(); Models.TravelPlan travelPlan = new Models.TravelPlan(); travelPlan.UserTravelPlans = null; DTOs.UserDto user = new DTOs.UserDto(); //arrange tpRepo.Setup((tpr) => tpr.GetAsync(_emptyTPId, true)).ReturnsAsync(travelPlan); userRepo.Setup((ur) => ur.GetUserAsync(userName)).ReturnsAsync(user); //act using (var context = new AppDbContext(_dbOptions)) { var tpService = new TravelPlanService(tpRepo.Object, userRepo.Object, userTPService.Object, tpStatusService.Object, context); var result = await tpService.RemoveTraveler(loggedInUserId, userName, _emptyTPId); Assert.IsTrue(result); } }
public async Task RemoveTraveler_HostRemoveThemslves_ThrowsException() { var loggedInUserId = _emptyUserId; var userName = "******"; var tpRepo = _mockRepo.Create <ITravelPlanRepository>(); var userRepo = _mockRepo.Create <IUserRepository>(); var userTPService = _mockRepo.Create <IUserTravelPlanService>(); var tpStatusService = _mockRepo.Create <ITravelPlanStatusService>(); Models.TravelPlan travelPlan = new Models.TravelPlan(); travelPlan.CreatedById = _emptyUserId; //user to remove is the host var userTPToRemove = new Models.UserTravelPlan { UserId = _emptyUserId }; travelPlan.UserTravelPlans = new List <Models.UserTravelPlan> { userTPToRemove }; DTOs.UserDto user = new DTOs.UserDto(); user.Id = _emptyUserId.ToString(); //arrange tpRepo.Setup((tpr) => tpr.GetAsync(_emptyTPId, true)).ReturnsAsync(travelPlan); userRepo.Setup((ur) => ur.GetUserAsync(userName)).ReturnsAsync(user); userTPService.Setup(utp => utp.Delete(It.IsAny <Models.UserTravelPlan>())).ReturnsAsync(true); //act using (var context = new AppDbContext(_dbOptions)) { var tpService = new TravelPlanService(tpRepo.Object, userRepo.Object, userTPService.Object, tpStatusService.Object, context); var result = await tpService.RemoveTraveler(loggedInUserId, userName, _emptyTPId); } }