Esempio n. 1
0
        public void TideDataValueService_PostDeleteTideDataValueDB_IsContactOK_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        string ErrorText = "ErrorText";
                        shimTideDataValueService.IsContactOK = () =>
                        {
                            return(new ContactOK()
                            {
                                Error = ErrorText
                            });
                        };

                        TideDataValueModel tideDataValueModelRet2 = tideDataValueService.PostDeleteTideDataValueDB(tideDataValueModelRet.TideDataValueID);
                        Assert.AreEqual(ErrorText, tideDataValueModelRet2.Error);
                    }
                }
            }
        }
        public TideDataValueModel GetTideDataValueModelExistDB(TideDataValueModel tideDataValueModel)
        {
            TideDataValueModel TideDataValueModel = (from c in db.TideDataValues
                                                     where c.TideSiteTVItemID == tideDataValueModel.TideSiteTVItemID &&
                                                     c.DateTime_Local == tideDataValueModel.DateTime_Local
                                                     select new TideDataValueModel
            {
                Error = "",
                TideSiteTVItemID = c.TideSiteTVItemID,
                DBCommand = (DBCommandEnum)c.DBCommand,
                TideDataValueID = c.TideDataValueID,
                DateTime_Local = c.DateTime_Local,
                Keep = c.Keep,
                TideDataType = (TideDataTypeEnum)c.TideDataType,
                StorageDataType = (StorageDataTypeEnum)c.StorageDataType,
                TideEnd = (TideTextEnum)c.TideEnd,
                TideStart = (TideTextEnum)c.TideStart,
                Depth_m = c.Depth_m,
                UVelocity_m_s = c.UVelocity_m_s,
                VVelocity_m_s = c.VVelocity_m_s,
                LastUpdateDate_UTC = c.LastUpdateDate_UTC,
                LastUpdateContactTVItemID = c.LastUpdateContactTVItemID,
            }).FirstOrDefault <TideDataValueModel>();

            if (TideDataValueModel == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.TideDataValue, ServiceRes.TideSiteTVItemID + "," + ServiceRes.DateTime_Local, tideDataValueModel.TideSiteTVItemID + "," + tideDataValueModel.DateTime_Local)));
            }

            return(TideDataValueModel);
        }
Esempio n. 3
0
        public void TideDataValueService_PostUpdateTideDataValueDB_GetTideDataValueWithTideDataValueIDDB_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        //string ErrorText = "ErrorText";
                        shimTideDataValueService.GetTideDataValueWithTideDataValueIDDBInt32 = (a) =>
                        {
                            return(null);
                        };

                        TideDataValueModel tideDataValueModelRet2 = UpdateTideDataValue(tideDataValueModelRet);
                        Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.TideDataValue), tideDataValueModelRet2.Error);
                    }
                }
            }
        }
Esempio n. 4
0
        public void TideDataValueService_PostUpdateTideDataValueDB_DoUpdateChanges_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        string ErrorText = "ErrorText";
                        shimTideDataValueService.DoUpdateChanges = () =>
                        {
                            return(ErrorText);
                        };

                        TideDataValueModel tideDataValueModelRet2 = UpdateTideDataValue(tideDataValueModelRet);
                        Assert.AreEqual(ErrorText, tideDataValueModelRet2.Error);
                    }
                }
            }
        }
Esempio n. 5
0
        public void TideDataValueService_PostAddTideDataValueDB_GetTideDataValueModelExistDB_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        //string ErrorText = "ErrorText";
                        shimTideDataValueService.GetTideDataValueModelExistDBTideDataValueModel = (a) =>
                        {
                            return(new TideDataValueModel()
                            {
                                Error = ""
                            });
                        };

                        TideDataValueModel tideDataValueModelRet = AddTideDataValue();
                        Assert.AreEqual(string.Format(ServiceRes._AlreadyExists, ServiceRes.TideDataValue), tideDataValueModelRet.Error);
                    }
                }
            }
        }
        // Fill
        public string FillTideDataValue(TideDataValue tideDataValueNew, TideDataValueModel tideDataValueModel, ContactOK contactOK)
        {
            tideDataValueNew.DBCommand          = (int)tideDataValueModel.DBCommand;
            tideDataValueNew.TideSiteTVItemID   = tideDataValueModel.TideSiteTVItemID;
            tideDataValueNew.DateTime_Local     = tideDataValueModel.DateTime_Local;
            tideDataValueNew.Keep               = tideDataValueModel.Keep;
            tideDataValueNew.TideDataType       = (int)tideDataValueModel.TideDataType;
            tideDataValueNew.StorageDataType    = (int)tideDataValueModel.StorageDataType;
            tideDataValueNew.Depth_m            = tideDataValueModel.Depth_m;
            tideDataValueNew.UVelocity_m_s      = tideDataValueModel.UVelocity_m_s;
            tideDataValueNew.VVelocity_m_s      = tideDataValueModel.VVelocity_m_s;
            tideDataValueNew.TideEnd            = (int?)tideDataValueModel.TideEnd;
            tideDataValueNew.TideStart          = (int?)tideDataValueModel.TideStart;
            tideDataValueNew.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                tideDataValueNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                tideDataValueNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
        // Check
        public string TideDataValueModelOK(TideDataValueModel tideDataValueModel)
        {
            string retStr = FieldCheckNotZeroInt(tideDataValueModel.TideSiteTVItemID, ServiceRes.TideSiteTVItemID);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckNotNullDateTime(tideDataValueModel.DateTime_Local, ServiceRes.DateTime_Local);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckNotNullBool(tideDataValueModel.Keep, ServiceRes.Keep);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.TideDataTypeOK(tideDataValueModel.TideDataType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.StorageDataTypeOK(tideDataValueModel.StorageDataType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckIfNotNullWithinRangeDouble(tideDataValueModel.Depth_m, ServiceRes.Depth_m, -10, 10);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckIfNotNullWithinRangeDouble(tideDataValueModel.UVelocity_m_s, ServiceRes.UVelocity_m_s, -10, 10);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckIfNotNullWithinRangeDouble(tideDataValueModel.VVelocity_m_s, ServiceRes.VVelocity_m_s, -10, 10);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.DBCommandOK(tideDataValueModel.DBCommand);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }
            return("");
        }
Esempio n. 8
0
 private void CompareTideDataValueModels(TideDataValueModel tideDataValueModelNew, TideDataValueModel tideDataValueModelRet)
 {
     Assert.AreEqual(tideDataValueModelNew.TideSiteTVItemID, tideDataValueModelRet.TideSiteTVItemID);
     Assert.AreEqual(tideDataValueModelNew.DateTime_Local, tideDataValueModelRet.DateTime_Local);
     Assert.AreEqual(tideDataValueModelNew.Keep, tideDataValueModelRet.Keep);
     Assert.AreEqual(tideDataValueModelNew.TideDataType, tideDataValueModelRet.TideDataType);
     Assert.AreEqual(tideDataValueModelNew.StorageDataType, tideDataValueModelRet.StorageDataType);
     Assert.AreEqual(tideDataValueModelNew.Depth_m, tideDataValueModelRet.Depth_m);
     Assert.AreEqual(tideDataValueModelNew.UVelocity_m_s, tideDataValueModelRet.UVelocity_m_s);
     Assert.AreEqual(tideDataValueModelNew.VVelocity_m_s, tideDataValueModelRet.VVelocity_m_s);
 }
        // Post
        public TideDataValueModel PostAddTideDataValueDB(TideDataValueModel tideDataValueModel)
        {
            string retStr = TideDataValueModelOK(tideDataValueModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            TideDataValueModel tideDataValueModelExist = GetTideDataValueModelExistDB(tideDataValueModel);

            if (string.IsNullOrWhiteSpace(tideDataValueModelExist.Error))
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.TideDataValue)));
            }

            TideDataValue tideDataValueNew = new TideDataValue();

            retStr = FillTideDataValue(tideDataValueNew, tideDataValueModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.TideDataValues.Add(tideDataValueNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("TideDataValues", tideDataValueNew.TideDataValueID, LogCommandEnum.Add, tideDataValueNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            return(GetTideDataValueModelWithTideDataValueIDDB(tideDataValueNew.TideDataValueID));
        }
Esempio n. 10
0
        public void TideDataValueService_ReturnError_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    string             ErrorText             = "ErrorText";
                    TideDataValueModel tideDataValueModelRet = tideDataValueService.ReturnError(ErrorText);
                    Assert.AreEqual(ErrorText, tideDataValueModelRet.Error);
                }
            }
        }
