public void ReportSection_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ReportSectionService reportSectionService = new ReportSectionService(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] } ReportSection reportSection = GetFilledRandomReportSection(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = reportSectionService.GetReportSectionList().Count(); Assert.AreEqual(count, (from c in dbTestDB.ReportSections select c).Count()); reportSectionService.Add(reportSection); if (reportSection.HasErrors) { Assert.AreEqual("", reportSection.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, reportSectionService.GetReportSectionList().Where(c => c == reportSection).Any()); reportSectionService.Update(reportSection); if (reportSection.HasErrors) { Assert.AreEqual("", reportSection.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, reportSectionService.GetReportSectionList().Count()); reportSectionService.Delete(reportSection); if (reportSection.HasErrors) { Assert.AreEqual("", reportSection.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); } } }
public IHttpActionResult Put([FromBody] ReportSection reportSection, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { ReportSectionService reportSectionService = new ReportSectionService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!reportSectionService.Update(reportSection)) { return(BadRequest(String.Join("|||", reportSection.ValidationResults))); } else { reportSection.ValidationResults = null; return(Ok(reportSection)); } } }
public void ReportSection_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ReportSectionService reportSectionService = new ReportSectionService(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 = reportSectionService.GetReportSectionList().Count(); ReportSection reportSection = GetFilledRandomReportSection(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // reportSection.ReportSectionID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ReportSectionID = 0; reportSectionService.Update(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ReportSectionID"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ReportSectionID = 10000000; reportSectionService.Update(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportSection", "ReportSectionID", reportSection.ReportSectionID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "ReportType", ExistPlurial = "s", ExistFieldID = "ReportTypeID", AllowableTVtypeList = )] // reportSection.ReportTypeID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ReportTypeID = 0; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportType", "ReportTypeID", reportSection.ReportTypeID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = )] // reportSection.TVItemID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.TVItemID = 0; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID", reportSection.TVItemID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.TVItemID = 1; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID", ""), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPEnumType] // reportSection.Language (LanguageEnum) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.Language = (LanguageEnum)1000000; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 1000)] // reportSection.Ordinal (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.Ordinal = -1; Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.Ordinal = 1001; Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); // ----------------------------------- // Is NOT Nullable // reportSection.IsStatic (Boolean) // ----------------------------------- // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "ReportSection", ExistPlurial = "s", ExistFieldID = "ReportSectionID", AllowableTVtypeList = )] // reportSection.ParentReportSectionID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ParentReportSectionID = 0; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportSection", "ParentReportSectionID", reportSection.ParentReportSectionID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [Range(1979, 2050)] // reportSection.Year (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.Year = 1978; Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "1979", "2050"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.Year = 2051; Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "1979", "2050"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); // ----------------------------------- // Is NOT Nullable // reportSection.Locked (Boolean) // ----------------------------------- // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "ReportSection", ExistPlurial = "s", ExistFieldID = "ReportSectionID", AllowableTVtypeList = )] // reportSection.TemplateReportSectionID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.TemplateReportSectionID = 0; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportSection", "TemplateReportSectionID", reportSection.TemplateReportSectionID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(100))] // reportSection.ReportSectionName (String) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ReportSectionName = GetRandomString("", 101); Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ReportSectionName", "100"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); // ----------------------------------- // Is Nullable // [StringLength(10000))] // reportSection.ReportSectionText (String) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.ReportSectionText = GetRandomString("", 10001); Assert.AreEqual(false, reportSectionService.Add(reportSection)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ReportSectionText", "10000"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportSectionService.GetReportSectionList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // reportSection.LastUpdateDate_UTC (DateTime) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.LastUpdateDate_UTC = new DateTime(); reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.LastUpdateDate_UTC = new DateTime(1979, 1, 1); reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // reportSection.LastUpdateContactTVItemID (Int32) // ----------------------------------- reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.LastUpdateContactTVItemID = 0; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", reportSection.LastUpdateContactTVItemID.ToString()), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); reportSection = null; reportSection = GetFilledRandomReportSection(""); reportSection.LastUpdateContactTVItemID = 1; reportSectionService.Add(reportSection); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), reportSection.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // reportSection.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // reportSection.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }