Example #1
0
        public async Task CreateComment_Anon()
        {
            string userName = "******";
            var    user     = TestHelper.SetPrincipal(userName);

            var cmd = new CreateCommentCommand(2, null, "This is my data").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c);
            Assert.AreNotEqual(0, c.Response.ID);
            Assert.AreEqual(true, c.Response.IsAnonymized);
            Assert.AreNotEqual(cmd.Content, c.Response.FormattedContent);

            //verify in db
            using (var db = new Voat.Data.Repository(user))
            {
                var comment = await db.GetComment(c.Response.ID);

                Assert.IsNotNull(comment, "Couldn't find comment in db", c.Response.ID);

                Assert.AreEqual(c.Response.ID, comment.ID);
                Assert.AreEqual(comment.ID.ToString(), comment.UserName);
                Assert.AreEqual(c.Response.Content, comment.Content);
                Assert.IsTrue(comment.IsAnonymized);
                Assert.AreEqual(c.Response.IsAnonymized, comment.IsAnonymized);
            }

            base.VerifyCommentIsProtected(c.Response.SubmissionID.Value, c.Response.ID, userName);
        }
Example #2
0
 private Submission GetSubmission()
 {
     using (var repo = new Voat.Data.Repository())
     {
         return(repo.GetSubmission(submissionID));
     }
 }
Example #3
0
        public async Task Block_Subverse_Toggle()
        {
            string userName = "******";

            var user = TestHelper.SetPrincipal(userName);

            using (var db = new Voat.Data.Repository(user))
            {
                string name = "whatever";

                await db.Block(DomainType.Subverse, name, SubscriptionAction.Toggle);

                var blocks = await db.GetBlockedSubverses(userName);

                Assert.IsNotNull(blocks);
                Assert.IsTrue(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse));

                await db.Block(DomainType.Subverse, name, SubscriptionAction.Toggle);

                blocks = await db.GetBlockedSubverses(userName);

                Assert.IsNotNull(blocks);
                Assert.IsFalse(blocks.Any(x => x.Name == name && x.Type == DomainType.Subverse));
            }
        }
Example #4
0
        public void BannedDomainTest()
        {
            var domain      = "paydayloansforeverybody.com";
            var reason      = "Total Rip off!";
            var createdBy   = "AntiSpamcist";
            var createdDate = DateTime.UtcNow.AddDays(-10);

            using (var db = new VoatDataContext())
            {
                db.BannedDomain.Add(new BannedDomain()
                {
                    Domain       = domain,
                    Reason       = reason,
                    CreatedBy    = createdBy,
                    CreationDate = createdDate
                });
                db.SaveChanges();
            }
            using (var repo = new Voat.Data.Repository())
            {
                var result = repo.BannedDomains(new string[] { "yahoo.com", "google.com", domain, domain.ToUpper(), "testuri.org" });
                Assert.IsNotNull(result, "Result was null");
                Assert.IsTrue(result.Any(), "Result expected");
                Assert.AreEqual(1, result.Count(), "Count off");
                var bd = result.First();
                Assert.AreEqual(domain, bd.Domain);
                Assert.AreEqual(reason, bd.Reason);
                Assert.AreEqual(createdBy, bd.CreatedBy);
                Assert.AreEqual(createdDate.ToString(), bd.CreationDate.ToString());

                result = repo.BannedDomains(new string[] { "subdomain." + domain });
                Assert.IsNotNull(result, "subdomain failure");
                Assert.IsTrue(result.Any(), "Subdomain Result expected");
            }
        }
Example #5
0
 public void Block_Subverse_SubverseDoesNotExist()
 {
     using (var db = new Voat.Data.Repository())
     {
         TestHelper.SetPrincipal("TestUser1");
         db.Block(DomainType.Subverse, "happyhappyjoyjoy");
     }
 }
Example #6
0
 public void SubverseRetrieval()
 {
     using (var db = new Voat.Data.Repository())
     {
         var info = db.GetSubverseInfo("unit");
         Assert.IsTrue(info.Title == "v/unit");
     }
 }
Example #7
0
 public void Block_Subverse_NoAuthentication()
 {
     TestHelper.SetPrincipal(null);
     using (var db = new Voat.Data.Repository())
     {
         db.Block(DomainType.Subverse, "test");
     }
 }
Example #8
0
 public void GetAnonymousSubmission()
 {
     using (var db = new Voat.Data.Repository())
     {
         var anon_sub = db.GetSubmission(2);
         Assert.IsTrue(anon_sub.UserName == anon_sub.ID.ToString());
     }
 }
Example #9
0
 public void Get_SubversesUser_Moderates()
 {
     using (var db = new Voat.Data.Repository())
     {
         var result = db.GetSubversesUserModerates("unit");
         Assert.IsNotNull(result, "Result was null");
         Assert.IsTrue(result.Any(x => x.Subverse == "AuthorizedOnly"), "Result expected to see subverse AuthorizedOnly for user unit");
     }
 }
Example #10
0
        public async Task GetUserPrefernces_UserNotExists()
        {
            using (var db = new Voat.Data.Repository())
            {
                var p = await db.GetUserPreferences("asrtastarstarstarstart343");

                Assert.AreNotEqual(null, p);
            }
        }
Example #11
0
        public async Task GetSubmission()
        {
            using (var db = new Voat.Data.Repository())
            {
                var s = await db.GetSubmissionsDapper("unit", new SearchOptions()).ConfigureAwait(false);

                Assert.IsTrue(s.Any());
            }
        }
Example #12
0
        public async Task SaveComment()
        {
            using (var db = new Voat.Data.Repository())
            {
                var result = await db.Save(ContentType.Comment, 1);

                Assert.AreEqual(Status.Success, result.Status);
                Assert.AreEqual(true, result.Response.Value);
            }
        }
Example #13
0
        public void GetAnonymousSubmission()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var anon_sub = db.GetSubmission(2);
                Assert.IsTrue(anon_sub.UserName == anon_sub.ID.ToString());
            }
        }
Example #14
0
        public void SubverseRetrieval()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var info = db.GetSubverseInfo(SUBVERSES.Unit);
                Assert.IsTrue(info.Title == "v/unit");
            }
        }
Example #15
0
 public async Task Block_Subverse_NoAuthentication()
 {
     await VoatAssert.ThrowsAsync <VoatSecurityException>(() => {
         var user = TestHelper.SetPrincipal(null);
         using (var db = new Voat.Data.Repository(user))
         {
             return(db.Block(DomainType.Subverse, "test"));
         }
     });
 }
Example #16
0
        public void Get_SubversesUser_Moderates()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var result = db.GetSubversesUserModerates(USERNAMES.Unit);
                Assert.IsNotNull(result, "Result was null");
                Assert.IsTrue(result.Any(x => x.Subverse == "AuthorizedOnly"), "Result expected to see subverse AuthorizedOnly for user unit");
            }
        }
Example #17
0
        public async Task EnsureLogVisitWorks()
        {
            using (var repo = new Voat.Data.Repository())
            {
                await repo.LogVisit(null, 1, "127.0.0.1");

                await repo.LogVisit(SUBVERSES.Whatever, null, "127.0.0.2");

                await repo.LogVisit(SUBVERSES.Anon, 2, "127.0.0.3");
            }
        }
Example #18
0
        public async Task GetUserPrefernces_UserNotExists()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var p = await db.GetUserPreferences("asrtastarstarstarstart343");

                Assert.AreNotEqual(null, p);
            }
        }
Example #19
0
 public async Task Block_Subverse_SubverseDoesNotExist()
 {
     string userName = "******";
     var    user     = TestHelper.SetPrincipal(userName);
     await VoatAssert.ThrowsAsync <VoatNotFoundException>(() => {
         using (var db = new Voat.Data.Repository(user))
         {
             return(db.Block(DomainType.Subverse, "happyhappyjoyjoy"));
         }
     });
 }
Example #20
0
        public async Task GetSubmission()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var s = await db.GetSubmissionsDapper(new DomainReference(DomainType.Subverse, SUBVERSES.Unit), new SearchOptions()).ConfigureAwait(Utilities.CONSTANTS.AWAIT_CAPTURE_CONTEXT);

                Assert.IsTrue(s.Any());
            }
        }
Example #21
0
 public void GetAnonymousComments()
 {
     using (var db = new Voat.Data.Repository())
     {
         var comments = db.GetCommentTree(2, null, null);
         foreach (var c in comments)
         {
             Assert.IsTrue(c.IsAnonymized);
         }
     }
 }
