RavenOverflow.Web.Controllers.HomeController.IndexJson C# (CSharp) Method

IndexJson() public method

public IndexJson ( string displayName, string tag ) : System.Web.Mvc.JsonResult
displayName string
tag string
return System.Web.Mvc.JsonResult
        public JsonResult IndexJson(string displayName, string tag)
        {
            string header;
            var questions = QuestionQuery(tag, out header).ToList();
            return Json(questions.Count <= 0 ? null : questions);
        }

Usage Example

Esempio n. 1
0
        public void GivenSomeQuestionsAndNoDisplayNameAndNoTags_Index_ReturnsAJsonViewOfMostRecentQuestions()
        {
            using (IDocumentSession documentSession = DocumentStore.OpenSession())
            {
                // Arrange.
                var homeController = new HomeController(documentSession);
                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                // Note: this should return a list of the 20 most recent.
                JsonResult result = homeController.IndexJson(null, null);

                // Assert.
                Assert.NotNull(result);
                var questions = result.Data as IList<QuestionWithDisplayName>;
                Assert.NotNull(questions);
                Assert.Equal(20, questions.Count);

                // Now lets Make sure each one is ok.
                DateTime? previousDate = null;
                foreach (var question in questions)
                {
                    if (previousDate.HasValue)
                    {
                        Assert.True(previousDate.Value > question.CreatedOn);
                    }

                    previousDate = question.CreatedOn;
                    Assert.NotNull(question.DisplayName);
                    Assert.NotNull(question.Id);
                    Assert.NotNull(question.CreatedByUserId);
                    Assert.NotNull(question.Subject);
                    Assert.NotNull(question.Content);
                }
            }
        }
All Usage Examples Of RavenOverflow.Web.Controllers.HomeController::IndexJson