public void UnsubscribeTest_Case_Show_Not_Subscribed() { var user = new User { Email = "*****@*****.**", Role = Role.User, FamilyName = "", GivenName = "", Picture = "", Id = Guid.NewGuid(), TvShowSubscriptions = new List <TvShowSubscription>() }; userRepository.Setup(c => c.FindUser(It.IsAny <Guid>())).Returns(user); var controller = new TvShowController(logger.Object, showRssService.Object, userRepository.Object, memoryCache.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user.MapToClaimPrincipal() } } }; var res = controller.Unsubscribe(123); Assert.AreEqual(400, res.StatusCode); Assert.AreEqual("Show not subscribed", res.Value); }
public void Setup() { _fixture = new Fixture(); _fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => _fixture.Behaviors.Remove(b)); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _shows = _fixture.Create <IEnumerable <TvShow> >(); _logger = new Mock <ILogger>(); _getTVShowsByUser = new Mock <IGetTVShowsByUser>(); _userContextManager = new Mock <IUserContextManager>(); _userContextManager.Setup(x => x.GetUserIdFromContext()).Returns("testuser"); _getTVShowsByUser.Setup(x => x.GetTvShowsByUserId(It.IsAny <string>())).ReturnsAsync(new ActionResponse <IEnumerable <TvShow> > { WasSuccessful = true, Result = _shows }); _mapping = _fixture.Create <UserTVShowMapping>(); _userTVShowMappingManager = new Mock <IUserTVShowMappingManager>(); _userTVShowMappingManager.Setup(x => x.ManageAdditionAsync(It.IsAny <TvShow>())).ReturnsAsync(new ActionResponse <UserTVShowMapping> { WasSuccessful = true, Result = _mapping }); _userTVShowMappingManager.Setup(x => x.ManageDeletionAsync(It.IsAny <string>())).ReturnsAsync(new ActionResponse <UserTVShowMapping> { WasSuccessful = true, Result = null }); _showController = new TvShowController(_getTVShowsByUser.Object, _logger.Object, _userContextManager.Object, _userTVShowMappingManager.Object); }
public void Check_Modal_State_Is_Valid_Then_Response_Ok() { // Setup var mockTvShowService = new Mock <ITvShowService>(); mockTvShowService.Setup(x => x.GetFilteredTvShows(It.IsAny <List <TvShowRequest> >())).Returns( new List <TvShowResponse> { new TvShowResponse(new TvShow(new TvShowRequest { Drm = true, EpisodeCount = 3, ImageRequest = new ImageRequest(), Slug = "dd", Title = "ddd" })) }); // Action var controller = new TvShowController(mockTvShowService.Object); var actionResult = controller.Post(new ApiRequest <TvShowRequest>()); // Assert var okRes = actionResult as OkNegotiatedContentResult <ApiResponse <TvShowResponse> >; Assert.IsNotNull(okRes); }
public void SubscribeTest_Case_Ok() { var user = new User { Email = "*****@*****.**", Role = Role.User, FamilyName = "", GivenName = "", Picture = "", Id = Guid.NewGuid(), TvShowSubscriptions = new List <TvShowSubscription>() }; userRepository.Setup(c => c.FindUser(It.IsAny <Guid>())).Returns(user); userRepository.Setup(c => c.IsTvShowSubscribedByOtherUsers(It.IsAny <int>(), It.IsAny <Guid>())).Returns(false); var emptySummary = new SubscriptionsSummary { SubscribedShows = new List <TvShowRss>() }; showRssService.Setup(c => c.Authenticate(out emptySummary)).Returns(new ShowRssAuthenticationContext()); showRssService .Setup(c => c.SubscribeToShow(It.IsAny <ShowRssAuthenticationContext>(), It.IsAny <int>())) .Returns(new ShowRssGlobalSubscriptionService.SubscriptionResult { Succeeded = true, Summary = new SubscriptionsSummary { SubscribedShows = new List <TvShowRss> { new TvShowRss { ShowRssId = 123 } } } }); var controller = new TvShowController(logger.Object, showRssService.Object, userRepository.Object, memoryCache.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user.MapToClaimPrincipal() } } }; var res = controller.Subscribe(123); Assert.AreEqual(200, res.StatusCode); Assert.AreEqual("Subscribed", res.Value); Assert.AreEqual(1, user.TvShowSubscriptions.Count); Assert.AreEqual(123, user.TvShowSubscriptions.First().ShowRssId); }
public void UnsubscribeTest_Case_ShowRssUnsubscribeFailed() { var user = new User { Email = "*****@*****.**", Role = Role.User, FamilyName = "", GivenName = "", Picture = "", Id = Guid.NewGuid(), TvShowSubscriptions = new List <TvShowSubscription> { new TvShowSubscription { Id = new Guid(), ShowRssId = 123, ShowTitle = "ABC" } } }; userRepository.Setup(c => c.FindUser(It.IsAny <Guid>())).Returns(user); userRepository.Setup(c => c.IsTvShowSubscribedByOtherUsers(It.IsAny <int>(), It.IsAny <Guid>())).Returns(false); var emptySummary = new SubscriptionsSummary(); showRssService.Setup(c => c.Authenticate(out emptySummary)).Returns(new ShowRssAuthenticationContext()); showRssService .Setup(c => c.UnsubscribeToShow(It.IsAny <ShowRssAuthenticationContext>(), It.IsAny <int>())) .Returns(new ShowRssGlobalSubscriptionService.UnsubscriptionResult { Succeeded = false }); var controller = new TvShowController(logger.Object, showRssService.Object, userRepository.Object, memoryCache.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user.MapToClaimPrincipal() } } }; var res = controller.Unsubscribe(123); Assert.AreEqual(400, res.StatusCode); Assert.AreEqual("Internal error, failed to unsubscribe to show", res.Value); }
public void TestApiWithPaginationOnPageWithNoElementsAndEmptyListReturn() { var tvshows = GetMockedListOfTvShows(25); var mockRepo = new Mock <ITvShowRepository>(); mockRepo.Setup(repo => repo.Get()).Returns(tvshows); var controller = new TvShowController(mockRepo.Object); var results = Assert.IsType <OkObjectResult>(controller.Get(4).Result); Assert.Equal(200, results.StatusCode); var list = new List <TvShow>((IEnumerable <TvShow>)results.Value); Assert.Empty(list); }
public void Check_Bad_Request_With_Message_Is_Response_When_Invalid_Json_Is_Sent() { // Setup var controller = new TvShowController(); // Action controller.ModelState.AddModelError("test", "test"); var actionResult = controller.Post(new ApiRequest <TvShowRequest>()); // Assert var badRequest = actionResult as NegotiatedContentResult <ErrorResponse>; Assert.IsNotNull(badRequest); Assert.That(badRequest.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); Assert.That(badRequest.Content.Error, Is.EqualTo("Could not decode request: JSON parsing failed")); }
public void TestApiWithPaginationWhenMoreThanTenTvShowsAndNoPageParameter() { var tvshows = GetMockedListOfTvShows(25); var mockRepo = new Mock <ITvShowRepository>(); mockRepo.Setup(repo => repo.Get()).Returns(tvshows); var controller = new TvShowController(mockRepo.Object); var results = Assert.IsType <OkObjectResult>(controller.Get().Result); Assert.Equal(200, results.StatusCode); var list = new List <TvShow>((IEnumerable <TvShow>)results.Value); Assert.Equal(10, list.Count); Assert.Equal(1, list[0].Id); Assert.Equal(10, list[9].Id); }
public void AddTvShowAsyncTest() { var resultDto = new ResultDto { Title = "Success" }; _fixture.MockService.Setup(_ => _.AddTvShowAsync(It.IsAny <SearchTv>(), Convert.ToInt32(TestConsts.Id))) .ReturnsAsync(resultDto); var controller = new TvShowController(_fixture.MockService.Object, _fixture.Mapper) { ControllerContext = _fixture.ControllerContextWithSession() }; var result = controller.AddTvShowAsync(JsonConvert.SerializeObject(new SearchTv())); var viewResult = Assert.IsType <PartialViewResult>(result.Result); Assert.IsType <ResultViewModel>(viewResult.Model); }
public void SearchTvShowAsync() { const string query = "TvShowTitle"; var resultDto = new SearchResultDto <string, SearchTv>() { CurrentCollection = new List <string> { "True Detective" }, QueryCollection = new List <SearchTv>() }; _fixture.MockService.Setup(_ => _.SearchTvShowAsync(query)).ReturnsAsync(resultDto); var controller = new TvShowController(_fixture.MockService.Object, _fixture.Mapper); var result = controller.SearchTvShowAsync(query); var viewResult = Assert.IsType <PartialViewResult>(result.Result); Assert.IsType <SearchResultViewModel <string, SearchTv> >(viewResult.Model); }
public void TestApiNoPagination() { var tvshows = new List <TvShow>() { new TvShow() { Id = 1, Name = "Tv Show 1", Cast = new List <CastMember>() { new CastMember() { Id = 1, Name = "Actor 1", Birthday = DateTime.Now.AddYears(-30) } } }, new TvShow() { Id = 2, Name = "Tv Show 2" } }; var mockRepo = new Mock <ITvShowRepository>(); mockRepo.Setup(repo => repo.Get()).Returns(tvshows); var controller = new TvShowController(mockRepo.Object); var results = Assert.IsType <OkObjectResult>(controller.Get().Result); Assert.Equal(200, results.StatusCode); var list = new List <TvShow>((IEnumerable <TvShow>)results.Value); Assert.Equal(2, list.Count); }
public TvShowControllerTests() { tvShowMockRepo = Substitute.For <IRepository <TvShow> >(); testController = new TvShowController(tvShowMockRepo); }