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

Tag() public method

public Tag ( string id ) : System.Web.Mvc.ActionResult
id string
return System.Web.Mvc.ActionResult
        public ActionResult Tag(string id)
        {
            RavenQueryStatistics stats;
            List<Question> questions = DocumentSession.Query<Question>()
                                                      .Statistics(out stats)
                                                      .OrderByCreatedByDescending()
                                                      .Take(20)
                                                      .Where(x => x.Tags.Any(tag => tag == id))
                                                      .ToList();

            return Json(new
            {
                Questions = questions,
                stats.TotalResults
            }, JsonRequestBehavior.AllowGet);
        }

Usage Example

Esempio n. 1
0
        public void GivenSomeQuestionsAndAnExistingTag_Tags_ReturnsAListOfTaggedQuestions()
        {
            using (IDocumentSession documentSession = DocumentStore.OpenSession())
            {
                // Arrange.
                const string tag = "ravendb";
                var homeController = new HomeController(documentSession);
                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                var result = homeController.Tag(tag) as JsonResult;

                // Assert.
                Assert.NotNull(result);

                dynamic model = result.Data;
                Assert.NotNull(model);

                // At least 5 questions are hardcoded to include the RavenDb tag.
                Assert.NotNull(model.Questions);
                Assert.True(model.Questions.Count >= 5);
                Assert.True(model.TotalResults >= 5);
            }
        }
All Usage Examples Of RavenOverflow.Web.Controllers.HomeController::Tag