Пример #1
0
        public void VPResult_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultLast = new VPResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultLast = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultLast.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultLast.VPResultID, vpResultRet.VPResultID);

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

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

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet2);

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

                    // Put to return CSSPError because VPResultID of 0 does not exist
                    vpResultRet.VPResultID = 0;
                    IHttpActionResult jsonRet3 = vpResultController.Put(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <VPResult> vpResultRet3 = jsonRet3 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Пример #2
0
 public IHttpActionResult GetVPResultList([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))
     {
         VPResultService vpResultService = new VPResultService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Пример #3
0
        public void VPResult_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    VPResult vpResult = GetFilledRandomVPResult("");

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

                    count = vpResultService.GetVPResultList().Count();

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

                    vpResultService.Add(vpResult);
                    if (vpResult.HasErrors)
                    {
                        Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, vpResultService.GetVPResultList().Where(c => c == vpResult).Any());
                    vpResultService.Update(vpResult);
                    if (vpResult.HasErrors)
                    {
                        Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, vpResultService.GetVPResultList().Count());
                    vpResultService.Delete(vpResult);
                    if (vpResult.HasErrors)
                    {
                        Assert.AreEqual("", vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                }
            }
        }
Пример #4
0
        public IHttpActionResult GetVPResultWithID([FromUri] int VPResultID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                VPResultService vpResultService = new VPResultService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), lang, 0, 1, "", "", extra);

                if (vpResultService.Query.Extra == "A")
                {
                    VPResultExtraA vpResultExtraA = new VPResultExtraA();
                    vpResultExtraA = vpResultService.GetVPResultExtraAWithVPResultID(VPResultID);

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

                    return(Ok(vpResultExtraA));
                }
                else if (vpResultService.Query.Extra == "B")
                {
                    VPResultExtraB vpResultExtraB = new VPResultExtraB();
                    vpResultExtraB = vpResultService.GetVPResultExtraBWithVPResultID(VPResultID);

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

                    return(Ok(vpResultExtraB));
                }
                else
                {
                    VPResult vpResult = new VPResult();
                    vpResult = vpResultService.GetVPResultWithVPResultID(VPResultID);

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

                    return(Ok(vpResult));
                }
            }
        }
Пример #5
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);
            vpResultService       = new VPResultService((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);
            vpResultModelNew      = new VPResultModel();
            vpResult              = new VPResult();
            vpScenarioServiceTest = new VPScenarioServiceTest();
            vpScenarioServiceTest.SetupTest(contactModelToDo, culture);
        }
Пример #6
0
        public void VPResult_Controller_GetVPResultWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultFirst = new VPResult();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        VPResultService vpResultService = new VPResultService(new Query(), db, ContactID);
                        vpResultFirst = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultFirst.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultFirst.VPResultID, vpResultRet.VPResultID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = vpResultController.GetVPResultWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Пример #7
0
        public IHttpActionResult Delete([FromBody] VPResult vpResult, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                VPResultService vpResultService = new VPResultService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!vpResultService.Delete(vpResult))
                {
                    return(BadRequest(String.Join("|||", vpResult.ValidationResults)));
                }
                else
                {
                    vpResult.ValidationResults = null;
                    return(Ok(vpResult));
                }
            }
        }