Esempio n. 11
0
        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);
            tideDataValueService  = new TideDataValueService((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);
            tideDataValueModelNew = new TideDataValueModel();
            tideDataValue         = new TideDataValue();
            tideSiteServiceTest   = new TideSiteServiceTest();
            tideSiteServiceTest.SetupTest(contactModelToDo, culture);
        }
Esempio n. 12
0
        public void TideDataValueService_GetTideDataValueModelCountDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    int tideDataValueCount = tideDataValueService.GetTideDataValueModelCountDB();
                    Assert.AreEqual(testDBService.Count + 1, tideDataValueCount);
                }
            }
        }
Esempio n. 13
0
        public void TideDataValueService_GetTideDataValueWithTideDataValueIDDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    TideDataValue tideDataValueRet = tideDataValueService.GetTideDataValueWithTideDataValueIDDB(tideDataValueModelRet.TideDataValueID);
                    Assert.AreEqual(tideDataValueModelRet.TideDataValueID, tideDataValueRet.TideDataValueID);
                }
            }
        }
Esempio n. 14
0
        private TideDataValueModel UpdateTideDataValue(TideDataValueModel tideDataValueModelRet)
        {
            FillTideDataValueModel(tideDataValueModelRet);

            TideDataValueModel tideDataValueModelRet2 = tideDataValueService.PostUpdateTideDataValueDB(tideDataValueModelRet);

            if (!string.IsNullOrWhiteSpace(tideDataValueModelRet2.Error))
            {
                return(tideDataValueModelRet2);
            }

            Assert.IsNotNull(tideDataValueModelRet2);
            CompareTideDataValueModels(tideDataValueModelRet, tideDataValueModelRet2);

            return(tideDataValueModelRet2);
        }
Esempio n. 15
0
        public TideDataValueModel PostUpdateTideDataValueDB(TideDataValueModel tideDataValueModel)
        {
            string retStr = TideDataValueModelOK(tideDataValueModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            TideDataValue tideDataValueToUpdate = GetTideDataValueWithTideDataValueIDDB(tideDataValueModel.TideDataValueID);

            if (tideDataValueToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.TideDataValue)));
            }

            retStr = FillTideDataValue(tideDataValueToUpdate, tideDataValueModel, 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("TideDataValues", tideDataValueToUpdate.TideDataValueID, LogCommandEnum.Change, tideDataValueToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetTideDataValueModelWithTideDataValueIDDB(tideDataValueToUpdate.TideDataValueID));
        }
Esempio n. 16
0
        public void TideDataValueService_PostAddUpdateDeleteTideDataValueDB_Good_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    TideDataValueModel tideDataValueModelRet2 = UpdateTideDataValue(tideDataValueModelRet);

                    TideDataValueModel tideDataValueModelRet3 = tideDataValueService.PostDeleteTideDataValueDB(tideDataValueModelRet2.TideDataValueID);
                    Assert.AreEqual("", tideDataValueModelRet3.Error);
                }
            }
        }
Esempio n. 17
0
        private TideDataValueModel AddTideDataValue()
        {
            TideSiteModel tideDataStartDateModelRet = tideSiteServiceTest.AddTideSiteModel();

            tideDataValueModelNew.TideSiteTVItemID = tideDataStartDateModelRet.TideSiteTVItemID;
            FillTideDataValueModel(tideDataValueModelNew);

            TideDataValueModel tideDataValueModelRet = tideDataValueService.PostAddTideDataValueDB(tideDataValueModelNew);

            if (!string.IsNullOrWhiteSpace(tideDataValueModelRet.Error))
            {
                return(tideDataValueModelRet);
            }

            Assert.IsNotNull(tideDataValueModelRet);
            CompareTideDataValueModels(tideDataValueModelNew, tideDataValueModelRet);

            return(tideDataValueModelRet);
        }
