public void RatingCurveService_PostUpdateRatingCurveDB_GetRatingCurveWithRatingCurveIDDB_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); using (ShimsContext.Create()) { //string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.GetRatingCurveWithRatingCurveIDDBInt32 = (a) => { return(null); }; RatingCurveModel ratingCurveModelret2 = UpdateRatingCurveModel(ratingCurveModelRet); Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.RatingCurve), ratingCurveModelret2.Error); } } } }
public RatingCurveValueModel AddRatingCurveValueModel() { RatingCurveModel ratingCurveModel = ratingCurveServiceTest.AddRatingCurveModel(); if (!string.IsNullOrWhiteSpace(ratingCurveModel.Error)) { return(new RatingCurveValueModel() { Error = ratingCurveModel.Error }); } ratingCurveValueModelNew.RatingCurveID = ratingCurveModel.RatingCurveID; FillRatingCurveValueModel(ratingCurveValueModelNew); RatingCurveValueModel ratingCurveValueModelRet = ratingCurveValueService.PostAddRatingCurveValueDB(ratingCurveValueModelNew); if (!string.IsNullOrWhiteSpace(ratingCurveValueModelRet.Error)) { return(ratingCurveValueModelRet); } CompareRatingCurveValueModels(ratingCurveValueModelNew, ratingCurveValueModelRet); return(ratingCurveValueModelRet); }
public void RatingCurveService_PostUpdateRatingCurveDB_DoUpdateChanges_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); using (ShimsContext.Create()) { string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.DoUpdateChanges = () => { return(ErrorText); }; RatingCurveModel ratingCurveModelret2 = UpdateRatingCurveModel(ratingCurveModelRet); Assert.AreEqual(ErrorText, ratingCurveModelret2.Error); } } } }
public void RatingCurveService_PostAddRatingCurveDB_GetTVItemModelWithTVItemIDForLocationDB_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { using (ShimsContext.Create()) { string ErrorText = "ErrorText"; SetupShim(); shimHydrometricSiteService.GetHydrometricSiteModelWithHydrometricSiteIDDBInt32 = (a) => { return(new HydrometricSiteModel() { Error = ErrorText }); }; RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.AreEqual(ErrorText, ratingCurveModelRet.Error); } } } }
public RatingCurveModel GetRatingCurveModelWithRatingCurveIDDB(int RatingCurveID) { RatingCurveModel ratingCurveModel = (from c in db.RatingCurves let tvText = (from h in db.HydrometricSites from cl in db.TVItemLanguages where h.HydrometricSiteTVItemID == cl.TVItemID && cl.Language == (int)LanguageRequest && cl.TVItemID == h.HydrometricSiteTVItemID select cl.TVText).FirstOrDefault <string>() where c.RatingCurveID == RatingCurveID select new RatingCurveModel { Error = "", RatingCurveID = c.RatingCurveID, DBCommand = (DBCommandEnum)c.DBCommand, HydrometricSiteID = c.HydrometricSiteID, HydrometricSiteTVText = tvText, RatingCurveNumber = c.RatingCurveNumber, LastUpdateDate_UTC = c.LastUpdateDate_UTC, LastUpdateContactTVItemID = c.LastUpdateContactTVItemID, }).FirstOrDefault <RatingCurveModel>(); if (ratingCurveModel == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.RatingCurve, ServiceRes.RatingCurveID, RatingCurveID))); } return(ratingCurveModel); }
public void RatingCurveService_PostDeleteRatingCurveDB_IsContactOK_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); using (ShimsContext.Create()) { string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.IsContactOK = () => { return(new ContactOK() { Error = ErrorText }); }; RatingCurveModel ratingCurveModelRet2 = ratingCurveService.PostDeleteRatingCurveDB(ratingCurve.RatingCurveID); Assert.AreEqual(ErrorText, ratingCurveModelRet2.Error); } } } }
public void RatingCurveService_FillRatingCurve_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); RatingCurve ratingCurve = new RatingCurve(); FillRatingCurveModel(ratingCurveModelRet); ContactOK contactOK = ratingCurveService.IsContactOK(); string retStr = ratingCurveService.FillRatingCurve(ratingCurve, ratingCurveModelRet, contactOK); Assert.AreEqual("", retStr); Assert.AreEqual(contactOK.ContactTVItemID, ratingCurve.LastUpdateContactTVItemID); contactOK = null; retStr = ratingCurveService.FillRatingCurve(ratingCurve, ratingCurveModelRet, contactOK); Assert.AreEqual("", retStr); Assert.AreEqual(2, ratingCurve.LastUpdateContactTVItemID); } } }
public void FillRatingCurveModel(RatingCurveModel ratingCurveModel) { ratingCurveModel.HydrometricSiteID = ratingCurveModel.HydrometricSiteID; ratingCurveModel.RatingCurveNumber = randomService.RandomString("Rating Curve", 30); Assert.IsTrue(ratingCurveModel.HydrometricSiteID != 0); Assert.IsTrue(ratingCurveModel.RatingCurveNumber.Length == 30); }
public RatingCurve GetRatingCurveExistDB(RatingCurveModel ratingCurveModel) { RatingCurve ratingCurve = (from c in db.RatingCurves where c.HydrometricSiteID == ratingCurveModel.HydrometricSiteID && c.RatingCurveNumber == ratingCurveModel.RatingCurveNumber select c).FirstOrDefault <RatingCurve>(); return(ratingCurve); }
// Post public RatingCurveModel PostAddRatingCurveDB(RatingCurveModel ratingCurveModel) { string retStr = RatingCurveModelOK(ratingCurveModel); if (!string.IsNullOrEmpty(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } HydrometricSiteModel hydrometricSiteModel = _HydrometricSiteService.GetHydrometricSiteModelWithHydrometricSiteIDDB(ratingCurveModel.HydrometricSiteID); if (!string.IsNullOrWhiteSpace(hydrometricSiteModel.Error)) { return(ReturnError(hydrometricSiteModel.Error)); } RatingCurve ratingCurveExist = GetRatingCurveExistDB(ratingCurveModel); if (ratingCurveExist != null) { return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.RatingCurve))); } RatingCurve ratingCurveNew = new RatingCurve(); retStr = FillRatingCurve(ratingCurveNew, ratingCurveModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { db.RatingCurves.Add(ratingCurveNew); retStr = DoAddChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("RatingCurves", ratingCurveNew.RatingCurveID, LogCommandEnum.Add, ratingCurveNew); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetRatingCurveModelWithRatingCurveIDDB(ratingCurveNew.RatingCurveID)); }
public void RatingCurveService_PostAddUpdateDeleteRatingDB_BadUser_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListBad[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.AreEqual(ServiceRes.NeedToBeLoggedIn, ratingCurveModelRet.Error); } } }
public void RatingCurveService_PostAddUpdateDeleteRatingDB_UserEmailNotValidated_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[2], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.AreEqual(ServiceRes.EmailRequiresValidation, ratingCurveModelRet.Error); } } }
public void SetupTest(ContactModel contactModelToDo, CultureInfo culture) { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; contactModel = contactModelToDo; user = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null); ratingCurveService = new RatingCurveService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user); testDBService = new TestDBService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user, TableName, Plurial); randomService = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user); hydrometricSiteService = new HydrometricSiteService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user); ratingCurveModelNew = new RatingCurveModel(); ratingCurve = new RatingCurve(); }
public void RatingCurveService_GetRatingCurveModelListWithHydrometricSiteTVItemIDDB_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); List <RatingCurveModel> ratingCurveModelList = ratingCurveService.GetRatingCurveModelListWithHydrometricSiteIDDB(ratingCurveModelRet.HydrometricSiteID); Assert.IsTrue(ratingCurveModelList.Where(c => c.RatingCurveID == ratingCurveModelRet.RatingCurveID).Any()); } } }
public RatingCurveModel UpdateRatingCurveModel(RatingCurveModel ratingCurveModel) { FillRatingCurveModel(ratingCurveModel); RatingCurveModel ratingCurveModelRet2 = ratingCurveService.PostUpdateRatingCurveDB(ratingCurveModel); if (!string.IsNullOrWhiteSpace(ratingCurveModelRet2.Error)) { return(ratingCurveModelRet2); } CompareRatingCurveModels(ratingCurveModel, ratingCurveModelRet2); return(ratingCurveModelRet2); }
public void RatingCurveService_GetRatingCurveModelCountDB_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); int ratingCurveCount = ratingCurveService.GetRatingCurveModelCountDB(); Assert.AreEqual(testDBService.Count + 1, ratingCurveCount); } } }
public RatingCurveModel PostUpdateRatingCurveDB(RatingCurveModel ratingCurveModel) { string retStr = RatingCurveModelOK(ratingCurveModel); if (!string.IsNullOrEmpty(retStr)) { return(ReturnError(retStr)); } ContactOK contactOK = IsContactOK(); if (!string.IsNullOrEmpty(contactOK.Error)) { return(ReturnError(contactOK.Error)); } RatingCurve ratingCurveToUpdate = GetRatingCurveWithRatingCurveIDDB(ratingCurveModel.RatingCurveID); if (ratingCurveToUpdate == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.RatingCurve))); } retStr = FillRatingCurve(ratingCurveToUpdate, ratingCurveModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { retStr = DoUpdateChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("RatingCurves", ratingCurveToUpdate.RatingCurveID, LogCommandEnum.Change, ratingCurveToUpdate); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetRatingCurveModelWithRatingCurveIDDB(ratingCurveToUpdate.RatingCurveID)); }
// Fill public string FillRatingCurve(RatingCurve ratingCurveNew, RatingCurveModel ratingCurveModel, ContactOK contactOK) { ratingCurveNew.DBCommand = (int)ratingCurveModel.DBCommand; ratingCurveNew.HydrometricSiteID = ratingCurveModel.HydrometricSiteID; ratingCurveNew.RatingCurveNumber = ratingCurveModel.RatingCurveNumber; ratingCurveNew.LastUpdateDate_UTC = DateTime.UtcNow; if (contactOK == null) { ratingCurveNew.LastUpdateContactTVItemID = 2; } else { ratingCurveNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID; } return(""); }
public void RatingCurveService_PostAddUpdateDeleteRatingCurveDB_Good_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); RatingCurveModel ratingCurveModelRet2 = UpdateRatingCurveModel(ratingCurveModelRet); RatingCurveModel ratingCurveModelRet3 = ratingCurveService.PostDeleteRatingCurveDB(ratingCurveModelRet2.RatingCurveID); Assert.AreEqual("", ratingCurveModelRet3.Error); } } }
public void RatingCurveService_GetRatingCurveModelWithRatingCurveIDDB_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); RatingCurveModel ratingCurveModelRet2 = ratingCurveService.GetRatingCurveModelWithRatingCurveIDDB(ratingCurveModelRet.RatingCurveID); Assert.AreEqual(ratingCurveModelRet.RatingCurveID, ratingCurveModelRet2.RatingCurveID); int RatingCurveID = 0; ratingCurveModelRet2 = ratingCurveService.GetRatingCurveModelWithRatingCurveIDDB(RatingCurveID); Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.RatingCurve, ServiceRes.RatingCurveID, RatingCurveID), ratingCurveModelRet2.Error); } } }
public void RatingCurveService_GetRatingCurveExistDB_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); RatingCurve ratingCurveRet = ratingCurveService.GetRatingCurveExistDB(ratingCurveModelRet); Assert.AreEqual(ratingCurveModelRet.RatingCurveID, ratingCurveRet.RatingCurveID); ratingCurveModelRet.HydrometricSiteID = 0; ratingCurveRet = ratingCurveService.GetRatingCurveExistDB(ratingCurveModelRet); Assert.IsNull(ratingCurveRet); } } }
// Check public string RatingCurveModelOK(RatingCurveModel ratingCurveModel) { string retStr = FieldCheckNotZeroInt(ratingCurveModel.HydrometricSiteID, ServiceRes.HydrometricSiteID); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = FieldCheckNotEmptyAndMaxLengthString(ratingCurveModel.RatingCurveNumber, ServiceRes.RatingCurveNumber, 50); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } retStr = _BaseEnumService.DBCommandOK(ratingCurveModel.DBCommand); if (!string.IsNullOrWhiteSpace(retStr)) { return(retStr); } return(""); }
public void RatingCurveService_PostAddRatingCurveDB_GetRatingCurveExistDB_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { using (ShimsContext.Create()) { //string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.GetRatingCurveExistDBRatingCurveModel = (a) => { return(new RatingCurve()); }; RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.AreEqual(string.Format(ServiceRes._AlreadyExists, ServiceRes.RatingCurve), ratingCurveModelRet.Error); } } } }
public void RatingCurveService_PostAddRatingCurveDB_FillRatingCurveModel_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { using (ShimsContext.Create()) { string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.FillRatingCurveRatingCurveRatingCurveModelContactOK = (a, b, c) => { return(ErrorText); }; RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.AreEqual(ErrorText, ratingCurveModelRet.Error); } } } }
public void RatingCurveService_PostAddRatingCurveDB_Add_Error_Test() { foreach (CultureInfo culture in setupData.cultureListGood) { SetupTest(contactModelListGood[0], culture); using (TransactionScope ts = new TransactionScope()) { using (ShimsContext.Create()) { //string ErrorText = "ErrorText"; SetupShim(); shimRatingCurveService.FillRatingCurveRatingCurveRatingCurveModelContactOK = (a, b, c) => { return(""); }; RatingCurveModel ratingCurveModelRet = AddRatingCurveModel(); Assert.IsTrue(ratingCurveModelRet.Error.StartsWith(string.Format(ServiceRes.CouldNotAddError_, "").Substring(0, 10))); } } } }
public RatingCurveModel AddRatingCurveModel() { TVItemModel tvItemModel = randomService.RandomTVItem(TVTypeEnum.HydrometricSite); Assert.AreEqual("", tvItemModel.Error); HydrometricSiteModel hydrometricSiteModel = hydrometricSiteService.GetHydrometricSiteModelWithHydrometricSiteTVItemIDDB(tvItemModel.TVItemID); Assert.AreEqual("", hydrometricSiteModel.Error); ratingCurveModelNew.HydrometricSiteID = hydrometricSiteModel.HydrometricSiteID; FillRatingCurveModel(ratingCurveModelNew); RatingCurveModel ratingCurveModelRet = ratingCurveService.PostAddRatingCurveDB(ratingCurveModelNew); if (!string.IsNullOrWhiteSpace(ratingCurveModelRet.Error)) { return(ratingCurveModelRet); } CompareRatingCurveModels(ratingCurveModelNew, ratingCurveModelRet); return(ratingCurveModelRet); }
public void CompareRatingCurveModels(RatingCurveModel ratingCurveModelNew, RatingCurveModel ratingCurveModelRet) { Assert.AreEqual(ratingCurveModelNew.HydrometricSiteID, ratingCurveModelRet.HydrometricSiteID); Assert.AreEqual(ratingCurveModelNew.RatingCurveNumber, ratingCurveModelRet.RatingCurveNumber); }