예제 #1
0
        public async Task MentionUser_MentionWithReply_Duplicate_Test()
        {
            // This test will require rewriting the notification code. Current this does not pass and as such has it's test method commented out.

            //We have two pipelines for sending notifications. They need to be centralized to allow this test to pass. Future people, solve this.

            string user1 = "UnitTestUser09";
            string user2 = "UnitTestUser10";

            var    user           = TestHelper.SetPrincipal(user1);
            string commentContent = $"Some ground breaking inciteful comment here";
            var    cmd            = new CreateCommentCommand(submission.ID, null, commentContent);
            var    result         = await cmd.Execute();

            Assert.IsTrue(result.Success, result.Message);

            user           = TestHelper.SetPrincipal(user2);
            commentContent = $"Hey @{user1} I'm replying to your comment and mentioning you because I'm super annoying. Like you.";
            cmd            = new CreateCommentCommand(submission.ID, result.Response.ID, commentContent);
            result         = await cmd.Execute();

            Assert.IsTrue(result.Success, result.Message);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x => x.Sender == user2 && x.Recipient == user1 && x.CommentID == result.Response.ID).Count();
                Assert.AreEqual(1, count, "Received duplicates and now users are annoyed and burning down the village! Run!");
            }
        }
예제 #2
0
        public void DeleteComment()
        {
            TestHelper.SetPrincipal("TestUser1");
            var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know");
            var c         = cmdcreate.Execute().Result;

            Assert.IsNotNull(c, "response null");
            Assert.IsTrue(c.Success, c.Message);
            Assert.IsNotNull(c.Response, "Response payload null");

            int id = c.Response.ID;

            var cmd = new DeleteCommentCommand(id);
            var r   = cmd.Execute().Result;

            Assert.IsTrue(r.Success);

            //verify
            using (var db = new Voat.Data.Repository())
            {
                var comment = db.GetComment(id);
                Assert.AreEqual(true, comment.IsDeleted);
                Assert.AreNotEqual(c.Response.Content, comment.Content);
            }
        }
예제 #3
0
        public async Task CreateComment_TestSubmissionCommentNotification()
        {
            var userName = "******";

            TestHelper.SetPrincipal(userName);
            var body = Guid.NewGuid().ToString();
            var cmd  = new CreateCommentCommand(1, null, body);
            var c    = await cmd.Execute();

            Assert.IsNotNull(c, "response null");
            if (!c.Success)
            {
                if (c.Exception != null)
                {
                    Assert.Fail(c.Exception.ToString());
                }
                else
                {
                    Assert.Fail(c.Message);
                }
            }
            Assert.AreEqual(Status.Success, c.Status);

            //check for comment reply entry
            using (var db = new voatEntities())
            {
                var notice = db.Messages.FirstOrDefault(x => x.Sender == userName && x.Recipient == "anon" && x.SubmissionID == 1);
                Assert.IsNotNull(notice, "Did not find a reply notification");
            }
        }
예제 #4
0
        public void ReturnCorrectMessage_WhenCorrectParametrsArePassed()
        {
            //Arrange
            gettersMock.Setup(x => x.GetWorkItem(It.IsAny <IBoard>(), validWorkItemTitle)).Returns(workItemMock.Object);

            this.componentsFactoryMock.Setup(x => x.CreateComment(this.validMessage, It.IsAny <IPerson>())).Returns(this.commentMock.Object);

            var sut        = new CreateCommentCommand(this.historyEventWriterMock.Object, this.componentsFactoryMock.Object, this.gettersMock.Object);
            var parameters = new List <string>()
            {
                this.validTeamName,
                this.validBoardName,
                this.validWorkItemTitle,
                this.validMessage,
                this.validAuthorName,
            };

            var expectedReturn = string.Format(CommandsConsts.CommentAdded, validMessage, validAuthorName, validWorkItemTitle);

            //Act
            var actualReturn = sut.Execute(parameters);

            //Assert
            Assert.AreEqual(expectedReturn, actualReturn);
        }
