public IHttpActionResult GetHydrometricDataValueList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                      [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
 {
     using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
     {
         HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
         {
             Lang = lang
         }, db, ContactID);
예제 #2
0
        public void HydrometricDataValue_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HydrometricDataValueController hydrometricDataValueController = new HydrometricDataValueController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(hydrometricDataValueController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, hydrometricDataValueController.DatabaseType);

                    HydrometricDataValue hydrometricDataValueLast = new HydrometricDataValue();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(query, db, ContactID);
                        hydrometricDataValueLast = (from c in db.HydrometricDataValues select c).FirstOrDefault();
                    }

                    // ok with HydrometricDataValue info
                    IHttpActionResult jsonRet = hydrometricDataValueController.GetHydrometricDataValueWithID(hydrometricDataValueLast.HydrometricDataValueID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <HydrometricDataValue> Ret = jsonRet as OkNegotiatedContentResult <HydrometricDataValue>;
                    HydrometricDataValue hydrometricDataValueRet         = Ret.Content;
                    Assert.AreEqual(hydrometricDataValueLast.HydrometricDataValueID, hydrometricDataValueRet.HydrometricDataValueID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = hydrometricDataValueController.Put(hydrometricDataValueRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet2 = jsonRet2 as OkNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNotNull(hydrometricDataValueRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because HydrometricDataValueID of 0 does not exist
                    hydrometricDataValueRet.HydrometricDataValueID = 0;
                    IHttpActionResult jsonRet3 = hydrometricDataValueController.Put(hydrometricDataValueRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet3 = jsonRet3 as OkNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNull(hydrometricDataValueRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
        public void HydrometricDataValue_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(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]
                    }

                    HydrometricDataValue hydrometricDataValue = GetFilledRandomHydrometricDataValue("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

                    count = hydrometricDataValueService.GetHydrometricDataValueList().Count();

                    Assert.AreEqual(count, (from c in dbTestDB.HydrometricDataValues select c).Count());

                    hydrometricDataValueService.Add(hydrometricDataValue);
                    if (hydrometricDataValue.HasErrors)
                    {
                        Assert.AreEqual("", hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, hydrometricDataValueService.GetHydrometricDataValueList().Where(c => c == hydrometricDataValue).Any());
                    hydrometricDataValueService.Update(hydrometricDataValue);
                    if (hydrometricDataValue.HasErrors)
                    {
                        Assert.AreEqual("", hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, hydrometricDataValueService.GetHydrometricDataValueList().Count());
                    hydrometricDataValueService.Delete(hydrometricDataValue);
                    if (hydrometricDataValue.HasErrors)
                    {
                        Assert.AreEqual("", hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());
                }
            }
        }
        public IHttpActionResult GetHydrometricDataValueWithID([FromUri] int HydrometricDataValueID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                hydrometricDataValueService.Query = hydrometricDataValueService.FillQuery(typeof(HydrometricDataValue), lang, 0, 1, "", "", extra);

                if (hydrometricDataValueService.Query.Extra == "A")
                {
                    HydrometricDataValueExtraA hydrometricDataValueExtraA = new HydrometricDataValueExtraA();
                    hydrometricDataValueExtraA = hydrometricDataValueService.GetHydrometricDataValueExtraAWithHydrometricDataValueID(HydrometricDataValueID);

                    if (hydrometricDataValueExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(hydrometricDataValueExtraA));
                }
                else if (hydrometricDataValueService.Query.Extra == "B")
                {
                    HydrometricDataValueExtraB hydrometricDataValueExtraB = new HydrometricDataValueExtraB();
                    hydrometricDataValueExtraB = hydrometricDataValueService.GetHydrometricDataValueExtraBWithHydrometricDataValueID(HydrometricDataValueID);

                    if (hydrometricDataValueExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(hydrometricDataValueExtraB));
                }
                else
                {
                    HydrometricDataValue hydrometricDataValue = new HydrometricDataValue();
                    hydrometricDataValue = hydrometricDataValueService.GetHydrometricDataValueWithHydrometricDataValueID(HydrometricDataValueID);

                    if (hydrometricDataValue == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(hydrometricDataValue));
                }
            }
        }
        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);
            hydrometricDataValueService = new HydrometricDataValueService((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);
            hydrometricDataValueModelNew = new HydrometricDataValueModel();
            hydrometricDataValue         = new HydrometricDataValue();
            hydrometricSiteServiceTest   = new HydrometricSiteServiceTest();
            hydrometricSiteServiceTest.SetupTest(contactModelToDo, culture);
        }
        public void HydrometricDataValueService_Constructor_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                ContactModel contactModel = contactModelListGood[0];
                IPrincipal   user         = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null);

                // Act for Add
                HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);

                Assert.IsNotNull(hydrometricDataValueService);
                Assert.IsNotNull(hydrometricDataValueService.db);
                Assert.IsNotNull(hydrometricDataValueService.LanguageRequest);
                Assert.IsNotNull(hydrometricDataValueService.User);
                Assert.AreEqual(user.Identity.Name, hydrometricDataValueService.User.Identity.Name);
                Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), hydrometricDataValueService.LanguageRequest);
            }
        }
예제 #7
0
        public void HydrometricDataValue_Controller_GetHydrometricDataValueWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HydrometricDataValueController hydrometricDataValueController = new HydrometricDataValueController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(hydrometricDataValueController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, hydrometricDataValueController.DatabaseType);

                    HydrometricDataValue hydrometricDataValueFirst = new HydrometricDataValue();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query(), db, ContactID);
                        hydrometricDataValueFirst = (from c in db.HydrometricDataValues select c).FirstOrDefault();
                    }

                    // ok with HydrometricDataValue info
                    IHttpActionResult jsonRet = hydrometricDataValueController.GetHydrometricDataValueWithID(hydrometricDataValueFirst.HydrometricDataValueID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <HydrometricDataValue> Ret = jsonRet as OkNegotiatedContentResult <HydrometricDataValue>;
                    HydrometricDataValue hydrometricDataValueRet         = Ret.Content;
                    Assert.AreEqual(hydrometricDataValueFirst.HydrometricDataValueID, hydrometricDataValueRet.HydrometricDataValueID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = hydrometricDataValueController.GetHydrometricDataValueWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet2 = jsonRet2 as OkNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNull(hydrometricDataValueRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        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);
            reportServiceMike_Scenario_File = new ReportServiceMike_Scenario_File((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            tvItemService               = new TVItemService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            boxModelService             = new BoxModelService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            vpScenarioService           = new VPScenarioService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            labSheetService             = new LabSheetService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            polSourceObservationService = new PolSourceObservationService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            climateSiteService          = new ClimateSiteService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            hydrometricSiteService      = new HydrometricSiteService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            tideSiteService             = new TideSiteService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            randomService               = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            hydrometricDataValueService = new HydrometricDataValueService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            tideDataValueService        = new TideDataValueService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
        }
        public IHttpActionResult Delete([FromBody] HydrometricDataValue hydrometricDataValue, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!hydrometricDataValueService.Delete(hydrometricDataValue))
                {
                    return(BadRequest(String.Join("|||", hydrometricDataValue.ValidationResults)));
                }
                else
                {
                    hydrometricDataValue.ValidationResults = null;
                    return(Ok(hydrometricDataValue));
                }
            }
        }
        public void HydrometricDataValueService_PostAddDeleteHydrometricDataValueDB_BadUser_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    HydrometricSiteModel hydrometricSiteModelRet = hydrometricSiteServiceTest.AddHydrometricSiteModel();

                    ContactModel                contactModelBad                = contactModelListBad[0];
                    IPrincipal                  userBad                        = new GenericPrincipal(new GenericIdentity(contactModelBad.LoginEmail, "Forms"), null);
                    HydrometricSiteService      hydrometricSiteServiceBad      = new HydrometricSiteService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), userBad);
                    HydrometricDataValueService hydrometricDataValueServiceBad = new HydrometricDataValueService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), userBad);

                    FillHydrometricDataValueModel(hydrometricDataValueModelNew);
                    HydrometricDataValueModel hydrometricDataValueModelRet = hydrometricDataValueServiceBad.PostAddHydrometricDataValueDB(hydrometricDataValueModelNew);
                    Assert.AreEqual(ServiceRes.NeedToBeLoggedIn, hydrometricDataValueModelRet.Error);
                }
            }
        }
        public void GetHydrometricDataValueList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    HydrometricDataValue hydrometricDataValue = (from c in dbTestDB.HydrometricDataValues select c).FirstOrDefault();
                    Assert.IsNotNull(hydrometricDataValue);

                    List <HydrometricDataValue> hydrometricDataValueDirectQueryList = new List <HydrometricDataValue>();
                    hydrometricDataValueDirectQueryList = (from c in dbTestDB.HydrometricDataValues select c).Take(200).ToList();

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        hydrometricDataValueService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <HydrometricDataValue> hydrometricDataValueList = new List <HydrometricDataValue>();
                            hydrometricDataValueList = hydrometricDataValueService.GetHydrometricDataValueList().ToList();
                            CheckHydrometricDataValueFields(hydrometricDataValueList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public void GetHydrometricDataValueList_2Where_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        hydrometricDataValueService.Query = hydrometricDataValueService.FillQuery(typeof(HydrometricDataValue), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "HydrometricDataValueID,GT,2|HydrometricDataValueID,LT,5", extra);

                        List <HydrometricDataValue> hydrometricDataValueDirectQueryList = new List <HydrometricDataValue>();
                        hydrometricDataValueDirectQueryList = (from c in dbTestDB.HydrometricDataValues select c).Where(c => c.HydrometricDataValueID > 2 && c.HydrometricDataValueID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <HydrometricDataValue> hydrometricDataValueList = new List <HydrometricDataValue>();
                            hydrometricDataValueList = hydrometricDataValueService.GetHydrometricDataValueList().ToList();
                            CheckHydrometricDataValueFields(hydrometricDataValueList);
                            Assert.AreEqual(hydrometricDataValueDirectQueryList[0].HydrometricDataValueID, hydrometricDataValueList[0].HydrometricDataValueID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
예제 #13
0
        public void HydrometricDataValue_Controller_GetHydrometricDataValueList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HydrometricDataValueController hydrometricDataValueController = new HydrometricDataValueController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(hydrometricDataValueController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, hydrometricDataValueController.DatabaseType);

                    HydrometricDataValue hydrometricDataValueFirst = new HydrometricDataValue();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(query, db, ContactID);
                        hydrometricDataValueFirst = (from c in db.HydrometricDataValues select c).FirstOrDefault();
                        count = (from c in db.HydrometricDataValues select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with HydrometricDataValue info
                    IHttpActionResult jsonRet = hydrometricDataValueController.GetHydrometricDataValueList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <HydrometricDataValue> > ret = jsonRet as OkNegotiatedContentResult <List <HydrometricDataValue> >;
                    Assert.AreEqual(hydrometricDataValueFirst.HydrometricDataValueID, ret.Content[0].HydrometricDataValueID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <HydrometricDataValue> hydrometricDataValueList = new List <HydrometricDataValue>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(query, db, ContactID);
                        hydrometricDataValueList = (from c in db.HydrometricDataValues select c).OrderBy(c => c.HydrometricDataValueID).Skip(0).Take(2).ToList();
                        count = (from c in db.HydrometricDataValues select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with HydrometricDataValue info
                        jsonRet = hydrometricDataValueController.GetHydrometricDataValueList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <HydrometricDataValue> >;
                        Assert.AreEqual(hydrometricDataValueList[0].HydrometricDataValueID, ret.Content[0].HydrometricDataValueID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with HydrometricDataValue info
                            IHttpActionResult jsonRet2 = hydrometricDataValueController.GetHydrometricDataValueList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <HydrometricDataValue> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <HydrometricDataValue> >;
                            Assert.AreEqual(hydrometricDataValueList[1].HydrometricDataValueID, ret2.Content[0].HydrometricDataValueID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
예제 #14
0
        public void HydrometricDataValue_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    HydrometricDataValueController hydrometricDataValueController = new HydrometricDataValueController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(hydrometricDataValueController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, hydrometricDataValueController.DatabaseType);

                    HydrometricDataValue hydrometricDataValueLast = new HydrometricDataValue();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(query, db, ContactID);
                        hydrometricDataValueLast = (from c in db.HydrometricDataValues select c).FirstOrDefault();
                    }

                    // ok with HydrometricDataValue info
                    IHttpActionResult jsonRet = hydrometricDataValueController.GetHydrometricDataValueWithID(hydrometricDataValueLast.HydrometricDataValueID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <HydrometricDataValue> Ret = jsonRet as OkNegotiatedContentResult <HydrometricDataValue>;
                    HydrometricDataValue hydrometricDataValueRet         = Ret.Content;
                    Assert.AreEqual(hydrometricDataValueLast.HydrometricDataValueID, hydrometricDataValueRet.HydrometricDataValueID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because HydrometricDataValueID exist
                    IHttpActionResult jsonRet2 = hydrometricDataValueController.Post(hydrometricDataValueRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet2 = jsonRet2 as OkNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNull(hydrometricDataValueRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added HydrometricDataValue
                    hydrometricDataValueRet.HydrometricDataValueID    = 0;
                    hydrometricDataValueController.Request            = new System.Net.Http.HttpRequestMessage();
                    hydrometricDataValueController.Request.RequestUri = new System.Uri("http://localhost:5000/api/hydrometricDataValue");
                    IHttpActionResult jsonRet3 = hydrometricDataValueController.Post(hydrometricDataValueRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet3 = jsonRet3 as CreatedNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNotNull(hydrometricDataValueRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = hydrometricDataValueController.Delete(hydrometricDataValueRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <HydrometricDataValue> hydrometricDataValueRet4 = jsonRet4 as OkNegotiatedContentResult <HydrometricDataValue>;
                    Assert.IsNotNull(hydrometricDataValueRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        public IHttpActionResult GetHydrometricDataValueList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                             [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

                if (extra == "A") // QueryString contains [extra=A]
                {
                    hydrometricDataValueService.Query = hydrometricDataValueService.FillQuery(typeof(HydrometricDataValueExtraA), lang, skip, take, asc, desc, where, extra);

                    if (hydrometricDataValueService.Query.HasErrors)
                    {
                        return(Ok(new List <HydrometricDataValueExtraA>()
                        {
                            new HydrometricDataValueExtraA()
                            {
                                HasErrors = hydrometricDataValueService.Query.HasErrors,
                                ValidationResults = hydrometricDataValueService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(hydrometricDataValueService.GetHydrometricDataValueExtraAList().ToList()));
                    }
                }
                else if (extra == "B") // QueryString contains [extra=B]
                {
                    hydrometricDataValueService.Query = hydrometricDataValueService.FillQuery(typeof(HydrometricDataValueExtraB), lang, skip, take, asc, desc, where, extra);

                    if (hydrometricDataValueService.Query.HasErrors)
                    {
                        return(Ok(new List <HydrometricDataValueExtraB>()
                        {
                            new HydrometricDataValueExtraB()
                            {
                                HasErrors = hydrometricDataValueService.Query.HasErrors,
                                ValidationResults = hydrometricDataValueService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(hydrometricDataValueService.GetHydrometricDataValueExtraBList().ToList()));
                    }
                }
                else // QueryString has no parameter [extra] or extra is empty
                {
                    hydrometricDataValueService.Query = hydrometricDataValueService.FillQuery(typeof(HydrometricDataValue), lang, skip, take, asc, desc, where, extra);

                    if (hydrometricDataValueService.Query.HasErrors)
                    {
                        return(Ok(new List <HydrometricDataValue>()
                        {
                            new HydrometricDataValue()
                            {
                                HasErrors = hydrometricDataValueService.Query.HasErrors,
                                ValidationResults = hydrometricDataValueService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(hydrometricDataValueService.GetHydrometricDataValueList().ToList()));
                    }
                }
            }
        }
        public void HydrometricDataValue_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    HydrometricDataValueService hydrometricDataValueService = new HydrometricDataValueService(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 = hydrometricDataValueService.GetHydrometricDataValueList().Count();

                    HydrometricDataValue hydrometricDataValue = GetFilledRandomHydrometricDataValue("");

                    // -------------------------------
                    // -------------------------------
                    // Properties testing
                    // -------------------------------
                    // -------------------------------


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // hydrometricDataValue.HydrometricDataValueID   (Int32)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.HydrometricDataValueID = 0;
                    hydrometricDataValueService.Update(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "HydrometricDataValueID"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.HydrometricDataValueID = 10000000;
                    hydrometricDataValueService.Update(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "HydrometricDataValue", "HydrometricDataValueID", hydrometricDataValue.HydrometricDataValueID.ToString()), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "HydrometricSite", ExistPlurial = "s", ExistFieldID = "HydrometricSiteID", AllowableTVtypeList = )]
                    // hydrometricDataValue.HydrometricSiteID   (Int32)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.HydrometricSiteID = 0;
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "HydrometricSite", "HydrometricSiteID", hydrometricDataValue.HydrometricSiteID.ToString()), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // hydrometricDataValue.DateTime_Local   (DateTime)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.DateTime_Local = new DateTime();
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DateTime_Local"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.DateTime_Local = new DateTime(1979, 1, 1);
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "DateTime_Local", "1980"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // hydrometricDataValue.Keep   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // hydrometricDataValue.StorageDataType   (StorageDataTypeEnum)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.StorageDataType = (StorageDataTypeEnum)1000000;
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "StorageDataType"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // hydrometricDataValue.HasBeenRead   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is Nullable
                    // [Range(0, 100000)]
                    // hydrometricDataValue.Discharge_m3_s   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [Discharge_m3_s]

                    //CSSPError: Type not implemented [Discharge_m3_s]

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.Discharge_m3_s = -1.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Discharge_m3_s", "0", "100000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());
                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.Discharge_m3_s = 100001.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Discharge_m3_s", "0", "100000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());

                    // -----------------------------------
                    // Is Nullable
                    // [Range(0, 100000)]
                    // hydrometricDataValue.DischargeEntered_m3_s   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [DischargeEntered_m3_s]

                    //CSSPError: Type not implemented [DischargeEntered_m3_s]

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.DischargeEntered_m3_s = -1.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DischargeEntered_m3_s", "0", "100000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());
                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.DischargeEntered_m3_s = 100001.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DischargeEntered_m3_s", "0", "100000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());

                    // -----------------------------------
                    // Is Nullable
                    // [Range(0, 10000)]
                    // hydrometricDataValue.Level_m   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [Level_m]

                    //CSSPError: Type not implemented [Level_m]

                    hydrometricDataValue         = null;
                    hydrometricDataValue         = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.Level_m = -1.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Level_m", "0", "10000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());
                    hydrometricDataValue         = null;
                    hydrometricDataValue         = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.Level_m = 10001.0D;
                    Assert.AreEqual(false, hydrometricDataValueService.Add(hydrometricDataValue));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Level_m", "0", "10000"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, hydrometricDataValueService.GetHydrometricDataValueList().Count());

                    // -----------------------------------
                    // Is Nullable
                    // hydrometricDataValue.HourlyValues   (String)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // hydrometricDataValue.LastUpdateDate_UTC   (DateTime)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.LastUpdateDate_UTC = new DateTime();
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);
                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.LastUpdateDate_UTC = new DateTime(1979, 1, 1);
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)]
                    // hydrometricDataValue.LastUpdateContactTVItemID   (Int32)
                    // -----------------------------------

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.LastUpdateContactTVItemID = 0;
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", hydrometricDataValue.LastUpdateContactTVItemID.ToString()), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);

                    hydrometricDataValue = null;
                    hydrometricDataValue = GetFilledRandomHydrometricDataValue("");
                    hydrometricDataValue.LastUpdateContactTVItemID = 1;
                    hydrometricDataValueService.Add(hydrometricDataValue);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), hydrometricDataValue.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // hydrometricDataValue.HasErrors   (Boolean)
                    // -----------------------------------

                    // No testing requied

                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // hydrometricDataValue.ValidationResults   (IEnumerable`1)
                    // -----------------------------------

                    // No testing requied
                }
            }
        }