Пример #8
0
        public void GetVPResultList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    VPResultService vpResultService = new VPResultService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    VPResult vpResult = (from c in dbTestDB.VPResults select c).FirstOrDefault();
                    Assert.IsNotNull(vpResult);

                    List <VPResult> vpResultDirectQueryList = new List <VPResult>();
                    vpResultDirectQueryList = (from c in dbTestDB.VPResults select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <VPResult> vpResultList = new List <VPResult>();
                            vpResultList = vpResultService.GetVPResultList().ToList();
                            CheckVPResultFields(vpResultList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Пример #9
0
        public void GetVPResultList_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"
                    })
                    {
                        VPResultService vpResultService = new VPResultService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        vpResultService.Query = vpResultService.FillQuery(typeof(VPResult), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "VPResultID,GT,2|VPResultID,LT,5", extra);

                        List <VPResult> vpResultDirectQueryList = new List <VPResult>();
                        vpResultDirectQueryList = (from c in dbTestDB.VPResults select c).Where(c => c.VPResultID > 2 && c.VPResultID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <VPResult> vpResultList = new List <VPResult>();
                            vpResultList = vpResultService.GetVPResultList().ToList();
                            CheckVPResultFields(vpResultList);
                            Assert.AreEqual(vpResultDirectQueryList[0].VPResultID, vpResultList[0].VPResultID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Пример #10
0
        public void VPResult_Controller_GetVPResultList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

                    VPResult vpResultFirst = new VPResult();
                    int      count         = -1;
                    Query    query         = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultFirst = (from c in db.VPResults select c).FirstOrDefault();
                        count         = (from c in db.VPResults select c).Count();
                        count         = (query.Take > count ? count : query.Take);
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultList();
                    Assert.IsNotNull(jsonRet);

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

                    List <VPResult> vpResultList = new List <VPResult>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultList = (from c in db.VPResults select c).OrderBy(c => c.VPResultID).Skip(0).Take(2).ToList();
                        count        = (from c in db.VPResults select c).Count();
                    }

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

                        // ok with VPResult info
                        jsonRet = vpResultController.GetVPResultList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <VPResult> >;
                        Assert.AreEqual(vpResultList[0].VPResultID, ret.Content[0].VPResultID);
                        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 VPResult info
                            IHttpActionResult jsonRet2 = vpResultController.GetVPResultList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <VPResult> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <VPResult> >;
                            Assert.AreEqual(vpResultList[1].VPResultID, ret2.Content[0].VPResultID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Пример #11
0
        public void VPResult_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPResultController vpResultController = new VPResultController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpResultController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpResultController.DatabaseType);

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

                        VPResultService vpResultService = new VPResultService(query, db, ContactID);
                        vpResultLast = (from c in db.VPResults select c).FirstOrDefault();
                    }

                    // ok with VPResult info
                    IHttpActionResult jsonRet = vpResultController.GetVPResultWithID(vpResultLast.VPResultID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPResult> Ret = jsonRet as OkNegotiatedContentResult <VPResult>;
                    VPResult vpResultRet = Ret.Content;
                    Assert.AreEqual(vpResultLast.VPResultID, vpResultRet.VPResultID);

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

                    // Post to return CSSPError because VPResultID exist
                    IHttpActionResult jsonRet2 = vpResultController.Post(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPResult> vpResultRet2 = jsonRet2 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNull(vpResultRet2);

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

                    // Post to return newly added VPResult
                    vpResultRet.VPResultID                = 0;
                    vpResultController.Request            = new System.Net.Http.HttpRequestMessage();
                    vpResultController.Request.RequestUri = new System.Uri("http://localhost:5000/api/vpResult");
                    IHttpActionResult jsonRet3 = vpResultController.Post(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <VPResult> vpResultRet3 = jsonRet3 as CreatedNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet3);

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

                    IHttpActionResult jsonRet4 = vpResultController.Delete(vpResultRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <VPResult> vpResultRet4 = jsonRet4 as OkNegotiatedContentResult <VPResult>;
                    Assert.IsNotNull(vpResultRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Пример #12
0
        public void VPResult_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    VPResultService vpResultService = new VPResultService(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 = vpResultService.GetVPResultList().Count();

                    VPResult vpResult = GetFilledRandomVPResult("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // vpResult.VPResultID   (Int32)
                    // -----------------------------------

                    vpResult            = null;
                    vpResult            = GetFilledRandomVPResult("");
                    vpResult.VPResultID = 0;
                    vpResultService.Update(vpResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "VPResultID"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);

                    vpResult            = null;
                    vpResult            = GetFilledRandomVPResult("");
                    vpResult.VPResultID = 10000000;
                    vpResultService.Update(vpResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "VPResult", "VPResultID", vpResult.VPResultID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "VPScenario", ExistPlurial = "s", ExistFieldID = "VPScenarioID", AllowableTVtypeList = )]
                    // vpResult.VPScenarioID   (Int32)
                    // -----------------------------------

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.VPScenarioID = 0;
                    vpResultService.Add(vpResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "VPScenario", "VPScenarioID", vpResult.VPScenarioID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 1000)]
                    // vpResult.Ordinal   (Int32)
                    // -----------------------------------

                    vpResult         = null;
                    vpResult         = GetFilledRandomVPResult("");
                    vpResult.Ordinal = -1;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult         = null;
                    vpResult         = GetFilledRandomVPResult("");
                    vpResult.Ordinal = 1001;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 10000000)]
                    // vpResult.Concentration_MPN_100ml   (Int32)
                    // -----------------------------------

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.Concentration_MPN_100ml = -1;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Concentration_MPN_100ml", "0", "10000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.Concentration_MPN_100ml = 10000001;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Concentration_MPN_100ml", "0", "10000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 1000000)]
                    // vpResult.Dilution   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [Dilution]

                    //CSSPError: Type not implemented [Dilution]

                    vpResult          = null;
                    vpResult          = GetFilledRandomVPResult("");
                    vpResult.Dilution = -1.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Dilution", "0", "1000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult          = null;
                    vpResult          = GetFilledRandomVPResult("");
                    vpResult.Dilution = 1000001.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Dilution", "0", "1000000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 10000)]
                    // vpResult.FarFieldWidth_m   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [FarFieldWidth_m]

                    //CSSPError: Type not implemented [FarFieldWidth_m]

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.FarFieldWidth_m = -1.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldWidth_m", "0", "10000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.FarFieldWidth_m = 10001.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldWidth_m", "0", "10000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 100000)]
                    // vpResult.DispersionDistance_m   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [DispersionDistance_m]

                    //CSSPError: Type not implemented [DispersionDistance_m]

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.DispersionDistance_m = -1.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DispersionDistance_m", "0", "100000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.DispersionDistance_m = 100001.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DispersionDistance_m", "0", "100000"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 100)]
                    // vpResult.TravelTime_hour   (Double)
                    // -----------------------------------

                    //CSSPError: Type not implemented [TravelTime_hour]

                    //CSSPError: Type not implemented [TravelTime_hour]

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.TravelTime_hour = -1.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TravelTime_hour", "0", "100"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());
                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.TravelTime_hour = 101.0D;
                    Assert.AreEqual(false, vpResultService.Add(vpResult));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TravelTime_hour", "0", "100"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, vpResultService.GetVPResultList().Count());

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

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

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

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.LastUpdateContactTVItemID = 0;
                    vpResultService.Add(vpResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", vpResult.LastUpdateContactTVItemID.ToString()), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);

                    vpResult = null;
                    vpResult = GetFilledRandomVPResult("");
                    vpResult.LastUpdateContactTVItemID = 1;
                    vpResultService.Add(vpResult);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), vpResult.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
Пример #13
0
        public IHttpActionResult GetVPResultList([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))
            {
                VPResultService vpResultService = new VPResultService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (vpResultService.Query.HasErrors)
                    {
                        return(Ok(new List <VPResult>()
                        {
                            new VPResult()
                            {
                                HasErrors = vpResultService.Query.HasErrors,
                                ValidationResults = vpResultService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(vpResultService.GetVPResultList().ToList()));
                    }
                }
            }
        }