예제 #5
0
        public void DeleteComment_Owner()
        {
            //Assert.Inconclusive("Complete this test");

            var user      = TestHelper.SetPrincipal("TestUser01");
            var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know").SetUserContext(user);
            var c         = cmdcreate.Execute().Result;

            VoatAssert.IsValid(c);

            int id = c.Response.ID;

            var cmd = new DeleteCommentCommand(id).SetUserContext(user);
            var r   = cmd.Execute().Result;

            VoatAssert.IsValid(r);

            //verify
            using (var db = new VoatDataContext())
            {
                var comment = db.Comment.FirstOrDefault(x => x.ID == id);
                Assert.AreEqual(true, comment.IsDeleted);
                Assert.AreNotEqual(c.Response.Content, comment.Content);

                //Ensure content is replaced in moderator deletion
                Assert.IsTrue(comment.Content.StartsWith("Deleted by"));
                Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(comment.Content));
            }
        }
예제 #6
0
        public async Task MentionUser_Duplicate_Test()
        {
            string user1 = "UnitTestUser05";
            string user2 = "UnitTestUser06";

            var user = TestHelper.SetPrincipal(user1);

            string mentionTwiceContent = $"Hello @{user2}, I am mentioning you twice using two different forms ok. So here: /u/{user2} ha ha";
            var    cmd    = new CreateCommentCommand(submission.ID, null, mentionTwiceContent).SetUserContext(user);
            var    result = await cmd.Execute();

            Assert.IsTrue(result.Success, result.Message);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x => x.Sender == user1 && x.Recipient == user2 && x.CommentID == result.Response.ID).Count();
                Assert.AreEqual(1, count, "Received duplicates and now users are annoyed and burning down the village! Run!");
            }


            //change casing test
            user = TestHelper.SetPrincipal(user2);
            mentionTwiceContent = $"Hello @{user1.ToLower()}, I am mentioning you twice using two different forms ok. So here: /u/{user1.ToUpper()} ha ha";
            cmd    = new CreateCommentCommand(submission.ID, null, mentionTwiceContent).SetUserContext(user);
            result = await cmd.Execute();

            Assert.IsTrue(result.Success, result.Message);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x => x.Sender == user2 && x.Recipient == user1 && x.CommentID == result.Response.ID).Count();
                Assert.AreEqual(1, count, "Received duplicates and now users are annoyed and burning down the village! Run!");
            }
        }
예제 #7
0
        public async Task DeleteComment_Moderator()
        {
            //Assert.Inconclusive("Complete this test");
            var content   = "This is my data too you know 2";
            var user      = TestHelper.SetPrincipal("TestUser01");
            var cmdcreate = new CreateCommentCommand(1, null, content).SetUserContext(user);
            var c         = cmdcreate.Execute().Result;

            VoatAssert.IsValid(c);

            int id = c.Response.ID;

            //switch to mod of sub
            user = TestHelper.SetPrincipal(USERNAMES.Unit);
            var cmd = new DeleteCommentCommand(id, "This is spam").SetUserContext(user);
            var r   = await cmd.Execute();

            VoatAssert.IsValid(r);

            //verify
            using (var db = new VoatDataContext())
            {
                var comment = db.Comment.FirstOrDefault(x => x.ID == id);
                Assert.AreEqual(true, comment.IsDeleted);

                //Content should remain unchanged in mod deletion
                Assert.AreEqual(comment.Content, content);
                Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(content));
            }
        }
예제 #8
0
        public void CreateComment_DisabledSubverse()
        {
            //insert post via db into disabled sub
            Submission submission = null;

            using (var db = new VoatDataContext())
            {
                submission = new Submission()
                {
                    Subverse     = SUBVERSES.Disabled,
                    Title        = "Super Sneaky",
                    Content      = "How can I post to disabled subs?",
                    UserName     = USERNAMES.Unit,
                    CreationDate = DateTime.UtcNow
                };
                db.Submission.Add(submission);
                db.SaveChanges();
            }

            var user = TestHelper.SetPrincipal("TestUser05");
            var cmd  = new CreateCommentCommand(submission.ID, null, "Are you @FuzzyWords?").SetUserContext(user);
            var c    = cmd.Execute().Result;

            Assert.IsFalse(c.Success, "Disabled subs should not allow comments");
            Assert.AreEqual(Status.Denied, c.Status);
            Assert.AreEqual(c.Message, "Subverse is disabled");
        }
