public void UpvoteSubmission() { TestHelper.SetPrincipal("User50CCP"); bool voteEventReceived = false; EventNotification.Instance.OnVoteReceived += (s, e) => { voteEventReceived = e.TargetUserName == "anon" && e.SendingUserName == "User50CCP" && e.ChangeValue == 1 && e.ReferenceType == Domain.Models.ContentType.Submission && e.ReferenceID == 1; }; var cmd = new SubmissionVoteCommand(1, 1, IpHash.CreateHash("127.0.0.2")); var c = cmd.Execute().Result; Assert.IsNotNull(c, "Response is null"); Assert.IsTrue(c.Success, c.Message); Assert.IsNotNull(c.Response); //verify in db using (var db = new Voat.Data.Repository()) { var comment = db.GetSubmission(1); Assert.IsNotNull(comment, "Couldn't find submission in db"); Assert.AreEqual(comment.UpCount, c.Response.UpCount); Assert.AreEqual(comment.DownCount, c.Response.DownCount); } Assert.IsTrue(voteEventReceived, "VoteEvent not have the expected values"); }
public async Task <JsonResult> Vote(int submissionID, int typeOfVote) { var cmd = new SubmissionVoteCommand(submissionID, typeOfVote, IpHash.CreateHash(UserHelper.UserIpAddress(this.Request))); var result = await cmd.Execute(); return(Json(result)); }
public void InvalidVoteValue_Submission_High() { TestHelper.SetPrincipal("unit"); var cmd = new SubmissionVoteCommand(1, 2, IpHash.CreateHash("127.0.0.1")); var c = cmd.Execute().Result; }
public void DownvoteSubmission_MinCCP() { var user = TestHelper.SetPrincipal(USERNAMES.User0CCP); var cmd = new SubmissionVoteCommand(3, -1, IpHash.CreateHash("127.0.0.1")).SetUserContext(user); //SubmissionID: 3 is in MinCCP sub var c = cmd.Execute().Result; Assert.IsFalse(c.Success); Assert.IsNull(c.Response); }
public void InvalidVoteValue_Submission_High() { VoatAssert.Throws<ArgumentOutOfRangeException>(() => { var user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new SubmissionVoteCommand(1, 2, IpHash.CreateHash("127.0.0.1")).SetUserContext(user); var c = cmd.Execute().Result; }); }
public void Bug_Trap_Spam_Votes_VoteCommand() { int submissionID = 1; Submission beforesubmission = GetSubmission(); int exCount = 0; Func <Task <VoteResponse> > vote1 = new Func <Task <VoteResponse> >(async() => { var principle = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(USERNAMES.User500CCP, "Bearer"), null); System.Threading.Thread.CurrentPrincipal = principle; var cmd = new SubmissionVoteCommand(submissionID, 1, IpHash.CreateHash("127.0.0.1")); Interlocked.Increment(ref exCount); return(await cmd.Execute());//.Result; }); Func <Task <VoteResponse> > vote2 = new Func <Task <VoteResponse> >(async() => { var principle = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(USERNAMES.User100CCP, "Bearer"), null); System.Threading.Thread.CurrentPrincipal = principle; var cmd = new SubmissionVoteCommand(submissionID, 1, IpHash.CreateHash("127.0.0.1")); Interlocked.Increment(ref exCount); return(await cmd.Execute());//.Result; }); //exCount = -2; //var x = vote1().Result; //var y = vote2().Result; var tasks = new List <Task <VoteResponse> >(); for (int i = 0; i < count; i++) { if (i % 2 == 0) { tasks.Add(Task.Run(vote1)); } else { tasks.Add(Task.Run(vote2)); } } Task.WaitAll(tasks.ToArray()); Submission aftersubmission = GetSubmission(); Assert.AreEqual(count, exCount, "Execution count is off"); AssertData(beforesubmission, aftersubmission); }
public void UpvoteSubmission_DeniesSameIP() { var user = TestHelper.SetPrincipal("UnitTestUser45"); var cmd = new SubmissionVoteCommand(1, 1, IpHash.CreateHash("1.1.1.1")).SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); user = TestHelper.SetPrincipal("UnitTestUser46"); cmd = new SubmissionVoteCommand(1, 1, IpHash.CreateHash("1.1.1.1")).SetUserContext(user); c = cmd.Execute().Result; Assert.IsNotNull(c, "Response is null"); Assert.IsFalse(c.Success, c.Message); Assert.IsNull(c.Response); }
public void DownvoteSubmission() { var submissionUser = "******"; var newSubmission = TestHelper.ContentCreation.CreateSubmission(submissionUser, new Domain.Models.UserSubmission() { Title = "This is what I think about you guys", Subverse = SUBVERSES.Unit }); var userName = USERNAMES.User500CCP; var user = TestHelper.SetPrincipal(userName); bool voteEventReceived = false; EventNotification.Instance.OnVoteReceived += (s, e) => { voteEventReceived = e.TargetUserName == submissionUser && e.SendingUserName == userName && e.ChangeValue == -1 && e.ReferenceType == Domain.Models.ContentType.Submission && e.ReferenceID == newSubmission.ID; }; var cmd = new SubmissionVoteCommand(newSubmission.ID, -1, IpHash.CreateHash("127.0.0.100")).SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); //verify in db using (var db = new Voat.Data.Repository(user)) { var submissionFromRepo = db.GetSubmission(newSubmission.ID); Assert.IsNotNull(submissionFromRepo, "Couldn't find comment in db"); Assert.AreEqual(submissionFromRepo.UpCount, c.Response.UpCount); Assert.AreEqual(submissionFromRepo.DownCount, c.Response.DownCount); } Assert.IsTrue(voteEventReceived, "VoteEvent not have the expected values"); //Verify Submission pull has correct vote value recorded in output for current user var q = new QuerySubmission(newSubmission.ID, true).SetUserContext(user); var submission = q.Execute(); Assert.IsNotNull(submission); Assert.AreEqual(c.RecordedValue, submission.Vote); //Verify non-logged in user has correct vote value TestHelper.SetPrincipal(null); q = new QuerySubmission(1, true); submission = q.Execute(); Assert.IsNotNull(submission); Assert.AreEqual(null, submission.Vote); }
public void Bug_Trap_Spam_Votes_VoteCommand_2() { int submissionID = 1; Submission beforesubmission = GetSubmission(); int exCount = 0; Func <Task <VoteResponse> > vote1 = new Func <Task <VoteResponse> >(async() => { var user = TestHelper.SetPrincipal(USERNAMES.User500CCP); var cmd = new SubmissionVoteCommand(submissionID, 1, IpHash.CreateHash("127.0.0.1")).SetUserContext(user); Interlocked.Increment(ref exCount); return(await cmd.Execute());//.Result; }); Func <Task <VoteResponse> > vote2 = new Func <Task <VoteResponse> >(async() => { var user = TestHelper.SetPrincipal(USERNAMES.User100CCP); var cmd = new SubmissionVoteCommand(submissionID, 1, IpHash.CreateHash("127.0.0.1")).SetUserContext(user);; Interlocked.Increment(ref exCount); return(await cmd.Execute());//.Result; }); var tasks = new List <Task <VoteResponse> >(); for (int i = 0; i < count; i++) { if (i % 2 == 0) { tasks.Add(Task.Run(vote1)); } else { tasks.Add(Task.Run(vote2)); } } Task.WaitAll(tasks.ToArray()); Submission aftersubmission = GetSubmission(); Assert.AreEqual(count, exCount, "Execution count is off"); AssertData(beforesubmission, aftersubmission); }
public async Task <JsonResult> Vote(Domain.Models.ContentType contentType, int id, int voteStatus) { VoteResponse result = null; switch (contentType) { case Domain.Models.ContentType.Submission: var cmdV = new SubmissionVoteCommand(id, voteStatus, IpHash.CreateHash(Request.RemoteAddress())).SetUserContext(User); result = await cmdV.Execute(); break; case Domain.Models.ContentType.Comment: var cmdC = new CommentVoteCommand(id, voteStatus, IpHash.CreateHash(Request.RemoteAddress())).SetUserContext(User); result = await cmdC.Execute(); break; } return(Json(result)); }
public async Task Bug_Trap_Positive_ContributionPoints_Removed() { //Test that when a user deletes comments and submissions with positive points, that the points are reset var altList = new[] { "UnitTestUser10", "UnitTestUser11", "UnitTestUser12", "UnitTestUser13", "UnitTestUser14", "UnitTestUser15" }; var primaryUser = "******"; var currentUser = TestHelper.SetPrincipal(primaryUser); var cmdSubmission = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Title = "Test Positive SCP Removed upon Delete", Content = "Does this get removed?", Subverse = "unit" }).SetUserContext(currentUser); var subResponse = await cmdSubmission.Execute(); VoatAssert.IsValid(subResponse); var submissionID = subResponse.Response.ID; var cmdComment = new CreateCommentCommand(submissionID, null, "This is my manipulation comment. Upvote. Go.").SetUserContext(currentUser); var commentResponse = await cmdComment.Execute(); VoatAssert.IsValid(commentResponse); var commentID = commentResponse.Response.ID; var vote = new Func <int, Domain.Models.ContentType, string[], Task>(async(id, contentType, users) => { foreach (string user in users) { var userIdentity = TestHelper.SetPrincipal(user); switch (contentType) { case Domain.Models.ContentType.Comment: var c = new CommentVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var cr = await c.Execute(); VoatAssert.IsValid(cr); break; case Domain.Models.ContentType.Submission: var s = new SubmissionVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var sr = await s.Execute(); VoatAssert.IsValid(sr); break; } } }); await vote(commentID, Domain.Models.ContentType.Comment, altList); var deleteComment = new DeleteCommentCommand(commentID).SetUserContext(currentUser); var deleteCommentResponse = await deleteComment.Execute(); VoatAssert.IsValid(deleteCommentResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.CommentVoteTracker.Where(x => x.CommentID == commentID); Assert.AreEqual(altList.Length, votes.Count()); var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found comment votes with a non-zero vote value"); } await vote(submissionID, Domain.Models.ContentType.Submission, altList); var deleteSubmission = new DeleteSubmissionCommand(submissionID).SetUserContext(currentUser); var deleteSubmissionResponse = await deleteSubmission.Execute(); VoatAssert.IsValid(deleteSubmissionResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.SubmissionVoteTracker.Where(x => x.SubmissionID == submissionID); Assert.AreEqual(altList.Length + 1, votes.Count()); //author has a vote var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found submission votes with a non-zero vote value"); } }
protected virtual void Seed(VoatDataContext context) { //******************************************************************************************************* //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ /* * * * DO NOT EDIT EXISTING SEED CODE, ALWAYS APPEND TO IT. * * EXISTING DATA BASED UNIT TESTS ARE BUILT UPON WHAT IS SPECIFIED HERE AND IF CHANGED WILL FAIL * * UPON SECOND THOUGHT THIS SOUNDS WRONG BUT THIS ALSO SOUNDS LIKE A FUTURE PERSON PROBLEM * */ //******************************************************************************************************* //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #region Subverses //ID:1 (Standard Subverse) var unitSubverse = context.Subverse.Add(new Subverse() { Name = SUBVERSES.Unit, Title = "v/unit", Description = "Unit test Subverse", SideBar = "For Unit Testing", //Type = "link", IsAnonymized = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:2 (Anon Subverse) var anonSubverse = context.Subverse.Add(new Subverse() { Name = SUBVERSES.Anon, Title = "v/anon", Description = "Anonymous Subverse", SideBar = "For Anonymous Testing", // Type = "link", IsAnonymized = true, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:4 (Min Subverse) var minCCPSubverse = context.Subverse.Add(new Subverse() { Name = SUBVERSES.MinCCP, Title = "v/minCCP", Description = "Min CCP for Testing", SideBar = "Min CCP for Testing", //Type = "link", IsAnonymized = false, MinCCPForDownvote = 5000, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:5 (Private Subverse) var privateSubverse = context.Subverse.Add(new Subverse() { Name = SUBVERSES.Private, Title = "v/private", Description = "Private for Testing", SideBar = "Private for Testing", //Type = "link", IsAnonymized = false, IsAuthorizedOnly = false, IsPrivate = true, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:6 (AskVoat Subverse) var askSubverse = context.Subverse.Add(new Subverse() { Name = SUBVERSES.AskVoat, Title = "v/AskVoat", Description = "Ask Voat.", SideBar = "Ask Me", //Type = "link", IsAnonymized = false, IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:7 (whatever Subverse) var whatever = context.Subverse.Add(new Subverse() { Name = SUBVERSES.Whatever, Title = "v/whatever", Description = "What Ever", SideBar = "What Ever goes here", // Type = "link", IsAnonymized = false, IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:8 (news Subverse) var news = context.Subverse.Add(new Subverse() { Name = SUBVERSES.News, Title = "v/news", Description = "News", SideBar = "News", //Type = "link", IsAnonymized = false, IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:9 (AuthorizedOnly Subverse) var authOnly = context.Subverse.Add(new Subverse() { Name = SUBVERSES.AuthorizedOnly, Title = "v/AuthorizedOnly", Description = "Authorized Only", SideBar = "Authorized Only", //Type = "link", IsAnonymized = false, IsAuthorizedOnly = true, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:10 (nsfw Subverse) var nsfwOnly = context.Subverse.Add(new Subverse() { Name = SUBVERSES.NSFW, Title = "v/NSFW", Description = "NSFW Only", SideBar = "NSFW Only", //Type = "link", IsAdult = true, IsAnonymized = false, IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; //ID:11 (allowAnon Subverse) var allowAnon = context.Subverse.Add(new Subverse() { Name = SUBVERSES.AllowAnon, Title = "v/AllowAnon", Description = "AllowAnon", SideBar = "AllowAnon", //Type = "link", IsAdult = false, IsAnonymized = null, //allows users to submit anon/non-anon content IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, }).Entity; var arst = context.Subverse.Add(new Subverse() { Name = "arst", Title = "v/arst", Description = "Colemak short hand sub arst", SideBar = "For those who are properly fingering: arst", //Type = "link", IsAdult = false, IsAnonymized = null, //allows users to submit anon/non-anon content IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, CreatedBy = "SurelyPutts" }).Entity; var asdf = context.Subverse.Add(new Subverse() { Name = "asdf", Title = "v/asdf", Description = "Qwerty short hand sub asdf", SideBar = "For those who are improperly fingering: asdf", //Type = "link", IsAdult = false, IsAnonymized = null, //allows users to submit anon/non-anon content IsAuthorizedOnly = false, IsPrivate = false, CreationDate = DateTime.UtcNow.AddDays(-7), IsAdminDisabled = false, CreatedBy = "NotPutts" }).Entity; context.SaveChanges(); context.SubverseModerator.Add(new SubverseModerator() { Subverse = SUBVERSES.AuthorizedOnly, CreatedBy = USERNAMES.Unit, CreationDate = DateTime.UtcNow, Power = 1, UserName = USERNAMES.Unit }); context.SubverseModerator.Add(new SubverseModerator() { Subverse = SUBVERSES.Unit, CreatedBy = null, CreationDate = null, Power = 1, UserName = USERNAMES.Unit }); context.SubverseModerator.Add(new SubverseModerator() { Subverse = SUBVERSES.Anon, CreatedBy = null, CreationDate = null, Power = 1, UserName = USERNAMES.Anon }); context.SaveChanges(); #endregion Subverses #region Submissions Comment c; //ID:1 var unitSubmission = context.Submission.Add(new Submission() { CreationDate = DateTime.UtcNow.AddHours(-12), Subverse = SUBVERSES.Unit, Title = "Favorite YouTube Video", Url = "https://www.youtube.com/watch?v=pnbJEg9r1o8", Type = 2, UserName = USERNAMES.Anon }).Entity; context.SaveChanges(); //ID: 1 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Unit, Content = "This is a comment", CreationDate = DateTime.UtcNow, SubmissionID = unitSubmission.ID, ParentID = null }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); //ID: 2 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Unit, Content = "This is a comment", CreationDate = DateTime.UtcNow, SubmissionID = unitSubmission.ID, ParentID = c.ID }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); //ID:2 (Anon Subverse submission) var anonSubmission = context.Submission.Add(new Submission() { CreationDate = DateTime.UtcNow.AddHours(-36), Content = "Hello @tester, it's sure nice to be at /v/anon. No one knows me.", Subverse = anonSubverse.Name, Title = "First Anon Post", Type = 1, UserName = USERNAMES.Anon, IsAnonymized = true }).Entity; context.SaveChanges(); //ID: 3 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Anon, Content = "You can't see my name with the data repository", CreationDate = DateTime.UtcNow, SubmissionID = anonSubmission.ID, IsAnonymized = true, ParentID = null }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); //ID: 4 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Unit, Content = "You can't see my name with the data repository, right?", CreationDate = DateTime.UtcNow, SubmissionID = anonSubmission.ID, IsAnonymized = true, ParentID = null }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); //ID:3 (MinCCP Subverse submission) var minCCPSubmission = context.Submission.Add(new Submission() { CreationDate = DateTime.UtcNow, Content = "Hello @tester, it's sure nice to be at /v/minCCP.", Subverse = minCCPSubverse.Name, Title = "First MinCCP Post", Type = 1, UserName = USERNAMES.Anon, IsAnonymized = false }).Entity; context.SaveChanges(); //ID: 5 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Anon, Content = "This is a comment in v/MinCCP Sub from user anon", CreationDate = DateTime.UtcNow, SubmissionID = minCCPSubmission.ID, ParentID = null }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); //ID: 6 c = context.Comment.Add(new Comment() { UserName = USERNAMES.Unit, Content = "This is a comment in v/MinCCP Sub from user unit", CreationDate = DateTime.UtcNow.AddHours(-4), SubmissionID = minCCPSubmission.ID, ParentID = null }).Entity; context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); #endregion Submissions #region UserPrefernces context.UserPreference.Add(new UserPreference() { UserName = USERNAMES.Unit, DisableCSS = false, NightMode = true, Language = "en", //OpenInNewWindow = true, EnableAdultContent = false, DisplayVotes = true, DisplaySubscriptions = false, UseSubscriptionsMenu = true, Bio = "User unit's short bio", Avatar = "somepath_i_think.jpg" }); context.SaveChanges(); //c = context.Comments.Add(new Comment() //{ // UserName = "******", // Content = String.Format("Test Comment w/Upvotes"), // CreationDate = DateTime.UtcNow, // ID = unitSubmission.ID, // UpCount = 101, // ParentID = null //}); context.SaveChanges(); Debug.WriteLine("Comment ID: {0}", c.ID); #endregion UserPrefernces #region Create Test Users //default users CreateUser(USERNAMES.Unit); CreateUser(USERNAMES.Anon); //these blocks are used for testing individual operations CreateUserBatch(CONSTANTS.UNIT_TEST_USER_TEMPLATE, 0, 50); CreateUserBatch(CONSTANTS.TEST_USER_TEMPLATE, 0, 50); //Users with varying levels of CCP CreateUser(USERNAMES.User0CCP); CreateUser(USERNAMES.User50CCP); CreateUser(USERNAMES.User100CCP, DateTime.UtcNow.AddDays(-45)); CreateUser(USERNAMES.User500CCP, DateTime.UtcNow.AddDays(-60)); var s = context.Submission.Add(new Submission() { UserName = USERNAMES.User500CCP, Title = "Test Submission", Type = 1, Subverse = SUBVERSES.Unit, Content = String.Format("Test Submission w/Upvotes 50"), CreationDate = DateTime.UtcNow, //SubmissionID = unitSubmission.ID, UpCount = 500, }).Entity; context.SaveChanges(); VoteContent(context, Domain.Models.ContentType.Submission, s.ID, 500, Domain.Models.VoteValue.Up); c = context.Comment.Add(new Comment() { UserName = USERNAMES.User50CCP, Content = String.Format("Test Comment w/Upvotes 50"), CreationDate = DateTime.UtcNow, SubmissionID = unitSubmission.ID, UpCount = 50, ParentID = null }).Entity; context.SaveChanges(); VoteContent(context, Domain.Models.ContentType.Comment, c.ID, 50, Domain.Models.VoteValue.Up); c = context.Comment.Add(new Comment() { UserName = USERNAMES.User100CCP, Content = String.Format("Test Comment w/Upvotes 100"), CreationDate = DateTime.UtcNow, SubmissionID = unitSubmission.ID, UpCount = 100, ParentID = null }).Entity; context.SaveChanges(); VoteContent(context, Domain.Models.ContentType.Comment, c.ID, 100, Domain.Models.VoteValue.Up); c = context.Comment.Add(new Comment() { UserName = USERNAMES.User500CCP, Content = String.Format("Test Comment w/Upvotes 500"), CreationDate = DateTime.UtcNow, SubmissionID = unitSubmission.ID, UpCount = 500, ParentID = null }).Entity; context.SaveChanges(); VoteContent(context, Domain.Models.ContentType.Comment, c.ID, 500, Domain.Models.VoteValue.Up); #endregion Create Test Users #region Banned Test Data CreateUser("BannedFromVUnit"); CreateUser("BannedGlobally"); context.BannedUser.Add(new BannedUser() { CreatedBy = USERNAMES.Unit, CreationDate = DateTime.UtcNow.AddDays(-30), Reason = "Unit Testing Global Ban", UserName = "******" }); context.SubverseBan.Add(new SubverseBan() { Subverse = SUBVERSES.Unit, CreatedBy = USERNAMES.Unit, CreationDate = DateTime.UtcNow.AddDays(-30), Reason = "Unit Testing v/Unit Ban", UserName = "******" }); context.BannedDomain.Add(new BannedDomain() { CreatedBy = USERNAMES.Unit, CreationDate = DateTime.UtcNow.AddDays(-15), Domain = "fleddit.com", Reason = "Turned Digg migrants into jelly fish" }); context.SaveChanges(); #endregion BannedUsers Test Data #region Disabled Test Data context.Subverse.Add(new Subverse() { Name = SUBVERSES.Disabled, Title = "Disabled", IsAdminDisabled = true, CreatedBy = USERNAMES.Unit, CreationDate = DateTime.UtcNow.AddDays(-100), SideBar = "We will never be disabled" }); context.SaveChanges(); #endregion BannedUsers Test Data #region AddDefaultSubs context.DefaultSubverse.Add(new DefaultSubverse() { Subverse = SUBVERSES.AskVoat, Order = 1 }); context.DefaultSubverse.Add(new DefaultSubverse() { Subverse = SUBVERSES.Whatever, Order = 2 }); context.DefaultSubverse.Add(new DefaultSubverse() { Subverse = SUBVERSES.News, Order = 3 }); context.SaveChanges(); #endregion AddDefaultSubs #region User500CCP Comment UpVotes //This user needs some upvotes in order to downvoat without triggering the mean rules for (int i = 0; i < 5; i++) { var user = TestHelper.SetPrincipal(USERNAMES.User500CCP); var submission = TestHelper.ContentCreation.CreateSubmission(TestHelper.NextUserName(), new Domain.Models.UserSubmission() { Title = $"This is an UpVote Farm Thread! ({i})", Content = "This Submission and all comments will be upvoted by User500CCP. Get in here!", Subverse = SUBVERSES.Whatever }); var scmd = new SubmissionVoteCommand(submission.ID, 1, Guid.NewGuid().ToString()).SetUserContext(user); var sr = scmd.Execute().Result; VoatAssert.IsValid(sr); var comment = TestHelper.ContentCreation.CreateComment(TestHelper.NextUserName(), submission.ID, "Please UpVote Me!"); user = TestHelper.SetPrincipal(USERNAMES.User500CCP); var cmd = new CommentVoteCommand(comment.ID, 1, Guid.NewGuid().ToString()).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); } CacheHandler.Instance.Remove(CachingKey.UserInformation(USERNAMES.User500CCP)); #endregion //****************************************************************************************************************** // ADD YOUR STUFF BELOW - DO NOT EDIT THE ABOVE CODE - NOT EVEN ONCE - I'LL SO FIGHT YOU IF YOU DO AND I FIGHT DIRTY //****************************************************************************************************************** }
private async Task VerifyVoteStatus(string userToPost, string subverse, Domain.Models.ContentType contentType, int voteStatus, int voteValue) { int id = 0; string userName = ""; //Create submission var user = TestHelper.SetPrincipal(userToPost); var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Subverse = subverse, Title = "VerifyVoteStatus Test Submission in " + subverse }).SetUserContext(user); var response = cmd.Execute().Result; VoatAssert.IsValid(response, Status.Success); //Assert.AreEqual(Status.Success, response.Status, response.Message); var submission = response.Response; //voting username userName = USERNAMES.User100CCP; if (contentType == Domain.Models.ContentType.Submission) { id = submission.ID; user = TestHelper.SetPrincipal(userName); var voteSubmissionCommand = new SubmissionVoteCommand(id, voteStatus, Guid.NewGuid().ToString()).SetUserContext(user); var voteSubmissionResponse = await voteSubmissionCommand.Execute(); VoatAssert.IsValid(voteSubmissionResponse); Assert.IsNotNull(voteSubmissionResponse, "Expecting non-null submission vote command"); //verify in db using (var db = new VoatDataContext()) { var record = db.SubmissionVoteTracker.Where(x => x.SubmissionID == id && x.UserName == userName).FirstOrDefault(); Assert.IsNotNull(record, "Did not find Vote Record in database"); Assert.AreEqual(voteStatus, record.VoteStatus); Assert.AreEqual(voteValue, record.VoteValue); } } else if (contentType == Domain.Models.ContentType.Comment) { //Create comment var cmdComment = new CreateCommentCommand(submission.ID, null, $"VerifyVoteStatus Test Submission in {subverse} - {Guid.NewGuid().ToString()}").SetUserContext(user); var responseComment = await cmdComment.Execute(); VoatAssert.IsValid(responseComment); id = responseComment.Response.ID; user = TestHelper.SetPrincipal(userName); var voteCommentCommand = new CommentVoteCommand(id, voteStatus, Guid.NewGuid().ToString()).SetUserContext(user); var voteCommentResponse = await voteCommentCommand.Execute(); Assert.IsNotNull(voteCommentResponse, "Expecting non-null submission vote command"); //verify in db using (var db = new VoatDataContext()) { var record = db.CommentVoteTracker.Where(x => x.CommentID == id && x.UserName == userName).FirstOrDefault(); Assert.IsNotNull(record, "Did not find Vote Record in database"); Assert.AreEqual(voteStatus, record.VoteStatus); Assert.AreEqual(voteValue, record.VoteValue); } } }