Пример #1
0
        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);
        }
Пример #2
0
 public UserRepositoryTest(DatabaseFixture fixture)
 {
     _fixture        = fixture;
     _context        = _fixture.CreateContext();
     _userRepository = new UserRepository(_context);
     TestDataInitializer.ClearData(_context);
 }
Пример #3
0
        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));
        }
Пример #4
0
        public static void SetUp(TestContext context, TestDataInitializer intializer, bool configure = true)
        {
            //bool preventDrop = false;

            if (configure)
            {
                //Configure App
                var config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                             .Build();
                config.ConfigureVoat();
                //config["voat:test:preventDatabaseDrop"] != "True"
            }

            FilePather.Instance = new FilePather(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

            //Drop and reseed database
            using (var db = new VoatDataContext())
            {
                intializer.InitializeDatabase(db); //This attempts to create and seed unit test db
            }

            //This causes the voat rules engine to init using config section for load
            var rulesEngine = VoatRulesEngine.Instance;

            //purge redis for unit tests if enabled
            var defaultHandler = CacheConfigurationSettings.Instance.Handlers.FirstOrDefault(x => x.Enabled && x.Type.ToLower().Contains("redis"));

            if (defaultHandler != null)
            {
                var instance = defaultHandler.Construct <ICacheHandler>();
                instance.Purge();
            }
        }
Пример #5
0
        public async Task GetPageAsync_should_return_1_user_when_page_is_3_and_pageSize_is_2()
        {
            // arrange
            TestDataInitializer.Init6UsersWhereLastOneIsDeleted(_context);

            //act
            var result = await _userRepository.GetPageAsync(3, 2);

            //assert
            Assert.Equal(1, result.Data.Count);
        }
Пример #6
0
        public async Task GetAllValidAsync_should_return_2_users_when_database_has_3_users_with_1_deleted_user()
        {
            // arrange
            TestDataInitializer.InitThreeUsersWhereLastOneIsDeleted(_context);

            //act
            var result = await _userRepository.GetAllValidAsync();

            //assert
            Assert.Equal(2, result.Count);
        }
Пример #7
0
        public async Task GetAsync_should_return_null_when_userIsDeleted_true()
        {
            //arrange
            var user = await TestDataInitializer.InitOneDeletedUserAsync(_context);

            //act
            var result = await _userRepository.GetAsync(user.Id);

            //assert
            Assert.Null(result);
        }
Пример #8
0
        public async Task GetPageAsync_should_return_2_posts_when_page_is_2_and_pageSize_is_2()
        {
            // arrange
            var user = await TestDataInitializer.InitOneGeneralUserAsync(_context);

            await TestDataInitializer.Init5PostsWith1DeletedPost(_context, user);

            //act
            var result = await _postRepository.GetPageAsync(1, 2, 2, false, null);

            //assert
            Assert.Equal(2, result.Data.Count);
        }
Пример #9
0
        public async Task GetAllAsync_should_return_4_posts_when_database_has_5_posts_with_1_deleted_Post()
        {
            // arrange
            var user = await TestDataInitializer.InitOneGeneralUserAsync(_context);

            await TestDataInitializer.Init5PostsWith1DeletedPost(_context, user);

            //act
            var result = await _postRepository.GetAllAsync();

            //assert
            Assert.Equal(4, result.Count);
        }
Пример #10
0
        public async Task FindAsync_should_return_null_if_post_is_deleted()
        {
            // arrange
            var user = await TestDataInitializer.InitOneGeneralUserAsync(_context);

            await TestDataInitializer.Init5PostsWith1DeletedPost(_context, user);

            //act
            var result = await _postRepository.FindValidAsync(p => p.IsDeleted);

            //assert
            Assert.Equal(0, result.Count);
        }
Пример #11
0
        public async Task GetPostsForBatchAsync_should_return_4_posts_with_titles_sequence_NH_OH_N_3_after_first_batch()
        {
            //arrange
            await TestDataInitializer.Init_3HP_3NP_Posts(_context);

            //act
            var result = await _postService.GetPostsForBatchAsync(DateTime.Now.AddDays(-13), _context.Posts.First(p => p.Title == "1").CreatedDate);

            //assert
            Assert.Equal(result[0].Title, "NH");
            Assert.Equal(result[1].Title, "OH");
            Assert.Equal(result[2].Title, "N");
            Assert.Equal(result[3].Title, "3");
        }
Пример #12
0
        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");
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        public PostServiceIntegrationTest(DatabaseFixture fixture)
        {
            _fixture        = fixture;
            _context        = _fixture.CreateContext();
            _postRepository = new PostRepository(_context);
            TestDataInitializer.ClearData(_context);

            _unitOfWork      = new Mock <IUnitOfWork>();
            _userContextMock = new Mock <IUserContext>();
            _fileServiceMock = new Mock <IFileService>();
            _commentService  = new Mock <ICommentService>();
            _postOptions     = new Mock <IOptionsSnapshot <PostConfig> >();
            _batchOptions    = new Mock <IOptionsSnapshot <FullscreenBatchConfig> >();

            _postService = new PostService(_unitOfWork.Object, _fileServiceMock.Object, _commentService.Object, _userContextMock.Object,
                                           _batchOptions.Object, _postOptions.Object);
            _unitOfWork.SetupGet(x => x.Posts).Returns(_postRepository);

            _batchOptions.SetupProperty(bo => bo.Value.FullscreenBatchSize, 4);

            //_batchOptions.Object.Value.FullscreenBatchSize = 4;
        }
Пример #15
0
        public async Task GetPostsForBatchAsync_should_return_4_posts_with_titles_sequence_OH_3_2_1_when_first_batch_ever()
        {
            //arrange
            await TestDataInitializer.Init_1Post(_context, "FutureNH", -100, PostPriority.High);

            await TestDataInitializer.Init_1Post(_context, "FutureN", -100, PostPriority.Normal);

            await TestDataInitializer.Init_1Post(_context, "3", 10, PostPriority.Normal);

            await TestDataInitializer.Init_1Post(_context, "2", 20, PostPriority.Normal);

            await TestDataInitializer.Init_1Post(_context, "OH", 100, PostPriority.High);

            await TestDataInitializer.Init_1Post(_context, "1", 30, PostPriority.Normal);

            //act
            var result = await _postService.GetPostsForBatchAsync(null, null);

            //assert
            Assert.Equal(result[0].Title, "OH");
            Assert.Equal(result[1].Title, "3");
            Assert.Equal(result[2].Title, "2");
            Assert.Equal(result[3].Title, "1");
        }
Пример #16
0
 public void Dispose()
 {
     TestDataInitializer.ClearData(_context);
     _context.Dispose();
 }
Пример #17
0
        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!!!!!!");
            }
        }