예제 #9
0
        public async Task CreateComment_TestCommentReplyNotification()
        {
            var userName = "******";
            var user     = TestHelper.SetPrincipal(userName);
            var body     = Guid.NewGuid().ToString();
            var cmd      = new CreateCommentCommand(1, 2, body).SetUserContext(user);
            var c        = await cmd.Execute();

            Assert.IsNotNull(c, "response null");
            if (!c.Success)
            {
                if (c.Exception != null)
                {
                    Assert.Fail(c.Exception.ToString());
                }
                else
                {
                    Assert.Fail(c.Message);
                }
            }
            Assert.AreEqual(Status.Success, c.Status);

            //check for comment reply entry
            using (var db = new VoatDataContext())
            {
                var notice = db.Message.FirstOrDefault(x => x.Sender == userName && x.Recipient == USERNAMES.Unit && x.SubmissionID == 1 && x.CommentID == c.Response.ID);
                Assert.IsNotNull(notice, "Did not find a reply notification");
            }
        }
예제 #10
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);
        }
예제 #11
0
        public void CreateComment_WithGloballyBannedUser()
        {
            var user = TestHelper.SetPrincipal("BannedGlobally");

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

            VoatAssert.IsValid(c, Status.Denied, "User should be banned from commenting");
        }
예제 #12
0
        public void CreateComment_Empty()
        {
            TestHelper.SetPrincipal("TestUser12");

            var cmd = new CreateCommentCommand(1, null, "          ");
            var c   = cmd.Execute().Result;

            Assert.IsFalse(c.Success, c.Message);
            Assert.AreEqual("Empty comments not allowed", c.Message);
        }
