Exemplo n.º 1
0
        public async Task CreateSet_Test()
        {
            var userName = "******";
            var user     = TestHelper.SetPrincipal(userName);

            var set = new Set()
            {
                Name = "HolyHell", Title = "Some Title", Type = SetType.Normal, UserName = userName
            };
            var cmd    = new UpdateSetCommand(set).SetUserContext(user);
            var result = await cmd.Execute();

            VoatAssert.IsValid(result);

            Assert.AreNotEqual(0, result.Response.ID);
            var setID = result.Response.ID;

            VerifySubscriber(set, userName, 1);

            //Subscribe another user
            userName = "******";
            user     = TestHelper.SetPrincipal(userName);
            var subCmd    = new SubscribeCommand(new DomainReference(DomainType.Set, set.Name, set.UserName), SubscriptionAction.Subscribe).SetUserContext(user);
            var subResult = await subCmd.Execute();

            VoatAssert.IsValid(result);
            VerifySubscriber(set, userName, 2);

            //unsub user
            subCmd    = new SubscribeCommand(new DomainReference(DomainType.Set, set.Name, set.UserName), SubscriptionAction.Unsubscribe).SetUserContext(user);
            subResult = await subCmd.Execute();

            VoatAssert.IsValid(result);
            VerifySubscriber(set, userName, 1, false);
        }
Exemplo n.º 2
0
        public async Task UserData_Information_SubscriptionTests()
        {
            //ensure users with no subscriptions don't error out
            var noSubUserName = "******";

            TestDataInitializer.CreateUser(noSubUserName);

            var userData = new Domain.UserData(noSubUserName);

            //var userData = new Domain.UserData(noSubUserName);
            Assert.AreEqual(0, userData.SubverseSubscriptions.Count());
            Assert.AreEqual(false, userData.HasSubscriptions());
            Assert.AreEqual(false, userData.HasSubscriptions(DomainType.Subverse));

            //test subscription
            var subUserName = "******";

            TestDataInitializer.CreateUser(subUserName);

            var user = TestHelper.SetPrincipal(subUserName);
            var cmd  = new SubscribeCommand(new DomainReference(DomainType.Subverse, SUBVERSES.Unit), Domain.Models.SubscriptionAction.Subscribe).SetUserContext(user);
            var x    = await cmd.Execute();

            VoatAssert.IsValid(x);

            userData = new Domain.UserData(subUserName);

            Assert.AreEqual(1, userData.SubverseSubscriptions.Count());
            Assert.AreEqual(SUBVERSES.Unit, userData.SubverseSubscriptions.First());
            Assert.AreEqual(true, userData.HasSubscriptions());
            Assert.AreEqual(true, userData.HasSubscriptions(DomainType.Subverse));
            Assert.AreEqual(true, userData.IsUserSubverseSubscriber(SUBVERSES.Unit));
        }
Exemplo n.º 3
0
        public async Task <JsonResult> Subscribe(Domain.Models.DomainType domainType, string name, Domain.Models.SubscriptionAction subscribeAction)
        {
            var domainReference = Domain.Models.DomainReference.Parse(name, domainType);

            var cmd    = new SubscribeCommand(domainReference, subscribeAction).SetUserContext(User);
            var result = await cmd.Execute();

            return(JsonResult(result));
        }
        public async Task <JsonResult> UnSubscribe(string subverseName)
        {
            //var loggedInUser = User.Identity.Name;

            //Voat.Utilities.UserHelper.UnSubscribeFromSubverse(loggedInUser, subverseName);
            //return Json("Unsubscribe request was successful." /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */);
            var cmd = new SubscribeCommand(new Domain.Models.DomainReference(Domain.Models.DomainType.Subverse, subverseName), Domain.Models.SubscriptionAction.Unsubscribe).SetUserContext(User);
            var r   = await cmd.Execute();

            if (r.Success)
            {
                return(Json("Unsubscribe request was successful." /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */));
            }
            else
            {
                return(Json(r.Message /* CORE_PORT: Removed , JsonRequestBehavior.AllowGet */));
            }
        }