Пример #18
0
        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 override void ClassInitialize()
 {
     TestDataInitializer.CreateSorted(subverse);
 }
Пример #20
0
        /// <summary>
        /// バッチ処理
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private static bool RunBatch(string[] args)
        {
            try
            {
                Dictionary <string, string> argList = GetCommandArgs(args);
                if (argList.Count == 0)
                {
                    return(false);
                }
                if (!argList.ContainsKey("mode"))
                {
                    return(false);
                }
                if (argList.ContainsKey("help"))
                {
                    return(false);
                }
                string mode = argList["mode"];
                switch (mode)
                {
                case "0":
                    if (argList.ContainsKey("path") && argList.ContainsKey("target"))
                    {
                        string path = argList["path"];
                        if (!System.IO.Directory.Exists(path))
                        {
                            return(false);
                        }
                        bool isTarget = false;

                        if (!bool.TryParse(argList["target"], out isTarget))
                        {
                            return(false);
                        }
                        string pattern = "*.xlsm";
                        if (argList.ContainsKey("pattern"))
                        {
                            pattern = argList["pattern"];
                        }
                        string batchFile = string.Empty;
                        if (argList.ContainsKey("batch"))
                        {
                            batchFile = argList["batch"];
                        }
                        string[] files = System.IO.Directory.GetFiles(path, pattern, System.IO.SearchOption.AllDirectories);
                        foreach (string file in files)
                        {
                            //SQL作成
                            TestDataInitializer initializer = new TestDataInitializer(null);
                            initializer.DoInitlize(file, isTarget, batchFile);
                        }
                        return(true);
                    }
                    break;

                case "1":
                    if (argList.ContainsKey("exceptfile"))
                    {
                        string exceptfile = argList["exceptfile"];
                        if (!System.IO.File.Exists(exceptfile))
                        {
                            return(false);
                        }
                        TestDataChecker checker      = new TestDataChecker(null);
                        string          outputFolder = "";
                        if (argList.ContainsKey("output"))
                        {
                            outputFolder = argList["output"];
                        }
                        checker.CheckDatas(exceptfile, outputFolder);
                        return(true);
                    }
                    break;

                default:
                    break;
                }
                return(false);
            }
            catch (Exception ex)
            {
                Logging.Exception("Batch", ex);
                return(false);
            }
        }
Пример #21
0
        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));
        }
Пример #22
0
        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);
        }
Пример #23
0
 public override void ClassInitialize()
 {
     _submissionID = TestDataInitializer.BuildCommentTree("anon", "Build Comment Tree", 1, 2, 2);
 }
Пример #24
0
 public override void ClassInitialize()
 {
     _unitSubmissionID = TestDataInitializer.BuildCommentTree(SUBVERSES.Unit, "Build Comment Tree", _rootCount, _nestedCount, _recurseCount);
 }
Пример #25
0
        /// <summary>
        /// データインサート用SQL文を生成する
        /// </summary>
        /// <param name="designFileName"></param>
        /// <param name="layoutType"></param>
        private void DoInsertSqlScript(string dataSheetName, bool isTarget)
        {
            TestDataInitializer initializer = new TestDataInitializer(reportHandler);

            initializer.DoInitlize(dataSheetName, isTarget, "");
        }