Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void SubscribeTest_Case_Show_Already_Subscribed()
        {
            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);
            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(400, res.StatusCode);
            Assert.AreEqual("Show already subscribed", res.Value);
        }