예제 #1
0
        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);
        }
예제 #2
0
        public void UnsubscribeTest_Case_Ok()
        {
            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 = true
            });

            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(200, res.StatusCode);
            Assert.AreEqual("Unsubscribed", res.Value);
            Assert.AreEqual(0, user.TvShowSubscriptions.Count);
        }