YouConf.Controllers.ConferenceController.All C# (CSharp) Метод

All() публичный Метод

public All ( ) : System.Web.Mvc.ActionResult
Результат System.Web.Mvc.ActionResult
        public ActionResult All()
        {
            var conferences = YouConfDbContext
                .Conferences
                .Where(x => x.AvailableToPublic)
                .OrderBy(x => x.StartDate)
                .ToList();
            ViewBag.Title = "All conferences";
            return View(conferences);
        }

Usage Example

        public void All_Should_ReturnOnlyPublicConferences()
        {
            //Three public conferences, one private
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = true });
            _context.Conferences.Add(new Conference() { HashTag = "test", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false });
            _context.SaveChangesWithErrors();

            var conferenceController = new ConferenceController(_context);

            var result = conferenceController.All()
                .As<ViewResult>();

            result.Model
                .As<IEnumerable<Conference>>()
                .Should().HaveCount(3);
        }