public void SamplingPlan_Controller_GetSamplingPlanList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(samplingPlanController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType); SamplingPlan samplingPlanFirst = new SamplingPlan(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanFirst = (from c in db.SamplingPlans select c).FirstOrDefault(); count = (from c in db.SamplingPlans select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with SamplingPlan info IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <SamplingPlan> > ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanFirst.SamplingPlanID, ret.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <SamplingPlan> samplingPlanList = new List <SamplingPlan>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID); samplingPlanList = (from c in db.SamplingPlans select c).OrderBy(c => c.SamplingPlanID).Skip(0).Take(2).ToList(); count = (from c in db.SamplingPlans select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with SamplingPlan info jsonRet = samplingPlanController.GetSamplingPlanList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanList[0].SamplingPlanID, ret.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); if (count > 1) { query.Skip = 1; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with SamplingPlan info IHttpActionResult jsonRet2 = samplingPlanController.GetSamplingPlanList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <SamplingPlan> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SamplingPlan> >; Assert.AreEqual(samplingPlanList[1].SamplingPlanID, ret2.Content[0].SamplingPlanID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }