public void TVFile_CRUD_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVFileService tvFileService = new TVFileService(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] } TVFile tvFile = GetFilledRandomTVFile(""); // ------------------------------- // ------------------------------- // CRUD testing // ------------------------------- // ------------------------------- count = tvFileService.GetTVFileList().Count(); Assert.AreEqual(count, (from c in dbTestDB.TVFiles select c).Count()); tvFileService.Add(tvFile); if (tvFile.HasErrors) { Assert.AreEqual("", tvFile.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(true, tvFileService.GetTVFileList().Where(c => c == tvFile).Any()); tvFileService.Update(tvFile); if (tvFile.HasErrors) { Assert.AreEqual("", tvFile.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count + 1, tvFileService.GetTVFileList().Count()); tvFileService.Delete(tvFile); if (tvFile.HasErrors) { Assert.AreEqual("", tvFile.ValidationResults.FirstOrDefault().ErrorMessage); } Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); } } }
public IHttpActionResult Post([FromBody] TVFile tvFile, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVFileService tvFileService = new TVFileService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!tvFileService.Add(tvFile)) { return(BadRequest(String.Join("|||", tvFile.ValidationResults))); } else { tvFile.ValidationResults = null; return(Created <TVFile>(new Uri(Request.RequestUri, tvFile.TVFileID.ToString()), tvFile)); } } }
public void TVFile_Properties_Test() { foreach (CultureInfo culture in AllowableCulture) { ChangeCulture(culture); using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVFileService tvFileService = new TVFileService(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 = tvFileService.GetTVFileList().Count(); TVFile tvFile = GetFilledRandomTVFile(""); // ------------------------------- // ------------------------------- // Properties testing // ------------------------------- // ------------------------------- // ----------------------------------- // [Key] // Is NOT Nullable // tvFile.TVFileID (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.TVFileID = 0; tvFileService.Update(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TVFileID"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.TVFileID = 10000000; tvFileService.Update(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVFile", "TVFileID", tvFile.TVFileID.ToString()), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = File)] // tvFile.TVFileTVItemID (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.TVFileTVItemID = 0; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVFileTVItemID", tvFile.TVFileTVItemID.ToString()), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.TVFileTVItemID = 1; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "TVFileTVItemID", "File"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPEnumType] // tvFile.TemplateTVType (TVTypeEnum) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.TemplateTVType = (TVTypeEnum)1000000; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TemplateTVType"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // [CSSPExist(ExistTypeName = "ReportType", ExistPlurial = "s", ExistFieldID = "ReportTypeID", AllowableTVtypeList = )] // tvFile.ReportTypeID (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.ReportTypeID = 0; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "ReportType", "ReportTypeID", tvFile.ReportTypeID.ToString()), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // tvFile.Parameters (String) // ----------------------------------- // ----------------------------------- // Is Nullable // [Range(1980, 2050)] // tvFile.Year (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.Year = 1979; Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "1980", "2050"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.Year = 2051; Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Year", "1980", "2050"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvFile.Language (LanguageEnum) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.Language = (LanguageEnum)1000000; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvFile.FilePurpose (FilePurposeEnum) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FilePurpose = (FilePurposeEnum)1000000; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "FilePurpose"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPEnumType] // tvFile.FileType (FileTypeEnum) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FileType = (FileTypeEnum)1000000; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "FileType"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [Range(0, 100000000)] // tvFile.FileSize_kb (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FileSize_kb = -1; Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FileSize_kb", "0", "100000000"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FileSize_kb = 100000001; Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FileSize_kb", "0", "100000000"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); // ----------------------------------- // Is Nullable // tvFile.FileInfo (String) // ----------------------------------- // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // tvFile.FileCreatedDate_UTC (DateTime) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FileCreatedDate_UTC = new DateTime(); tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "FileCreatedDate_UTC"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.FileCreatedDate_UTC = new DateTime(1979, 1, 1); tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "FileCreatedDate_UTC", "1980"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is Nullable // tvFile.FromWater (Boolean) // ----------------------------------- // ----------------------------------- // Is Nullable // [StringLength(250))] // tvFile.ClientFilePath (String) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.ClientFilePath = GetRandomString("", 251); Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ClientFilePath", "250"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); // ----------------------------------- // Is NOT Nullable // [StringLength(250))] // tvFile.ServerFileName (String) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile("ServerFileName"); Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(1, tvFile.ValidationResults.Count()); Assert.IsTrue(tvFile.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "ServerFileName")).Any()); Assert.AreEqual(null, tvFile.ServerFileName); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.ServerFileName = GetRandomString("", 251); Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ServerFileName", "250"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); // ----------------------------------- // Is NOT Nullable // [StringLength(250))] // tvFile.ServerFilePath (String) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile("ServerFilePath"); Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(1, tvFile.ValidationResults.Count()); Assert.IsTrue(tvFile.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "ServerFilePath")).Any()); Assert.AreEqual(null, tvFile.ServerFilePath); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.ServerFilePath = GetRandomString("", 251); Assert.AreEqual(false, tvFileService.Add(tvFile)); Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "ServerFilePath", "250"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); Assert.AreEqual(count, tvFileService.GetTVFileList().Count()); // ----------------------------------- // Is NOT Nullable // [CSSPAfter(Year = 1980)] // tvFile.LastUpdateDate_UTC (DateTime) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.LastUpdateDate_UTC = new DateTime(); tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.LastUpdateDate_UTC = new DateTime(1979, 1, 1); tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)] // tvFile.LastUpdateContactTVItemID (Int32) // ----------------------------------- tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.LastUpdateContactTVItemID = 0; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvFile.LastUpdateContactTVItemID.ToString()), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); tvFile = null; tvFile = GetFilledRandomTVFile(""); tvFile.LastUpdateContactTVItemID = 1; tvFileService.Add(tvFile); Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), tvFile.ValidationResults.FirstOrDefault().ErrorMessage); // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvFile.HasErrors (Boolean) // ----------------------------------- // No testing requied // ----------------------------------- // Is NOT Nullable // [NotMapped] // tvFile.ValidationResults (IEnumerable`1) // ----------------------------------- // No testing requied } } }