예제 #13
0
        public void CreateComment_BannedDomain()
        {
            TestHelper.SetPrincipal("TestUser2");

            var cmd = new CreateCommentCommand(1, null, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!");
            var c   = cmd.Execute().Result;

            Assert.IsFalse(c.Success);
            Assert.AreEqual("Comment contains banned domains", c.Message);
        }
예제 #14
0
        public void CreateComment_WithGloballyBannedUser()
        {
            TestHelper.SetPrincipal("BannedGlobally");

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

            Assert.IsFalse(c.Success, "User should be banned from commenting");
            Assert.AreEqual(Status.Denied, c.Status);
        }
예제 #15
0
        public void CreateComment_BannedDomain_NoProtocol()
        {
            var user = TestHelper.SetPrincipal("TestUser02");

            var cmd = new CreateCommentCommand(1, null, "[Check out this killer website](//fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c, Status.Denied);
            Assert.AreEqual("Comment contains banned domains", c.Message);
        }
예제 #16
0
        public void CreateComment_Empty()
        {
            var user = TestHelper.SetPrincipal("TestUser12");

            var cmd = new CreateCommentCommand(1, null, "          ").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c, Status.Denied);
            Assert.AreEqual("Empty comments not allowed", c.Message);
        }
예제 #17
0
            public static Domain.Models.Comment CreateComment(string userName, int submissionID, string content, int?parentCommentID = null)
            {
                var user = TestHelper.SetPrincipal(userName);
                var cmd  = new CreateCommentCommand(submissionID, parentCommentID, content).SetUserContext(user);
                var c    = cmd.Execute().Result;

                VoatAssert.IsValid(c);
                Assert.AreNotEqual(0, c.Response.ID);

                return(c.Response);
            }
예제 #18
0
        public async Task QueryUserComments_Anon()
        {
            var userName = "******";
            var user     = TestHelper.SetPrincipal(userName);
            var cmd      = new CreateCommentCommand(2, null, "You can never know I said this: Bollocks").SetUserContext(user);
            var x        = await cmd.Execute();

            VoatAssert.IsValid(x);

            var q = new QueryUserComments(userName, SearchOptions.Default);
            var r = await q.ExecuteAsync();

            Assert.AreEqual(false, r.Any(w => w.Content == "You can never know I said this: Bollocks"));
        }
예제 #19
0
        public async Task MentionUser_Anon_NoBlock_Test()
        {
            string user1 = "UnitTestUser11";
            string user2 = "UnitTestUser12";

            var user = TestHelper.SetPrincipal(user1);

            //Submission
            var anonSubmission = TestHelper.ContentCreation.CreateSubmission(user1, new Domain.Models.UserSubmission()
            {
                Title = $"I'm harrassing @{user2}!", Content = GetMethodName(true), Subverse = SUBVERSES.Anon
            });

            Assert.IsNotNull(anonSubmission, "Couldn't create test submission");
            Assert.AreNotEqual(0, anonSubmission.ID, "Doesn't appear we have a valid submission id");

            Thread.Sleep(2000);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x =>
                                             x.Sender == user1 &&
                                             x.Recipient == user2 &&
                                             x.SubmissionID == anonSubmission.ID &&
                                             x.IsAnonymized == true &&
                                             x.Type == (int)Domain.Models.MessageType.SubmissionMention
                                             ).Count();
                Assert.AreEqual(1, count, "Where is the harassment submission message!?!?!?");
            }

            //Comment
            string mentionTwiceContent = $"Hello @{user2}, I am mentioning you in an anon thread because I want to make you feel scared";
            var    cmd    = new CreateCommentCommand(anonSubmission.ID, null, mentionTwiceContent).SetUserContext(user);
            var    result = await cmd.Execute();

            VoatAssert.IsValid(result);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x =>
                                             x.Sender == user1 &&
                                             x.Recipient == user2 &&
                                             x.CommentID == result.Response.ID &&
                                             x.IsAnonymized == true &&
                                             x.Type == (int)Domain.Models.MessageType.CommentMention

                                             ).Count();
                Assert.AreEqual(1, count, "Where is the harassment comment message!?!?!?");
            }
        }
예제 #20
0
        public async Task QueryUserComments()
        {
            var userName = "******";
            var user     = TestHelper.SetPrincipal(userName);
            var cmd      = new CreateCommentCommand(1, null, "My pillow looks like jello").SetUserContext(user);
            var x        = await cmd.Execute();

            VoatAssert.IsValid(x);

            var q = new QueryUserComments(userName, SearchOptions.Default).SetUserContext(user);
            var r = await q.ExecuteAsync();

            Assert.AreEqual(true, r.Any(w => w.Content == "My pillow looks like jello"));
        }
예제 #21
0
        public void EditComment_BannedDomain()
        {
            var user = TestHelper.SetPrincipal("TestUser02");

            var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c);

            var editCmd    = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!").SetUserContext(user);
            var editResult = editCmd.Execute().Result;

            VoatAssert.IsValid(editResult, Status.Denied, "Expecting Denied Status");
            Assert.AreEqual("Comment contains banned domains", editResult.Message);
        }
예제 #22
0
        public void EditComment_Empty()
        {
            var user = TestHelper.SetPrincipal("TestUser11");

            var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c);

            var editCmd    = new EditCommentCommand(c.Response.ID, "            ").SetUserContext(user);
            var editResult = editCmd.Execute().Result;

            Assert.IsFalse(editResult.Success, editResult.Message);
            Assert.AreEqual("Empty comments not allowed", editResult.Message);
        }
