public void TestNegativeSCPSubmission() { var userName = "******"; //Create user TestDataInitializer.CreateUser(userName, DateTime.UtcNow.AddDays(-450)); //Add submission with negatives directly to db using (var context = new VoatDataContext()) { var s = context.Submission.Add(new Submission() { CreationDate = DateTime.UtcNow.AddHours(-12), Subverse = SUBVERSES.Unit, Title = "Test Negative SCP", Url = "https://www.youtube.com/watch?v=pnbJEg9r1o8", Type = 2, UpCount = 2, DownCount = 13, UserName = userName }); context.SaveChanges(); } var user = TestHelper.SetPrincipal(userName); var userSubmission = new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Le Censorship!", Content = "Will this work?" }; var cmd = new CreateSubmissionCommand(userSubmission).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); }
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)); }
public void TestLogin() { var userName = "******"; TestDataInitializer.CreateUser("TestLoginUser"); using (var m = VoatUserManager.Create()) { var r = m.Find(userName, userName); Assert.IsNotNull(r, "Did not find user"); r = m.Find(userName, userName.ToUpper()); Assert.IsNull(r, "Incorrect password works"); } }
public async Task DeleteAccount_Failures() { var userName = "******"; TestDataInitializer.CreateUser(userName); var user = TestHelper.SetPrincipal(userName); //username doesnt match var cmd = new DeleteAccountCommand( new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = "******" }); var result = await cmd.Execute(); Assert.IsFalse(result.Success, result.Message); //password doesn't match cmd = new DeleteAccountCommand( new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = userName, CurrentPassword = "******" }); result = await cmd.Execute(); Assert.IsFalse(result.Success, result.Message); //wrong user user = TestHelper.SetPrincipal("TestUser01"); cmd = new DeleteAccountCommand( new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = userName, CurrentPassword = userName }); result = await cmd.Execute(); Assert.IsFalse(result.Success, result.Message); }
public async Task UserSaves() { var userName = "******"; //var userName = "******" + Guid.NewGuid().ToString().Substring(0, 5); TestDataInitializer.CreateUser(userName); var bio = Guid.NewGuid().ToString(); var user = TestHelper.SetPrincipal(userName); //save start test data using (var repo = new Voat.Data.Repository(user)) { var r = await repo.Save(Domain.Models.ContentType.Submission, 1); VoatAssert.IsValid(r); var submissionSaves = await repo.GetUserSavedItems(Domain.Models.ContentType.Submission, user.Identity.Name); Assert.AreEqual(1, submissionSaves.Count()); Assert.IsTrue(submissionSaves.Any(x => x == 1), "Submission not saved"); r = await repo.Save(Domain.Models.ContentType.Comment, 1); VoatAssert.IsValid(r); var commentSaves = await repo.GetUserSavedItems(Domain.Models.ContentType.Comment, user.Identity.Name); Assert.AreEqual(1, commentSaves.Count()); Assert.IsTrue(commentSaves.Any(x => x == 1), "Comment not saved"); } var q = new QueryUserSaves(Domain.Models.ContentType.Submission).SetUserContext(user); var d = await q.ExecuteAsync(); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Submission, userName))); q = new QueryUserSaves(Domain.Models.ContentType.Comment).SetUserContext(user); d = await q.ExecuteAsync(); Assert.AreEqual(1, d.Count); Assert.AreEqual(true, d.Contains(1)); Assert.AreEqual(true, CacheHandler.Instance.Exists(CachingKey.UserSavedItems(Domain.Models.ContentType.Comment, userName))); //check helper object Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 1)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 2)); var cmd = new SaveCommand(Domain.Models.ContentType.Submission, 2).SetUserContext(user); var response = await cmd.Execute(); VoatAssert.IsValid(response); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 2).SetUserContext(user); response = await cmd.Execute(); VoatAssert.IsValid(response); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 2)); Assert.AreEqual(true, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 2)); cmd = new SaveCommand(Domain.Models.ContentType.Submission, 1).SetUserContext(user);; response = await cmd.Execute(); VoatAssert.IsValid(response); cmd = new SaveCommand(Domain.Models.ContentType.Comment, 1).SetUserContext(user); response = await cmd.Execute(); VoatAssert.IsValid(response); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Submission, 1)); Assert.AreEqual(false, UserHelper.IsSaved(user, Domain.Models.ContentType.Comment, 1)); }
public async Task DeleteAccount_Basic() { //EnsureBadges using (var db = new VoatDataContext()) { if (!db.Badge.Any(x => x.ID == "deleted")) { db.Badge.Add(new Badge() { ID = "deleted", Name = "Account Deleted", Graphic = "deleted.png", Title = "deleted" }); } if (!db.Badge.Any(x => x.ID == "deleted2")) { db.Badge.Add(new Badge() { ID = "deleted2", Name = "Account Deleted", Graphic = "deleted2.png", Title = "deleted" }); } if (!db.Badge.Any(x => x.ID == "donor_upto_30")) { db.Badge.Add(new Badge() { ID = "donor_upto_30", Name = "Donor Up To Thirty", Graphic = "donor30.png", Title = "Donor" }); } db.SaveChanges(); } var userName = "******"; TestDataInitializer.CreateUser(userName); var user = TestHelper.SetPrincipal(userName); DeleteAccountCommand cmd; CommandResponse result; var options = new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = userName, CurrentPassword = userName, Comments = Domain.Models.DeleteOption.Anonymize, LinkSubmissions = Domain.Models.DeleteOption.Anonymize, TextSubmissions = Domain.Models.DeleteOption.Anonymize }; var submission = TestHelper.ContentCreation.CreateSubmission(options.UserName, new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Test Submission Yeah", Content = "Test Submission Content" }); var comment = TestHelper.ContentCreation.CreateComment(options.UserName, submission.ID, "This is a test comment"); //Anon it all cmd = new DeleteAccountCommand(options).SetUserContext(user); result = await cmd.Execute(); VoatAssert.IsValid(result); VerifyDelete(options); userName = "******"; TestDataInitializer.CreateUser(userName); user = TestHelper.SetPrincipal(userName); using (var db = new VoatDataContext()) { //Trying to trap a bug with a user not getting delete badge db.UserBadge.Add(new Voat.Data.Models.UserBadge() { BadgeID = "donor_upto_30", CreationDate = DateTime.UtcNow, UserName = userName }); db.SaveChanges(); } options = new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = userName, CurrentPassword = userName, Comments = Domain.Models.DeleteOption.Delete, LinkSubmissions = Domain.Models.DeleteOption.Delete, TextSubmissions = Domain.Models.DeleteOption.Delete }; submission = TestHelper.ContentCreation.CreateSubmission(options.UserName, new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Test Submission Yeah", Content = "Test Submission Content" }); comment = TestHelper.ContentCreation.CreateComment(options.UserName, submission.ID, "This is a test comment"); //Delete cmd = new DeleteAccountCommand(options).SetUserContext(user); result = await cmd.Execute(); VoatAssert.IsValid(result); VerifyDelete(options); userName = "******"; TestDataInitializer.CreateUser(userName); user = TestHelper.SetPrincipal(userName); //Need to ensure delete clears preferences var prefUpdate = new UpdateUserPreferencesCommand(new Domain.Models.UserPreferenceUpdate() { Bio = "My Bio" }).SetUserContext(user); var p = await prefUpdate.Execute(); VoatAssert.IsValid(p); using (var db = new VoatDataContext()) { var prefs = db.UserPreference.FirstOrDefault(x => x.UserName == userName); Assert.IsNotNull(prefs, "Expected user to have preference record at this stage"); prefs.Avatar = userName + ".jpg"; //Add badges to prevent duplicates db.UserBadge.Add(new Voat.Data.Models.UserBadge() { BadgeID = "deleted", CreationDate = DateTime.UtcNow, UserName = userName }); db.UserBadge.Add(new Voat.Data.Models.UserBadge() { BadgeID = "deleted2", CreationDate = DateTime.UtcNow, UserName = userName }); db.SaveChanges(); } options = new Domain.Models.DeleteAccountOptions() { UserName = userName, ConfirmUserName = userName, CurrentPassword = userName, Comments = Domain.Models.DeleteOption.Delete, LinkSubmissions = Domain.Models.DeleteOption.Delete, TextSubmissions = Domain.Models.DeleteOption.Delete, RecoveryEmailAddress = "*****@*****.**", ConfirmRecoveryEmailAddress = "*****@*****.**", Reason = "I need a break from the racialists" }; submission = TestHelper.ContentCreation.CreateSubmission(options.UserName, new Domain.Models.UserSubmission() { Subverse = SUBVERSES.Unit, Title = "Test Submission Yeah", Content = "Test Submission Content" }); comment = TestHelper.ContentCreation.CreateComment(options.UserName, submission.ID, "This is a test comment"); //Delete cmd = new DeleteAccountCommand(options).SetUserContext(user); result = await cmd.Execute(); VoatAssert.IsValid(result); VerifyDelete(options); }
public async Task Block_Lifecycle_Tests() { var userName = "******"; var subName = SUBVERSES.Unit; TestDataInitializer.CreateUser(userName); var user = TestHelper.SetPrincipal(userName); //Verify No Front / Blocked Sets var userBlockQuery = new QueryUserBlocks(userName).SetUserContext(user); var userBlockResults = await userBlockQuery.ExecuteAsync(); Assert.IsNotNull(userBlockResults, "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, userBlockResults.Count(), "He is supposed to be Turkish. Some say his father was German. Nobody believed he was real."); var userSetQuery = new QueryUserSets(userName).SetUserContext(user); 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 blockCmd = new BlockCommand(domainReference.Type, domainReference.Name, true).SetUserContext(user); var blockResult = await blockCmd.Execute(); //Verify Front is created userBlockQuery = new QueryUserBlocks(userName).SetUserContext(user); userBlockResults = await userBlockQuery.ExecuteAsync(); Assert.IsNotNull(userBlockResults, "What about it, pretzel man? What's your story?"); Assert.AreEqual(1, userBlockResults.Count(), "First day on the job, you know what I learned? How to spot a murderer."); Assert.IsTrue(userBlockResults.Any(x => x.Type == DomainType.Subverse && x.Name == subName), "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(x => x.Type == SetType.Blocked), "Is it Friday already? "); var set = userSetResults.First(x => x.Type == SetType.Blocked); Assert.AreEqual(SetType.Blocked, 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, count, ""); currentSubscriberCount = count; } //verify FRONT set has sub using (var repo = new Voat.Data.Repository()) { var setList = await repo.GetSetListDescription(SetType.Blocked.ToString(), userName); Assert.IsTrue(setList.Any(x => x.Name == subName)); } //Unsubscribe blockCmd = new BlockCommand(domainReference.Type, domainReference.Name, true).SetUserContext(user); blockResult = await blockCmd.Execute(); VoatAssert.IsValid(blockResult); //Ensure Subverse Subscriber Count Updated using (var db = new VoatDataContext()) { var count = db.Subverse.First(x => x.Name == subName).SubscriberCount; Assert.AreEqual(currentSubscriberCount, count.HasValue ? count.Value : 0, ""); } //verify FRONT set has not sub using (var repo = new Voat.Data.Repository()) { var setList = await repo.GetSetListDescription(SetType.Blocked.ToString(), userName); Assert.IsFalse(setList.Any(x => x.Name == subName)); } }
public async Task MentionUser_Anon_Block_Test() { string user1 = "UnitTestUser13"; string user2 = "BlocksAnonTestUser01"; TestDataInitializer.CreateUser(user2); var user = TestHelper.SetPrincipal(user2); var prefCmd = new UpdateUserPreferencesCommand(new Domain.Models.UserPreferenceUpdate() { BlockAnonymized = true }).SetUserContext(user); var prefResult = await prefCmd.Execute(); VoatAssert.IsValid(prefResult); //Submission Mention - NO NO user = TestHelper.SetPrincipal(user1); var anonSubmission = TestHelper.ContentCreation.CreateSubmission(user1, new Domain.Models.UserSubmission() { Title = $"I'm harrassing @{user2}!", Content = $"Hey everyone isn't /u/{user2} a shill tornado?", 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"); 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(0, count, "Expecting No Submission Mentions!"); } //Comment Mention - NO NO string commentContent = $"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, commentContent).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(0, count, "Received duplicates and now users are annoyed and burning down the village! Run!"); } //Comment Reply - YES YES user = TestHelper.SetPrincipal(user2); commentContent = $"I'm {user2} won't someone reply to me so I can see if reply notifications work?"; cmd = new CreateCommentCommand(anonSubmission.ID, null, commentContent).SetUserContext(user); result = await cmd.Execute(); VoatAssert.IsValid(result); user = TestHelper.SetPrincipal(user1); commentContent = $"I'm following you!"; cmd = new CreateCommentCommand(anonSubmission.ID, result.Response.ID, commentContent).SetUserContext(user); 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.CommentReply ).Count(); Assert.AreEqual(1, count, "Replies should work!!!!!!"); } //Submission Reply - YES YES user = TestHelper.SetPrincipal(user2); anonSubmission = TestHelper.ContentCreation.CreateSubmission(user2, new Domain.Models.UserSubmission() { Title = $"Is this working?", Content = $"Someeone, anyone, am I alone?", 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"); user = TestHelper.SetPrincipal(user1); commentContent = $"I know who you are and I've been following you this entire unit test. I might be in love with you, if stalking is a form of love."; cmd = new CreateCommentCommand(anonSubmission.ID, null, commentContent).SetUserContext(user); 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.SubmissionID == anonSubmission.ID && x.IsAnonymized == true && x.Type == (int)Domain.Models.MessageType.SubmissionReply ).Count(); Assert.AreEqual(1, count, "Replies should work!!!!!!"); } }