Esempio n. 18
0
        public void TideDataValueService_GetTideDataValueModelWithTideDataValueIDDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    TideDataValueModel tideDataValueModelRet2 = tideDataValueService.GetTideDataValueModelWithTideDataValueIDDB(tideDataValueModelRet.TideDataValueID);

                    CompareTideDataValueModels(tideDataValueModelRet, tideDataValueModelRet2);

                    int TideDataValueID = 0;
                    TideDataValueModel tideDataValueModelRet3 = tideDataValueService.GetTideDataValueModelWithTideDataValueIDDB(TideDataValueID);
                    Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.TideDataValue, ServiceRes.TideDataValueID, TideDataValueID), tideDataValueModelRet3.Error);
                }
            }
        }
Esempio n. 19
0
        private void FillTideDataValueModel(TideDataValueModel tideDataValueModelRet)
        {
            tideDataValueModelRet.TideSiteTVItemID = tideDataValueModelRet.TideSiteTVItemID;
            tideDataValueModelRet.DateTime_Local   = randomService.RandomDateTime();
            tideDataValueModelRet.Keep             = true;
            tideDataValueModelRet.TideDataType     = TideDataTypeEnum.Min60;
            tideDataValueModelRet.StorageDataType  = StorageDataTypeEnum.Archived;
            tideDataValueModelRet.Depth_m          = randomService.RandomDouble(-10, 10);
            tideDataValueModelRet.UVelocity_m_s    = randomService.RandomDouble(-10, 10);
            tideDataValueModelRet.VVelocity_m_s    = randomService.RandomDouble(-10, 10);

            Assert.IsTrue(tideDataValueModelRet.TideSiteTVItemID != 0);
            Assert.IsTrue(tideDataValueModelRet.DateTime_Local != null);
            Assert.IsTrue(tideDataValueModelRet.Keep == true);
            Assert.IsTrue(tideDataValueModelRet.TideDataType == TideDataTypeEnum.Min60);
            Assert.IsTrue(tideDataValueModelRet.StorageDataType == StorageDataTypeEnum.Archived);
            Assert.IsTrue(tideDataValueModelRet.Depth_m >= -10 && tideDataValueModelRet.Depth_m <= 10);
            Assert.IsTrue(tideDataValueModelRet.UVelocity_m_s >= -10 && tideDataValueModelRet.UVelocity_m_s <= 10);
            Assert.IsTrue(tideDataValueModelRet.VVelocity_m_s >= -10 && tideDataValueModelRet.VVelocity_m_s <= 10);
        }
Esempio n. 20
0
        public void TideDataValueService_GetTideDataValueModelExistDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();

                    TideDataValueModel tideDataValueModelRet2 = tideDataValueService.GetTideDataValueModelExistDB(tideDataValueModelRet);

                    CompareTideDataValueModels(tideDataValueModelRet, tideDataValueModelRet2);

                    tideDataValueModelRet2.TideSiteTVItemID = 0;
                    TideDataValueModel tideDataValueModelRet3 = tideDataValueService.GetTideDataValueModelExistDB(tideDataValueModelRet2);
                    Assert.AreEqual(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.TideDataValue, ServiceRes.TideSiteTVItemID + "," + ServiceRes.DateTime_Local, tideDataValueModelRet2.TideSiteTVItemID + "," + tideDataValueModelRet2.DateTime_Local), tideDataValueModelRet3.Error);
                }
            }
        }
Esempio n. 21
0
        public void TideDataValueService_PostAddDeleteTideDataValueDB_UserEmailNotValidated_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideSiteModel tideSiteModelRet = tideSiteServiceTest.AddTideSiteModel();

                    SetupTest(contactModelListGood[2], culture);

                    tideDataValueModelNew.TideSiteTVItemID = tideSiteModelRet.TideSiteTVItemID;

                    FillTideDataValueModel(tideDataValueModelNew);

                    TideDataValueModel tideDataValueModelRet2 = tideDataValueService.PostAddTideDataValueDB(tideDataValueModelNew);
                    Assert.AreEqual(ServiceRes.EmailRequiresValidation, tideDataValueModelRet2.Error);
                }
            }
        }
Esempio n. 22
0
        public void TideDataValueService_PostAddTideDataValueDB_BadUser_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideSiteModel tideSiteModelRet = tideSiteServiceTest.AddTideSiteModel();

                    SetupTest(contactModelListBad[0], culture);

                    tideDataValueModelNew.TideSiteTVItemID = tideSiteModelRet.TideSiteTVItemID;

                    FillTideDataValueModel(tideDataValueModelNew);

                    TideDataValueModel tideDataValueModelRet2 = tideDataValueService.PostAddTideDataValueDB(tideDataValueModelNew);
                    Assert.AreEqual(ServiceRes.NeedToBeLoggedIn, tideDataValueModelRet2.Error);
                }
            }
        }
Esempio n. 23
0
        public void TideDataValueService_PostAddTideDataValueDB_Add_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        //string ErrorText = "ErrorText";
                        shimTideDataValueService.FillTideDataValueTideDataValueTideDataValueModelContactOK = (a, b, c) =>
                        {
                            return("");
                        };

                        TideDataValueModel tideDataValueModelRet = AddTideDataValue();
                        Assert.IsTrue(tideDataValueModelRet.Error.StartsWith(string.Format(ServiceRes.CouldNotAddError_, "").Substring(0, 10)));
                    }
                }
            }
        }