예제 #23
0
        public async Task TestCommentNotification(string sub, string user1, string user2)
        {
            var id = Guid.NewGuid().ToString();

            //Post submission as TestUser1
            var user = TestHelper.SetPrincipal(user1);
            var cmd  = new CreateSubmissionCommand(new Domain.Models.UserSubmission()
            {
                Subverse = sub, Title = "Let's be creative!", Content = "No"
            }).SetUserContext(user);
            var response = await cmd.Execute();

            VoatAssert.IsValid(response);

            var submission = response.Response;

            Assert.IsNotNull(submission, "Expected a non-null submission response");

            //Reply to comment as TestUser2
            user = TestHelper.SetPrincipal(user2);
            var commentCmd      = new CreateCommentCommand(submission.ID, null, "Important Comment").SetUserContext(user);
            var responseComment = await commentCmd.Execute();

            VoatAssert.IsValid(responseComment);

            var comment = responseComment.Response;

            Assert.IsNotNull(comment, "Expected a non-null comment response");


            //Check to see if Comment notification exists in messages
            using (var db = new VoatDataContext())
            {
                var record = (from x in db.Message
                              where
                              x.Recipient == user1 &&
                              x.Sender == user2 &&
                              x.IsAnonymized == submission.IsAnonymized &&
                              x.IsAnonymized == comment.IsAnonymized &&
                              x.CommentID == comment.ID &&
                              x.SubmissionID == submission.ID &&
                              x.Subverse == submission.Subverse &&
                              x.Type == (int)Domain.Models.MessageType.SubmissionReply
                              // && x.Direction == (int)Domain.Models.MessageDirection.InBound
                              select x).FirstOrDefault();
                Assert.IsNotNull(record, "Can not find message in database");
            }
        }
예제 #24
0
        public void EditComment_WrongOwner()
        {
            var user = TestHelper.SetPrincipal("TestUser15");

            var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user);
            var c   = cmd.Execute().Result;

            VoatAssert.IsValid(c);

            user = TestHelper.SetPrincipal("TestUser12");
            var editCmd    = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!").SetUserContext(user);
            var editResult = editCmd.Execute().Result;

            VoatAssert.IsValid(editResult, Status.Denied);
            Assert.AreEqual("User does not have permissions to perform requested action", editResult.Message);
        }
예제 #25
0
        public void EditComment_WrongOwner()
        {
            TestHelper.SetPrincipal("TestUser15");

            var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.");
            var c   = cmd.Execute().Result;

            Assert.IsTrue(c.Success, c.Message);

            TestHelper.SetPrincipal("TestUser12");
            var editCmd    = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!");
            var editResult = editCmd.Execute().Result;

            Assert.IsFalse(editResult.Success, editResult.Message);
            Assert.AreEqual("User doesn't have permissions to perform requested action", editResult.Message);
        }
예제 #26
0
        public async Task <ActionResult> SubmitComment([Bind(Include = "ID, Content, SubmissionID, ParentID")] Data.Models.Comment commentModel)
        {
            if (!ModelState.IsValid)
            {
                //Model isn't valid, can include throttling
                if (Request.IsAjaxRequest())
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ModelState.GetFirstErrorMessage()));
                }
                else
                {
                    ModelState.AddModelError(String.Empty, "Sorry, you are either banned from this sub or doing that too fast. Please try again in 2 minutes.");
                    return(View("~/Views/Help/SpeedyGonzales.cshtml"));
                }
            }
            else
            {
                var cmd    = new CreateCommentCommand(commentModel.SubmissionID.Value, commentModel.ParentID, commentModel.Content);
                var result = await cmd.Execute();

                if (result.Success)
                {
                    //if good return formatted comment
                    if (Request.IsAjaxRequest())
                    {
                        var comment = result.Response;
                        comment.IsOwner     = true;
                        ViewBag.CommentId   = comment.ID;               //why?
                        ViewBag.rootComment = comment.ParentID == null; //why?
                        return(PartialView("~/Views/Shared/Comments/_SubmissionComment.cshtml", comment));
                    }
                    else if (Request.UrlReferrer != null)
                    {
                        var url = Request.UrlReferrer.AbsolutePath;
                        return(Redirect(url));
                    }
                    else
                    {
                        return(new EmptyResult());
                    }
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message));
                }
            }
        }
예제 #27
0
        public async Task CreateComment_TestSubmissionCommentNotification()
        {
            var userName = "******";
            var user     = TestHelper.SetPrincipal(userName);
            var body     = Guid.NewGuid().ToString();
            var cmd      = new CreateCommentCommand(1, null, body).SetUserContext(user);
            var c        = await cmd.Execute();

            VoatAssert.IsValid(c);

            //check for comment reply entry
            using (var db = new VoatDataContext())
            {
                var notice = db.Message.FirstOrDefault(x => x.Sender == userName && x.Recipient == "anon" && x.SubmissionID == 1);
                Assert.IsNotNull(notice, "Did not find a reply notification");
            }
        }
예제 #28
0
        public void EditComment_BannedDomain()
        {
            TestHelper.SetPrincipal("TestUser2");

            var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.");
            var c   = cmd.Execute().Result;

            Assert.IsTrue(c.Success);

            var editCmd    = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!");
            var editResult = editCmd.Execute().Result;

            Assert.IsFalse(editResult.Success, "Edit command with banned domain returned true");
            Assert.AreEqual(Status.Denied, editResult.Status, "expecting denied status");

            Assert.AreEqual("Comment contains banned domains", editResult.Message);
        }
예제 #29
0
        public void CreateCommentAddMessageAndCallSaveChanges_WhenExecuted()
        {
            // Arrange
            var mockedContext            = new Mock <IMotorSystemContext>();
            var commentInputProviderMock = new Mock <ICommentInputProvider>();
            var factoryMock    = new Mock <IModelFactory>();
            var mockedCache    = new Mock <IMemoryCacheProvider>();
            var mockedDatetime = new Mock <IDateTimeProvider>();

            mockedDatetime.Setup(d => d.GetDate()).Returns(new DateTime(2017, 1, 1));

            commentInputProviderMock.Setup(i => i.CreateCommentInput())
            .Returns(new List <string> {
                "3", "comment content"
            });

            mockedContext.SetupGet(c => c.Comments)
            .Returns((new Mock <IDbSet <Comment> >()).Object);

            var comment = new Comment()
            {
                Id = 3, Content = "some comment"
            };

            factoryMock.Setup(f => f.CreateComment("some comment", mockedDatetime.Object.GetDate(), null, 2));
            var cache = new MemoryCache("test");

            cache["user"] = 5;
            mockedCache.SetupGet(c => c.MemoryCache).Returns(cache);

            mockedContext.Setup(c => c.Users.Find(It.IsAny <int>()))
            .Returns(new User());



            var createCommentCommand = new CreateCommentCommand(mockedContext.Object,
                                                                factoryMock.Object, commentInputProviderMock.Object, mockedCache.Object,
                                                                mockedDatetime.Object);
            // Act
            string result = createCommentCommand.Execute();

            // Assert
            //mockedContext.Verify(c => c.Comments.Add(comment), Times.Once);
            mockedContext.Verify(c => c.SaveChanges(), Times.Once);
        }
예제 #30
0
        public async Task MentionUser_Comment_Test()
        {
            string user1 = "UnitTestUser07";
            string user2 = "UnitTestUser08";

            var    user = TestHelper.SetPrincipal(user1);
            string mentionTwiceContent = $"PSA: @{user2} is a shill. I saw him getting ready for work and his socks were standard shill issue.";
            var    cmd    = new CreateCommentCommand(submission.ID, null, mentionTwiceContent).SetUserContext(user);
            var    result = await cmd.Execute();

            VoatAssert.IsValid(result);

            using (var db = new VoatDataContext())
            {
                var count = db.Message.Where(x => x.Sender == user1 && x.Recipient == user2 && x.CommentID == result.Response.ID).Count();
                Assert.AreEqual(1, count, "Expected to receive shill mention! THIS IS CENSORSHIP!");
            }
        }