public void VPResult_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { VPResultService vpResultService = new VPResultService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } VPResult vpResult = GetFilledRandomVPResult(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = vpResultService.GetVPResultList().Count(); Assert.AreEqual(count, (from c in dbTestDB.VPResults select c).Count()); vpResultService.Add(vpResult); if (vpResult.HasErrors) { Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, vpResultService.GetVPResultList().Where(c => c == vpResult).Any()); vpResultService.Update(vpResult); if (vpResult.HasErrors) { Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, vpResultService.GetVPResultList().Count()); vpResultService.Delete(vpResult); if (vpResult.HasErrors) { Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); } } }
public void GetVPResultList_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { VPResultService vpResultService = new VPResultService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); VPResult vpResult = (from c in dbTestDB.VPResults select c).FirstOrDefault(); Assert.IsNotNull(vpResult); List <VPResult> vpResultDirectQueryList = new List <VPResult>(); vpResultDirectQueryList = (from c in dbTestDB.VPResults select c).Take(200).ToList(); foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { vpResultService.Query.Extra = extra; if (string.IsNullOrWhiteSpace(extra)) { List <VPResult> vpResultList = new List <VPResult>(); vpResultList = vpResultService.GetVPResultList().ToList(); CheckVPResultFields(vpResultList); } else { //Assert.AreEqual(true, false); } } } } }
public void GetVPResultList_2Where_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { foreach (string extra in new List <string>() { null, "A", "B", "C", "D", "E" }) { VPResultService vpResultService = new VPResultService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "VPResultID,GT,2|VPResultID,LT,5", extra); List <VPResult> vpResultDirectQueryList = new List <VPResult>(); vpResultDirectQueryList = (from c in dbTestDB.VPResults select c).Where(c => c.VPResultID > 2 && c.VPResultID < 5).ToList(); if (string.IsNullOrWhiteSpace(extra)) { List <VPResult> vpResultList = new List <VPResult>(); vpResultList = vpResultService.GetVPResultList().ToList(); CheckVPResultFields(vpResultList); Assert.AreEqual(vpResultDirectQueryList[0].VPResultID, vpResultList[0].VPResultID); } else { //Assert.AreEqual(true, false); } } } } }
public void VPResult_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { VPResultService vpResultService = new VPResultService(new Query() { Lang = culture.TwoLetterISOLanguageName }, dbTestDB, ContactID); int count = 0; if (count == 1) { // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used] } count = vpResultService.GetVPResultList().Count(); VPResult vpResult = GetFilledRandomVPResult(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // vpResult.VPResultID (Int32) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.VPResultID = 0; vpResultService.Update(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "VPResultID"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.VPResultID = 10000000; vpResultService.Update(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "VPResult", "VPResultID", vpResult.VPResultID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "VPScenario", ExistPlurial = "s", ExistFieldID = "VPScenarioID", AllowableTVtypeList = )] // vpResult.VPScenarioID (Int32) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.VPScenarioID = 0; vpResultService.Add(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "VPScenario", "VPScenarioID", vpResult.VPScenarioID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 1000)] // vpResult.Ordinal (Int32) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Ordinal = -1; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Ordinal = 1001; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 10000000)] // vpResult.Concentration_MPN_100ml (Int32) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Concentration_MPN_100ml = -1; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Concentration_MPN_100ml", "0", "10000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Concentration_MPN_100ml = 10000001; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Concentration_MPN_100ml", "0", "10000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 1000000)] // vpResult.Dilution (Double) // ----------------------------------- //CSSPError: Type not implemented [Dilution] //CSSPError: Type not implemented [Dilution] vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Dilution = -1.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Dilution", "0", "1000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.Dilution = 1000001.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Dilution", "0", "1000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 10000)] // vpResult.FarFieldWidth_m (Double) // ----------------------------------- //CSSPError: Type not implemented [FarFieldWidth_m] //CSSPError: Type not implemented [FarFieldWidth_m] vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.FarFieldWidth_m = -1.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldWidth_m", "0", "10000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.FarFieldWidth_m = 10001.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldWidth_m", "0", "10000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 100000)] // vpResult.DispersionDistance_m (Double) // ----------------------------------- //CSSPError: Type not implemented [DispersionDistance_m] //CSSPError: Type not implemented [DispersionDistance_m] vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.DispersionDistance_m = -1.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DispersionDistance_m", "0", "100000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.DispersionDistance_m = 100001.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DispersionDistance_m", "0", "100000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [Range(0, 100)] // vpResult.TravelTime_hour (Double) // ----------------------------------- //CSSPError: Type not implemented [TravelTime_hour] //CSSPError: Type not implemented [TravelTime_hour] vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.TravelTime_hour = -1.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TravelTime_hour", "0", "100"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.TravelTime_hour = 101.0D; Assert.AreEqual(false, vpResultService.Add(vpResult)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TravelTime_hour", "0", "100"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, vpResultService.GetVPResultList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // vpResult.LastUpdateDate_UTC (DateTime) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.LastUpdateDate_UTC = new DateTime(); vpResultService.Add(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.LastUpdateDate_UTC = new DateTime(1979, 1, 1); vpResultService.Add(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // vpResult.LastUpdateContactTVItemID (Int32) // ----------------------------------- vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.LastUpdateContactTVItemID = 0; vpResultService.Add(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", vpResult.LastUpdateContactTVItemID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); vpResult = null; vpResult = GetFilledRandomVPResult(""); vpResult.LastUpdateContactTVItemID = 1; vpResultService.Add(vpResult); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // vpResult.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // vpResult.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }
public IHttpActionResult GetVPResultList([FromUri] string lang = "en", [FromUri] int skip = 0, [FromUri] int take = 200, [FromUri] string asc = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { VPResultService vpResultService = new VPResultService(new Query() { Lang = lang }, db, ContactID); if (extra == "A") // QueryString contains [extra=A] { vpResultService.Query = vpResultService.FillQuery(typeof(VPResultExtraA), lang, skip, take, asc, desc, where, extra); if (vpResultService.Query.HasErrors) { return(Ok(new List <VPResultExtraA>() { new VPResultExtraA() { HasErrors = vpResultService.Query.HasErrors, ValidationResults = vpResultService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(vpResultService.GetVPResultExtraAList().ToList())); } } else if (extra == "B") // QueryString contains [extra=B] { vpResultService.Query = vpResultService.FillQuery(typeof(VPResultExtraB), lang, skip, take, asc, desc, where, extra); if (vpResultService.Query.HasErrors) { return(Ok(new List <VPResultExtraB>() { new VPResultExtraB() { HasErrors = vpResultService.Query.HasErrors, ValidationResults = vpResultService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(vpResultService.GetVPResultExtraBList().ToList())); } } else // QueryString has no parameter [extra] or extra is empty { vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), lang, skip, take, asc, desc, where, extra); if (vpResultService.Query.HasErrors) { return(Ok(new List <VPResult>() { new VPResult() { HasErrors = vpResultService.Query.HasErrors, ValidationResults = vpResultService.Query.ValidationResults, }, }.ToList())); } else { return(Ok(vpResultService.GetVPResultList().ToList())); } } } }