public void GetSubjects()
 {
     using (OdsRepository repository = new OdsRepository())
     {
         IList <CoursePrefix> subjects = repository.GetCourseSubjects();
         Assert.IsTrue(subjects.Count > 0);
     }
 }
 public void GetSubjects()
 {
     using (OdsRepository repository = new OdsRepository())
     {
         IList<CoursePrefix> subjects = repository.GetCourseSubjects();
         Assert.IsTrue(subjects.Count > 0);
     }
 }
        public void GetSubjectsWithYQ_Success()
        {
            using (OdsRepository repo = new OdsRepository())
            {
                YearQuarter          yearQuarter = repo.CurrentYearQuarter;
                IList <CoursePrefix> actual      = repo.GetCourseSubjects(yearQuarter);

                int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID), true);
                Assert.AreEqual(expectedCount, actual.Count);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="yearQuarter"></param>
        /// <returns></returns>
        public static IList<ScheduleCoursePrefix> GetSubjectList(string yearQuarter)
        {
            IList<ScheduleCoursePrefix> subjectList;
            using (OdsRepository db = new OdsRepository())
            {
              IList<CoursePrefix> data;
              data = string.IsNullOrWhiteSpace(yearQuarter) || yearQuarter.Equals("All", StringComparison.OrdinalIgnoreCase)
                   ? db.GetCourseSubjects()
                   : db.GetCourseSubjects(YearQuarter.FromFriendlyName(yearQuarter));
              IList<string> apiSubjects = data.Select(s => s.Subject).ToList();

              using (ClassScheduleDb classScheduleDb = new ClassScheduleDb())
              {
            // Entity Framework doesn't support all the functionality that LINQ does, so first grab the records from the database...
            var dbSubjects = (from s in classScheduleDb.Subjects
                              join p in classScheduleDb.SubjectsCoursePrefixes on s.SubjectID equals p.SubjectID
                              select new
                                       {
                                         s.Slug,
                                         p.CoursePrefixID,
                                         s.Title
                                       })
              .ToList();
            // ...then apply the necessary filtering (e.g. TrimEnd() - which isn't fully supported by EF
            subjectList = (from s in dbSubjects
                           // TODO: replace hard-coded '&' with CommonCourseChar from .config
                           where apiSubjects.Contains(s.CoursePrefixID.TrimEnd('&'))
                           select new ScheduleCoursePrefix
                                    {
                                      Slug = s.Slug,
                                      Subject = s.CoursePrefixID,
                                      Title = s.Title
                                    })
              .OrderBy(s => s.Title)
              .Distinct()
              .ToList();
              }
            }
            return subjectList;
        }
        public void GetSubjectsWithChar()
        {
            using (OdsRepository repository = new OdsRepository())
            {
                char firstChar = 'b';
                IList <CoursePrefix> actual = repository.GetCourseSubjects(firstChar);

                int actualCount = actual.Count;
                Assert.IsTrue(actualCount > 0);

                int count = actual.Where(c => c.Subject.StartsWith(firstChar.ToString(), true, CultureInfo.CurrentCulture)).Count();
                Assert.AreEqual(actualCount, count);
            }
        }
        public void GetSubjectsWithYrq_Modality_Online_Success()
        {
            using (OdsRepository repo = new OdsRepository())
            {
                YearQuarter           yearQuarter = YearQuarter.FromString("B122");
                IList <ISectionFacet> facets      = new List <ISectionFacet>();

                facets.Add(new ModalityFacet(ModalityFacet.Options.Online));
                IList <CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter, facets);

                int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}' and SBCTCMisc1 like '3%'", yearQuarter.ID), true);
                Assert.AreEqual(expectedCount, actual.Count);

                int allCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID));
                Assert.IsTrue(allCount > actual.Count, "Count of online sections is not less than all sections");
            }
        }
        public void GetSubjects_VerifyCourseSubjectIsCorrectlyExcluded()
        {
            YearQuarter yrq = TestHelper.Data.YearQuarterWithSections;

            using (OdsRepository repo = new OdsRepository())
            {
                IList <CoursePrefix> actual = repo.GetCourseSubjects(yrq);
                Assert.IsTrue(actual.Count > 0, "No subjects were returned for {0} ({1})", yrq.FriendlyName, yrq);

                string subject = _dataVerifier.GetRandomCourseSubject(string.Format("YearQuarterID <> '{0}'", yrq.ID), true);

                IEnumerable <CoursePrefix> shouldBeEmpty = actual.Where(s => s.Subject.ToUpper() == subject.ToUpper());
                int emptyCount = shouldBeEmpty.Count();
                if (emptyCount > 0)
                {
                    Assert.Fail("{0} found in {1} ({2})", emptyCount, yrq.FriendlyName, yrq);
                }
            }
        }
        public void GetSubjectsWithChar()
        {
            using (OdsRepository repository = new OdsRepository())
            {
                char firstChar = 'b';
                IList<CoursePrefix> actual = repository.GetCourseSubjects(firstChar);

                int actualCount = actual.Count;
                Assert.IsTrue(actualCount > 0);

                int count = actual.Where(c => c.Subject.StartsWith(firstChar.ToString(), true, CultureInfo.CurrentCulture)).Count();
                Assert.AreEqual(actualCount, count);
            }
        }
        public void GetSubjects_VerifyCourseSubjectIsCorrectlyExcluded()
        {
            YearQuarter yrq = TestHelper.Data.YearQuarterWithSections;

            using (OdsRepository repo = new OdsRepository())
            {
                IList<CoursePrefix> actual = repo.GetCourseSubjects(yrq);
                Assert.IsTrue(actual.Count > 0, "No subjects were returned for {0} ({1})", yrq.FriendlyName, yrq);

                string subject = _dataVerifier.GetRandomCourseSubject(string.Format("YearQuarterID <> '{0}'", yrq.ID), true);

                IEnumerable<CoursePrefix> shouldBeEmpty = actual.Where(s => s.Subject.ToUpper() == subject.ToUpper());
                int emptyCount = shouldBeEmpty.Count();
              if (emptyCount > 0)
              {
                Assert.Fail("{0} found in {1} ({2})", emptyCount, yrq.FriendlyName, yrq);
              }
            }
        }
        public void GetSubjectsWithYrq_Modality_Online_Success()
        {
            using (OdsRepository repo = new OdsRepository())
            {
                YearQuarter yearQuarter = YearQuarter.FromString("B122");
                IList<ISectionFacet> facets = new List<ISectionFacet>();

                facets.Add(new ModalityFacet(ModalityFacet.Options.Online));
                IList<CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter, facets);

                int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}' and SBCTCMisc1 like '3%'", yearQuarter.ID), true);
                Assert.AreEqual(expectedCount, actual.Count);

                int allCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID));
                Assert.IsTrue(allCount > actual.Count, "Count of online sections is not less than all sections");
            }
        }
        public void GetSubjectsWithYQ_Success()
        {
            using (OdsRepository repo = new OdsRepository())
            {
                YearQuarter yearQuarter = repo.CurrentYearQuarter;
                IList<CoursePrefix> actual = repo.GetCourseSubjects(yearQuarter);

                int expectedCount = _dataVerifier.GetCourseSubjectCountForSections(string.Format("YearQuarterID = '{0}'", yearQuarter.ID), true);
                Assert.AreEqual(expectedCount, actual.Count);
            }
        }
        public ActionResult YearQuarter(String YearQuarter, string timestart, string timeend, string day_su, string day_m, string day_t, string day_w, string day_th, string day_f, string day_s, string f_oncampus, string f_online, string f_hybrid, string avail, string letter, string latestart, string numcredits, string format)
        {
            _log.Trace(m => m("Calling: [.../classes/{0}...] From (referrer): [{1}]", YearQuarter, Request.UrlReferrer));

              // TODO: come up with a better way to maintain various State flags
              ViewBag.Modality = Helpers.ConstructModalityList(f_oncampus, f_online, f_hybrid);
              ViewBag.Days = Helpers.ConstructDaysList(day_su, day_m, day_t, day_w, day_th, day_f, day_s);
              ViewBag.LinkParams = Helpers.getLinkParams(Request);
              ViewBag.timestart = timestart;
              ViewBag.timeend = timeend;
              ViewBag.latestart = latestart;
              ViewBag.avail = avail;
              IList<ISectionFacet> facets = Helpers.addFacets(timestart, timeend, day_su, day_m, day_t, day_w, day_th, day_f, day_s, f_oncampus, f_online, f_hybrid, avail, latestart, numcredits);

              YearQuarterModel model = new YearQuarterModel
              {
            ViewingSubjects = new List<SubjectModel>(),
            SubjectLetters = new List<char>(),
              };

              try
              {
            using (OdsRepository repository = new OdsRepository(HttpContext))
            {
              YearQuarter yrq = Helpers.DetermineRegistrationQuarter(YearQuarter, repository.CurrentRegistrationQuarter, RouteData);
              model.ViewingQuarter = yrq;

              model.NavigationQuarters = Helpers.GetYearQuarterListForMenus(repository);

              // set up all the ancillary data we'll need to display the View
              SetCommonViewBagVars(repository, avail, letter);

              // TODO: Refactor the following code to use ApiController.GetSubjectList()
              // after reconciling the noted differences between AllClasses() and YearQuarter() - 4/27/2012, [email protected]
              using (ClassScheduleDb db = new ClassScheduleDb())
              {
            // Compile a list of active subjects
            char[] commonCourseChar = _apiSettings.RegexPatterns.CommonCourseChar.ToCharArray();
            IList<string> activePrefixes = repository.GetCourseSubjects(yrq, facets).Select(p => p.Subject).ToList();

            IList<Subject> subjects = new List<Subject>();
            // NOTE: Unable to reduce the following loop to a LINQ statement because it complains about not being able to use TrimEnd(char[]) w/ LINQ-to-Entities
            // (Although it appears to be doing so just fine in the if statement below). - [email protected]
            foreach (Subject sub in db.Subjects)
            {
              // TODO: whether the CoursePrefix has active courses or not, any Prefix with a '&' will be included
              //			 because GetCourseSubjects() does not include the common course char.
              if (sub.CoursePrefixes.Select(sp => sp.CoursePrefixID).Any(sp => activePrefixes.Contains(sp.TrimEnd(commonCourseChar))))
              {
                subjects.Add(sub);
              }
            }

            model.SubjectLetters = subjects.Select(s => s.Title.First()).Distinct().ToList();
            model.ViewingSubjects = (letter != null
                                       ? subjects.Where(s => s.Title.StartsWith(letter, StringComparison.OrdinalIgnoreCase)).Distinct()
                                       : subjects
                                    ).Select(s => new SubjectModel
                                            {
                                              Title = s.Title,
                                              Slug = s.Slug,
                                              CoursePrefixes = s.CoursePrefixes.Select(p => p.CoursePrefixID).ToList()
                                            }
                                    ).ToList();

            if (format == "json")
            {
              // NOTE: AllowGet exposes the potential for JSON Hijacking (see http://haacked.com/archive/2009/06/25/json-hijacking.aspx)
              // but is not an issue here because we are receiving and returning public (e.g. non-sensitive) data
              JsonResult json = Json(model, JsonRequestBehavior.AllowGet);
              return json;
            }

            return View(model);
              }
            }
              }
              catch (ArgumentOutOfRangeException ex)
              {
            if (ex.Message.ToUpper().Contains("MUST BE A VALID QUARTER TITLE"))
            {
              throw new HttpException(404, string.Format("'{0}' is not a recognized Quarter.", YearQuarter), ex);
            }
            _log.Error(m => m("An unhandled ArgumentOutOfRangeException ocurred, returning an empty Model to the YearQuarter view."), ex);
              }
              catch (Exception ex)
              {
            _log.Error(m => m("An unhandled exception occurred, returning an empty Model to the YearQuarter view."), ex);
              }

              // empty model
              return View(model);
        }