Example #22
0
        public async Task SaveComment()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var result = await db.Save(ContentType.Comment, 1);

                Assert.AreEqual(Status.Success, result.Status);
                Assert.AreEqual(true, result.Response);
            }
        }
Example #23
0
        public async Task GetUserPrefernces()
        {
            using (var db = new Voat.Data.Repository())
            {
                var p = await db.GetUserPreferences("unit");

                Assert.IsTrue(p != null);
                Assert.IsTrue(p.UserName == "unit");
                Assert.IsTrue(p.Bio == "User unit's short bio");
                Assert.IsTrue(!p.DisableCSS);
            }
        }
Example #24
0
        public async Task GetSubmissionsFilterAnonymous()
        {
            using (var db = new Voat.Data.Repository())
            {
                var anon_sub = await db.GetSubmissionsDapper("anon", SearchOptions.Default).ConfigureAwait(false);

                var first = anon_sub.OrderBy(x => x.CreationDate).First();
                Assert.IsNotNull(first, "no anon submissions found");
                Assert.AreEqual("First Anon Post", first.Title);
                Assert.AreEqual(first.UserName, first.ID.ToString());
            }
        }
Example #25
0
        public async Task PostComment_BannedDomain()
        {
            using (var db = new Voat.Data.Repository())
            {
                TestHelper.SetPrincipal("TestUser10");

                var result = await db.PostComment(1, null, "Check out my new post: http://www.fleddit.com/r/something/hen9s87r9/How-I-Made-a-million-virtual-cat-pics");

                Assert.IsNotNull(result, "Result was null");
                Assert.IsFalse(result.Success, "Submitting content with banned domain did not get rejected");
                Assert.AreEqual(Status.Denied, result.Status, "Expecting a denied status");
            }
        }
Example #26
0
        public void GetAnonymousComments()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var comments = db.GetCommentTree(2, null, null);
                foreach (var c in comments)
                {
                    Assert.IsTrue(c.IsAnonymized);
                }
            }
        }
Example #27
0
        public async Task GetUserPrefernces()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var p = await db.GetUserPreferences(USERNAMES.Unit);

                Assert.IsTrue(p != null);
                Assert.IsTrue(p.UserName == USERNAMES.Unit);
                Assert.IsTrue(p.Bio == "User unit's short bio");
                Assert.IsTrue(!p.DisableCSS);
            }
        }
Example #28
0
        public async Task GetSubmissionsFilterAnonymous()
        {
            var user = TestHelper.SetPrincipal(null);

            using (var db = new Voat.Data.Repository(user))
            {
                var anon_sub = await db.GetSubmissionsDapper(new DomainReference(DomainType.Subverse, SUBVERSES.Anon), SearchOptions.Default).ConfigureAwait(Utilities.CONSTANTS.AWAIT_CAPTURE_CONTEXT);

                var first = anon_sub.OrderBy(x => x.CreationDate).First();
                Assert.IsNotNull(first, "no anon submissions found");
                Assert.AreEqual("First Anon Post", first.Title);
                Assert.AreEqual(first.UserName, first.ID.ToString());
            }
        }
Example #29
0
        public async Task PostSubmission_AuthorizedOnly_Denied()
        {
            using (var db = new Voat.Data.Repository())
            {
                TestHelper.SetPrincipal("TestUser11");

                var result = await db.PostSubmission(new UserSubmission()
                {
                    Subverse = "AuthorizedOnly", Title = "Ha ha, you can't stop me", Content = "Cookies for you my friend"
                });

                Assert.IsNotNull(result, "Result was null");
                Assert.IsFalse(result.Success, "Submitting to authorized only subverse was allowed by non admin");
                Assert.AreEqual(Status.Denied, result.Status, "Expecting a denied status");
            }
        }
Example #30
0
        public async Task PostSubmission_AuthorizedOnly_Allow()
        {
            var user = TestHelper.SetPrincipal(USERNAMES.Unit);

            using (var db = new Voat.Data.Repository(user))
            {
                var result = await db.PostSubmission(new UserSubmission()
                {
                    Subverse = SUBVERSES.AuthorizedOnly, Title = "Ha ha, you can't stop me", Content = "Cookies for you my friend"
                });

                Assert.IsNotNull(result, "Result was null");
                Assert.IsTrue(result.Success, "Submitting to authorized only subverse was not allowed by admin");
                Assert.AreEqual(Status.Success, result.Status, "Expecting a success status");
            }
        }