Exemplo n.º 5
0
        public async Task FrontPage_Lifecycle_Tests()
        {
            var userName = "******";
            var subName  = SUBVERSES.Unit;

            TestDataInitializer.CreateUser(userName);
            var user = TestHelper.SetPrincipal(userName);

            //Verify No Front / Blocked Sets
            var userSubQuery   = new QueryUserSubscriptions(userName);
            var userSubResults = await userSubQuery.ExecuteAsync();

            Assert.IsNotNull(userSubResults, "Old McDonald had a farm ee i ee i o. And on that farm he shot some guys. Badda boom badda bing bang boom.");
            Assert.AreEqual(0, userSubResults[DomainType.Set].Count(), "He is supposed to be Turkish. Some say his father was German. Nobody believed he was real.");

            var userSetQuery   = new QueryUserSets(userName);
            var userSetResults = await userSetQuery.ExecuteAsync();

            Assert.IsNotNull(userSetResults, "One cannot be betrayed if one has no people.");
            Assert.AreEqual(0, userSetResults.Count(), "A man can convince anyone he's somebody else, but never himself.");

            var currentSubscriberCount = 0;

            using (var db = new VoatDataContext())
            {
                var count = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                currentSubscriberCount = count.HasValue ? count.Value : 0;
            }

            //Sub a user to front
            var domainReference = new DomainReference(DomainType.Subverse, subName);
            var subCmd          = new SubscribeCommand(domainReference, SubscriptionAction.Toggle).SetUserContext(user);
            var subResult       = await subCmd.Execute();

            VoatAssert.IsValid(subResult);

            //Verify Front is created
            userSubQuery   = new QueryUserSubscriptions(userName, CachePolicy.None);
            userSubResults = await userSubQuery.ExecuteAsync();

            Assert.IsNotNull(userSubResults, "What about it, pretzel man? What's your story?");
            Assert.AreEqual(1, userSubResults[DomainType.Set].Count(), "First day on the job, you know what I learned? How to spot a murderer.");
            Assert.IsTrue(userSubResults[DomainType.Set].First() == new DomainReference(DomainType.Set, "Front", userName).FullName, "It was Keyser Soze, Agent Kujan. I mean the Devil himself. How do you shoot the Devil in the back? What if you miss?");

            userSetQuery   = new QueryUserSets(userName).SetUserContext(user);
            userSetResults = await userSetQuery.ExecuteAsync();

            Assert.IsNotNull(userSetResults, "What the cops never figured out, and what I know now, was that these men would never break, never lie down, never bend over for anybody");
            Assert.AreEqual(1, userSetResults.Count(), "Is it Friday already? ");
            var set = userSetResults.First();

            Assert.AreEqual(SetType.Front, set.Type, "I got a whole new problem when I post bail.");
            Assert.AreEqual(1, set.SubscriberCount, "I got a whole new problem when I post bail.");

            //Ensure Subverse Subscriber Count Updated
            using (var db = new VoatDataContext())
            {
                var tc    = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                var count = tc.HasValue ? tc.Value : 0;
                Assert.AreEqual(currentSubscriberCount + 1, count, "");
                currentSubscriberCount = count;
            }

            //verify FRONT set has sub
            using (var repo = new Voat.Data.Repository())
            {
                var setList = await repo.GetSetListDescription(SetType.Front.ToString(), userName);

                Assert.IsTrue(setList.Any(x => x.Name == subName));
            }

            //Unsubscribe
            subCmd    = new SubscribeCommand(domainReference, SubscriptionAction.Toggle).SetUserContext(user);
            subResult = await subCmd.Execute();

            VoatAssert.IsValid(subResult);

            //Ensure Subverse Subscriber Count Updated
            using (var db = new VoatDataContext())
            {
                var count = db.Subverse.First(x => x.Name == subName).SubscriberCount;
                Assert.AreEqual(currentSubscriberCount - 1, count.HasValue ? count.Value : 0, "");
            }

            //verify FRONT set has not sub
            using (var repo = new Voat.Data.Repository())
            {
                var setList = await repo.GetSetListDescription(SetType.Front.ToString(), userName);

                Assert.IsFalse(setList.Any(x => x.Name == subName));
            }
        }