Esempio n. 24
0
        public void TideDataValueService_PostAddTideDataValueDB_FillTideDataValueModel_Error_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    using (ShimsContext.Create())
                    {
                        SetupShim();
                        string ErrorText = "ErrorText";
                        shimTideDataValueService.FillTideDataValueTideDataValueTideDataValueModelContactOK = (a, b, c) =>
                        {
                            return(ErrorText);
                        };

                        TideDataValueModel tideDataValueModelRet = AddTideDataValue();
                        Assert.AreEqual(ErrorText, tideDataValueModelRet.Error);
                    }
                }
            }
        }
        private void GenerateSubsectorFaecalColiformDensitiesDocument(Document document)
        {
            Body      body      = new Body();
            Paragraph paragraph = new Paragraph();
            Run       run       = new Run();
            Table     table     = new Table();
            TableRow  tableRow  = new TableRow();
            TableCell tableCell = new TableCell();
            //string URL = "";

            BaseEnumService      baseEnumService      = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService        tvItemService        = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TVItemStatService    tvItemStatService    = new TVItemStatService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MWQMSampleService    mwqmSampleService    = new MWQMSampleService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MWQMSiteService      mwqmSiteService      = new MWQMSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TideSiteService      tideSiteService      = new TideSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TideDataValueService tideDataValueService = new TideDataValueService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            TVItemModel tvItemModelSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
            {
                paragraph = DocxBase.AddParagraph(body);
                DocxBase.AddRunWithCurrentParagraphStyle(paragraph, tvItemModelSubsector.Error);
            }

            //tvItemStatService.SetTVItemStatForTVItemIDAndParentsTVItemID(tvItemModelSubsector.TVItemID);

            TVItemModel tvItemModelTideSite = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.TideSite).FirstOrDefault();

            if (tvItemModelTideSite == null)
            {
                if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
                {
                    paragraph = DocxBase.AddParagraph(body);
                    DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.CoundNotFindTideSite);
                    return;
                }
            }

            List <TVItemModel> tvItemModelMWQMList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite);

            List <StationDateValue> stationDateValueList = new List <StationDateValue>();
            List <DateTime>         DateWithDataList     = new List <DateTime>();
            List <string>           StationList          = new List <string>();

            foreach (TVItemModel tvItemModelMWQM in tvItemModelMWQMList)
            {
                string Station = mwqmSiteService.GetMWQMSiteModelWithMWQMSiteTVItemIDDB(tvItemModelMWQM.TVItemID).MWQMSiteNumber;

                StationList.Add(Station);

                List <MWQMSampleModel> mwqmSampleModelList = mwqmSampleService.GetMWQMSampleModelListWithMWQMSiteTVItemIDDB(tvItemModelMWQM.TVItemID);

                foreach (MWQMSampleModel mwqmSampleModel in mwqmSampleModelList.OrderByDescending(c => c.SampleDateTime_Local))
                {
                    StationDateValue stationDateValue = new StationDateValue()
                    {
                        Station = Station,
                        Date    = new DateTime(mwqmSampleModel.SampleDateTime_Local.Year, mwqmSampleModel.SampleDateTime_Local.Month, mwqmSampleModel.SampleDateTime_Local.Day),
                        Value   = mwqmSampleModel.FecCol_MPN_100ml,
                    };

                    if (!DateWithDataList.Contains(stationDateValue.Date))
                    {
                        DateWithDataList.Add(stationDateValue.Date);
                    }

                    stationDateValueList.Add(stationDateValue);
                }
            }

            DateWithDataList = DateWithDataList.OrderBy(c => c).ToList();
            StationList      = StationList.OrderBy(c => c).ToList();

            for (int i = 0, count = DateWithDataList.Count; i < count; i = i + 15)
            {
                DocxBase.CurrentFontName           = FontNameEnum.Arial;
                DocxBase.CurrentFontSize           = 16;
                DocxBase.CurrentParagraphStyle     = ParagraphStyleEnum.Caption;
                DocxBase.CurrentJustificationValue = JustificationValues.Left;
                paragraph = DocxBase.AddParagraph(body);
                paragraph = DocxBase.AddParagraph(body);

                string TableTitle = DocxServiceSubsectorFCDensitiesRes.Table + "1B-" + ((int)(i / 15) + 1).ToString() + "." + DocxServiceSubsectorFCDensitiesRes.FaecalColiformDensitiesMPNPer100 +
                                    " " + DocxServiceSubsectorFCDensitiesRes.For + " " + tvItemModelSubsector.TVText;
                run = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, TableTitle);

                DocxBase.CurrentTableStyle = TableStyleEnum.PlainTable1;
                DocxBase.CurrentFontName   = FontNameEnum.Arial;
                DocxBase.CurrentFontSize   = 10;
                table    = DocxBase.AddTableStyle(body);
                tableRow = DocxBase.AddTableRow(table);

                List <DateTime> dateTimeNext15 = (from c in DateWithDataList
                                                  where c >= DateWithDataList[i]
                                                  select c).Take(15).ToList <DateTime>();

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, " ");
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Station);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, dateTime.ToString("yyyy"));
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, dateTime.ToString("dd MMM"));
                }

                List <StationDateValue> StationDateValueDataList = (from c in stationDateValueList
                                                                    orderby c.Station
                                                                    select c).ToList <StationDateValue>();

                foreach (string station in StationList)
                {
                    tableRow = DocxBase.AddTableRow(table);

                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, station);

                    foreach (DateTime dateTime in dateTimeNext15)
                    {
                        StationDateValue stationDateValueForDate = (from c in stationDateValueList
                                                                    where c.Station == station &&
                                                                    c.Date.Year == dateTime.Year &&
                                                                    c.Date.Month == dateTime.Month &&
                                                                    c.Date.Day == dateTime.Day
                                                                    select c).FirstOrDefault();

                        tableCell = DocxBase.AddTableCell(tableRow);
                        paragraph = DocxBase.AddTableCellParagraph(tableCell);
                        run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, (stationDateValueForDate == null ? " " : (stationDateValueForDate.Value < 2 ? "<2" : stationDateValueForDate.Value.ToString("F0"))));
                    }
                }

                // Tide Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Tide);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    TideDataValueModel tideDataValueModel = tideDataValueService.GetTideDataValueModelWithTideSiteTVItemIDAndDateDB(tvItemModelTideSite.TVItemID, dateTime);

                    string TideStartAccronym = GetTideTextAccronym(tideDataValueModel.TideStart);
                    string TideEndAccronym   = GetTideTextAccronym(tideDataValueModel.TideEnd);

                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, TideStartAccronym + "-" + TideEndAccronym);
                }

                // Rain (mm) Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes.Rain_mm);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "");
                }

                // 0-24 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_24h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }

                // 0-48 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_48h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }

                // 0-72 h Row
                tableRow = DocxBase.AddTableRow(table);

                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, DocxServiceSubsectorFCDensitiesRes._0_72h);

                foreach (DateTime dateTime in dateTimeNext15)
                {
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "ToDo");
                }
            }


            DocxBase.CurrentParagraphStyle = ParagraphStyleEnum.Quote;
            paragraph = DocxBase.AddParagraph(body);
            string NoteTxt = DocxServiceSubsectorFCDensitiesRes.Note + " : ";

            for (int i = 1, count = Enum.GetNames(typeof(TideTextEnum)).Length; i < count; i++)
            {
                NoteTxt = GetTideTextAccronym((TideTextEnum)i) + " = " + baseEnumService.GetEnumText_TideTextEnum((TideTextEnum)i) + " | ";
            }

            DocxBase.AddRunWithCurrentParagraphStyle(paragraph, NoteTxt);

            DocxBase.AddSectionProp(body);

            document.Append(body);
        }
