public void ReportType_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ReportTypeService reportTypeService = new ReportTypeService(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] } ReportType reportType = GetFilledRandomReportType(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = reportTypeService.GetReportTypeList().Count(); Assert.AreEqual(count, (from c in dbTestDB.ReportTypes select c).Count()); reportTypeService.Add(reportType); if (reportType.HasErrors) { Assert.AreEqual("", reportType.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, reportTypeService.GetReportTypeList().Where(c => c == reportType).Any()); reportTypeService.Update(reportType); if (reportType.HasErrors) { Assert.AreEqual("", reportType.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, reportTypeService.GetReportTypeList().Count()); reportTypeService.Delete(reportType); if (reportType.HasErrors) { Assert.AreEqual("", reportType.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); } } }
public IHttpActionResult Put([FromBody] ReportType reportType, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { ReportTypeService reportTypeService = new ReportTypeService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!reportTypeService.Update(reportType)) { return(BadRequest(String.Join("|||", reportType.ValidationResults))); } else { reportType.ValidationResults = null; return(Ok(reportType)); } } }
public void ReportType_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { ReportTypeService reportTypeService = new ReportTypeService(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 = reportTypeService.GetReportTypeList().Count(); ReportType reportType = GetFilledRandomReportType(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // reportType.ReportTypeID (Int32) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.ReportTypeID = 0; reportTypeService.Update(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "ReportTypeID"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); reportType = null; reportType = GetFilledRandomReportType(""); reportType.ReportTypeID = 10000000; reportTypeService.Update(reportType); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportType", "ReportTypeID", reportType.ReportTypeID.ToString()), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // reportType.TVType (TVTypeEnum) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.TVType = (TVTypeEnum)1000000; reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TVType"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // reportType.FileType (FileTypeEnum) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.FileType = (FileTypeEnum)1000000; reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "FileType"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [StringLength(100))] // reportType.UniqueCode (String) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType("UniqueCode"); Assert.AreEqual(false, reportTypeService.Add(reportType)); Assert.AreEqual(1, reportType.ValidationResults.Count()); Assert.IsTrue(reportType.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "UniqueCode")).Any()); Assert.AreEqual(null, reportType.UniqueCode); Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); reportType = null; reportType = GetFilledRandomReportType(""); reportType.UniqueCode = GetRandomString("", 101); Assert.AreEqual(false, reportTypeService.Add(reportType)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "UniqueCode", "100"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); // ----------------------------------- // Is Nullable // [CSSPEnumType] // reportType.Language (LanguageEnum) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.Language = (LanguageEnum)1000000; reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [StringLength(100))] // reportType.Name (String) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.Name = GetRandomString("", 101); Assert.AreEqual(false, reportTypeService.Add(reportType)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Name", "100"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); // ----------------------------------- // Is Nullable // [StringLength(1000))] // reportType.Description (String) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.Description = GetRandomString("", 1001); Assert.AreEqual(false, reportTypeService.Add(reportType)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Description", "1000"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); // ----------------------------------- // Is Nullable // [StringLength(100))] // reportType.StartOfFileName (String) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.StartOfFileName = GetRandomString("", 101); Assert.AreEqual(false, reportTypeService.Add(reportType)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "StartOfFileName", "100"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, reportTypeService.GetReportTypeList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // reportType.LastUpdateDate_UTC (DateTime) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.LastUpdateDate_UTC = new DateTime(); reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); reportType = null; reportType = GetFilledRandomReportType(""); reportType.LastUpdateDate_UTC = new DateTime(1979, 1, 1); reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // reportType.LastUpdateContactTVItemID (Int32) // ----------------------------------- reportType = null; reportType = GetFilledRandomReportType(""); reportType.LastUpdateContactTVItemID = 0; reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", reportType.LastUpdateContactTVItemID.ToString()), reportType.ValidationResults.FirstOrDefault().ErrorMessage); reportType = null; reportType = GetFilledRandomReportType(""); reportType.LastUpdateContactTVItemID = 1; reportTypeService.Add(reportType); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), reportType.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // reportType.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // reportType.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }