public IHttpActionResult GetTVItemWithID([FromUri] int TVItemID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemService tvItemService = new TVItemService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); tvItemService.Query = tvItemService.FillQuery(typeof(TVItem), lang, 0, 1, "", "", extra); if (tvItemService.Query.Extra == "A") { TVItemExtraA tvItemExtraA = new TVItemExtraA(); tvItemExtraA = tvItemService.GetTVItemExtraAWithTVItemID(TVItemID); if (tvItemExtraA == null) { return(NotFound()); } return(Ok(tvItemExtraA)); } else if (tvItemService.Query.Extra == "B") { TVItemExtraB tvItemExtraB = new TVItemExtraB(); tvItemExtraB = tvItemService.GetTVItemExtraBWithTVItemID(TVItemID); if (tvItemExtraB == null) { return(NotFound()); } return(Ok(tvItemExtraB)); } else { TVItem tvItem = new TVItem(); tvItem = tvItemService.GetTVItemWithTVItemID(TVItemID); if (tvItem == null) { return(NotFound()); } return(Ok(tvItem)); } } }
public void GetTVItemWithTVItemID__tvItem_TVItemID__Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemService tvItemService = new TVItemService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); TVItem tvItem = (from c in dbTestDB.TVItems select c).FirstOrDefault(); Assert.IsNotNull(tvItem); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { tvItemService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { TVItem tvItemRet = tvItemService.GetTVItemWithTVItemID(tvItem.TVItemID); CheckTVItemFields(new List <TVItem>() { tvItemRet }); Assert.AreEqual(tvItem.TVItemID, tvItemRet.TVItemID); } else { //Assert.AreEqual(true, false); } } } } }