Esempio n. 26
0
        public void TideDataValueService_TideDataValueModelOK_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    TideDataValueModel tideDataValueModelRet = AddTideDataValue();
                    Assert.AreEqual("", tideDataValueModelRet.Error);

                    #region Good
                    tideDataValueModelNew.TideSiteTVItemID = tideDataValueModelRet.TideSiteTVItemID;
                    FillTideDataValueModel(tideDataValueModelNew);

                    string retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion Good

                    #region TideSiteTVItemID
                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.TideSiteTVItemID = 0;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._IsRequired, ServiceRes.TideSiteTVItemID), retStr);

                    tideDataValueModelNew.TideSiteTVItemID = tideDataValueModelRet.TideSiteTVItemID;
                    FillTideDataValueModel(tideDataValueModelNew);

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion TideSiteTVItemID

                    #region TideDataDateTime_Local
                    FillTideDataValueModel(tideDataValueModelNew);
                    using (ShimsContext.Create())
                    {
                        string ErrorText = "ErrorText";
                        SetupShim();
                        shimTideDataValueService.FieldCheckNotNullDateTimeNullableOfDateTimeString = (a, b) =>
                        {
                            return(ErrorText);
                        };

                        tideDataValueModelNew.DateTime_Local = DateTime.Now;
                        retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                        Assert.AreEqual(ErrorText, retStr);
                    }
                    #endregion TideDataDateTime_Local

                    #region Keep
                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Keep = false;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Keep = true;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion Keep

                    #region TideDataType
                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.TideDataType = (TideDataTypeEnum)1000;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._IsRequired, ServiceRes.TideDataType), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.TideDataType = TideDataTypeEnum.Min60;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion TideDataType

                    #region StorageDataType
                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.StorageDataType = (StorageDataTypeEnum)1000;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._IsRequired, ServiceRes.StorageDataType), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.StorageDataType = StorageDataTypeEnum.Archived;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion StorageDataType

                    #region Depth_m
                    FillTideDataValueModel(tideDataValueModelNew);
                    double Min = -10D;
                    double Max = 10D;
                    tideDataValueModelNew.Depth_m = Min - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.Depth_m, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Depth_m = Max + 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.Depth_m, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Depth_m = Max - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Depth_m = Min;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.Depth_m = Max;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion Depth_m

                    #region UVelocity_m_s
                    FillTideDataValueModel(tideDataValueModelNew);
                    Min = -10D;
                    Max = 10D;
                    tideDataValueModelNew.UVelocity_m_s = Min - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.UVelocity_m_s, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.UVelocity_m_s = Max + 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.UVelocity_m_s, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.UVelocity_m_s = Max - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.UVelocity_m_s = Min;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.UVelocity_m_s = Max;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion UVelocity_m_s

                    #region VVelocity_m_s
                    FillTideDataValueModel(tideDataValueModelNew);
                    Min = -10D;
                    Max = 10D;
                    tideDataValueModelNew.VVelocity_m_s = Min - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.VVelocity_m_s, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.VVelocity_m_s = Max + 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual(string.Format(ServiceRes._RangeIsBetween_And_, ServiceRes.VVelocity_m_s, Min, Max), retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.VVelocity_m_s = Max - 1;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.VVelocity_m_s = Min;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);

                    FillTideDataValueModel(tideDataValueModelNew);
                    tideDataValueModelNew.VVelocity_m_s = Max;

                    retStr = tideDataValueService.TideDataValueModelOK(tideDataValueModelNew);
                    Assert.AreEqual("", retStr);
                    #endregion VVelocity_m_s
                }
            }
        }