Exemplo n.º 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);
        }
Exemplo n.º 2
0
 private Submission GetSubmission()
 {
     using (var repo = new Voat.Data.Repository())
     {
         return(repo.GetSubmission(submissionID));
     }
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 5
0
 public void Block_Subverse_SubverseDoesNotExist()
 {
     using (var db = new Voat.Data.Repository())
     {
         TestHelper.SetPrincipal("TestUser1");
         db.Block(DomainType.Subverse, "happyhappyjoyjoy");
     }
 }
Exemplo n.º 6
0
 public void SubverseRetrieval()
 {
     using (var db = new Voat.Data.Repository())
     {
         var info = db.GetSubverseInfo("unit");
         Assert.IsTrue(info.Title == "v/unit");
     }
 }
Exemplo n.º 7
0
 public void Block_Subverse_NoAuthentication()
 {
     TestHelper.SetPrincipal(null);
     using (var db = new Voat.Data.Repository())
     {
         db.Block(DomainType.Subverse, "test");
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 10
0
        public async Task GetUserPrefernces_UserNotExists()
        {
            using (var db = new Voat.Data.Repository())
            {
                var p = await db.GetUserPreferences("asrtastarstarstarstart343");

                Assert.AreNotEqual(null, p);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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"));
         }
     });
 }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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"));
         }
     });
 }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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");
            }
        }