public void Setup() { _showDto = new ShowDTO { ID = "1234" }; _showSubDto = new ShowSubscriptionDTO { Id = _showDto.ID, Title = "Test" }; _showService = new Mock <IShowService>(); _showService.Setup(s => s.GetMostPopularShows()).Returns(Task.FromResult(new List <ShowPopularityDTO>())); _showService.Setup(s => s.GetShowByIdAsync(1234)).Returns(Task.FromResult(_showDto)); _subService = new Mock <ISubscriptionService>(); _subService.Setup(s => s.SubscribeToShow(_showSubDto, "123")).Returns(Task.FromResult(true)); _contextMock = new Mock <HttpContext>(); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, _userId), }, "mock")); _contextMock.Setup(x => x.User).Returns(user); _showController = new ShowsController(_showService.Object, _subService.Object); _showController.ControllerContext.HttpContext = _contextMock.Object; }
public async Task <bool> SubscribeToShow(ShowSubscriptionDTO show, string userId) { var user = await CheckIfUserExists(userId); if (user is null) { var newUser = new UserSubscription { Id = Guid.NewGuid().ToString(), UserId = userId, ShowSubscriptions = new List <ShowSubscriptionDTO> { show } }; return(await CreateUserSubscriptionAsync(newUser)); } user.ShowSubscriptions.Add(show); return(await UpdateUserSubcriptionAsync(user)); }