Example #1
0
        public async Task QueryUserSubmissions()
        {
            var userName = "******";
            var content  = "@Fuzzy made fun of my if statements. Says my if statements look *off* and that they aren't as good as other peoples if statements. :(";
            var user     = TestHelper.SetPrincipal(userName);
            var cmd      = new CreateSubmissionCommand(new Domain.Models.UserSubmission()
            {
                Subverse = SUBVERSES.Unit, Title = "This broke my heart", Content = content
            }).SetUserContext(user);
            var x = await cmd.Execute();

            VoatAssert.IsValid(x);

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

            Assert.AreEqual(true, r.Any(w => w.Content == content));
        }
Example #2
0
        public async Task QueryUserSubmissions_Anon()
        {
            var userName = "******";
            var content  = "I have emotional issues whenever I see curly braces";
            var user     = TestHelper.SetPrincipal(userName);
            var cmd      = new CreateSubmissionCommand(new Domain.Models.UserSubmission()
            {
                Subverse = SUBVERSES.Anon, Title = "This is my biggest secret", Content = content
            }).SetUserContext(user);
            var x = await cmd.Execute();

            VoatAssert.IsValid(x);

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

            Assert.AreEqual(false, r.Any(w => w.Content == content));
        }
Example #3
0
        public async Task <ActionResult> Submissions(string userName, int?page = null)
        {
            if (page.HasValue && page.Value < 0)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }


            var originalUserName = UserHelper.OriginalUsername(userName);

            if (String.IsNullOrEmpty(originalUserName))
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }
            ViewBag.UserName = originalUserName;

            ////if user is accesing their own comments, increase max page size to 100, else use default
            int?maxPages = (originalUserName == User.Identity.Name ? 100 : (int?)null);

            var q = new QueryUserSubmissions(userName,
                                             new Data.SearchOptions(maxPages)
            {
                Page = page ?? 0,
                Sort = Domain.Models.SortAlgorithm.New,
            });

            var data = await q.ExecuteAsync();

            var paged = new PaginatedList <Domain.Models.Submission>(data, page ?? 0, PAGE_SIZE, -1);

            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                MenuType    = MenuType.UserProfile,
                Name        = originalUserName,
                BasePath    = "/user/" + originalUserName,
                Description = originalUserName + "'s Submissions",
            };

            ViewBag.RobotIndexing = Domain.Models.RobotIndexing.None;
            return(View(paged));
        }