Exemplo n.º 1
0
        public SamplingPlanSubsectorModel PostDeleteSamplingPlanSubsectorDB(int SamplingPlanSubsectorID)
        {
            ContactOK contactOK = IsContactOK();

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

            SamplingPlanSubsector SamplingPlanSubsectorToDelete = GetSamplingPlanSubsectorWithSamplingPlanSubsectorIDDB(SamplingPlanSubsectorID);

            if (SamplingPlanSubsectorToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.SamplingPlanSubsector)));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.SamplingPlanSubsectors.Remove(SamplingPlanSubsectorToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("SamplingPlanSubsectors", SamplingPlanSubsectorToDelete.SamplingPlanSubsectorID, LogCommandEnum.Delete, SamplingPlanSubsectorToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
Exemplo n.º 2
0
        public SamplingPlanSubsector GetSamplingPlanSubsectorWithSamplingPlanSubsectorIDDB(int SamplingPlanSubsectorID)
        {
            SamplingPlanSubsector SamplingPlanSubsector = (from c in db.SamplingPlanSubsectors
                                                           where c.SamplingPlanSubsectorID == SamplingPlanSubsectorID
                                                           select c).FirstOrDefault <SamplingPlanSubsector>();

            return(SamplingPlanSubsector);
        }
Exemplo n.º 3
0
        public void SamplingPlanSubsector_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanSubsectorController samplingPlanSubsectorController = new SamplingPlanSubsectorController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanSubsectorController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanSubsectorController.DatabaseType);

                    SamplingPlanSubsector samplingPlanSubsectorLast = new SamplingPlanSubsector();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(query, db, ContactID);
                        samplingPlanSubsectorLast = (from c in db.SamplingPlanSubsectors select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanSubsector info
                    IHttpActionResult jsonRet = samplingPlanSubsectorController.GetSamplingPlanSubsectorWithID(samplingPlanSubsectorLast.SamplingPlanSubsectorID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanSubsector> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    SamplingPlanSubsector samplingPlanSubsectorRet        = Ret.Content;
                    Assert.AreEqual(samplingPlanSubsectorLast.SamplingPlanSubsectorID, samplingPlanSubsectorRet.SamplingPlanSubsectorID);

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

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

                    OkNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNotNull(samplingPlanSubsectorRet2);

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

                    // Put to return CSSPError because SamplingPlanSubsectorID of 0 does not exist
                    samplingPlanSubsectorRet.SamplingPlanSubsectorID = 0;
                    IHttpActionResult jsonRet3 = samplingPlanSubsectorController.Put(samplingPlanSubsectorRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet3 = jsonRet3 as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNull(samplingPlanSubsectorRet3);

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

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

                    SamplingPlanSubsector samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");

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

                    count = samplingPlanSubsectorService.GetSamplingPlanSubsectorList().Count();

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

                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    if (samplingPlanSubsector.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, samplingPlanSubsectorService.GetSamplingPlanSubsectorList().Where(c => c == samplingPlanSubsector).Any());
                    samplingPlanSubsectorService.Update(samplingPlanSubsector);
                    if (samplingPlanSubsector.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, samplingPlanSubsectorService.GetSamplingPlanSubsectorList().Count());
                    samplingPlanSubsectorService.Delete(samplingPlanSubsector);
                    if (samplingPlanSubsector.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, samplingPlanSubsectorService.GetSamplingPlanSubsectorList().Count());
                }
            }
        }
Exemplo n.º 5
0
        // Post
        public SamplingPlanSubsectorModel PostAddSamplingPlanSubsectorDB(SamplingPlanSubsectorModel SamplingPlanSubsectorModel)
        {
            string retStr = SamplingPlanSubsectorModelOK(SamplingPlanSubsectorModel);

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

            ContactOK contactOK = IsContactOK();

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

            SamplingPlanSubsectorModel SamplingPlanSubsectorModelExist = GetSamplingPlanSubsectorModelExistDB(SamplingPlanSubsectorModel);

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

            SamplingPlanSubsector SamplingPlanSubsectorNew = new SamplingPlanSubsector();

            retStr = FillSamplingPlanSubsector(SamplingPlanSubsectorNew, SamplingPlanSubsectorModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("SamplingPlanSubsectors", SamplingPlanSubsectorNew.SamplingPlanSubsectorID, LogCommandEnum.Add, SamplingPlanSubsectorNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetSamplingPlanSubsectorModelWithSamplingPlanSubsectorIDDB(SamplingPlanSubsectorNew.SamplingPlanSubsectorID));
        }
Exemplo n.º 6
0
        public IHttpActionResult GetSamplingPlanSubsectorWithID([FromUri] int SamplingPlanSubsectorID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                samplingPlanSubsectorService.Query = samplingPlanSubsectorService.FillQuery(typeof(SamplingPlanSubsector), lang, 0, 1, "", "", extra);

                if (samplingPlanSubsectorService.Query.Extra == "A")
                {
                    SamplingPlanSubsectorExtraA samplingPlanSubsectorExtraA = new SamplingPlanSubsectorExtraA();
                    samplingPlanSubsectorExtraA = samplingPlanSubsectorService.GetSamplingPlanSubsectorExtraAWithSamplingPlanSubsectorID(SamplingPlanSubsectorID);

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

                    return(Ok(samplingPlanSubsectorExtraA));
                }
                else if (samplingPlanSubsectorService.Query.Extra == "B")
                {
                    SamplingPlanSubsectorExtraB samplingPlanSubsectorExtraB = new SamplingPlanSubsectorExtraB();
                    samplingPlanSubsectorExtraB = samplingPlanSubsectorService.GetSamplingPlanSubsectorExtraBWithSamplingPlanSubsectorID(SamplingPlanSubsectorID);

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

                    return(Ok(samplingPlanSubsectorExtraB));
                }
                else
                {
                    SamplingPlanSubsector samplingPlanSubsector = new SamplingPlanSubsector();
                    samplingPlanSubsector = samplingPlanSubsectorService.GetSamplingPlanSubsectorWithSamplingPlanSubsectorID(SamplingPlanSubsectorID);

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

                    return(Ok(samplingPlanSubsector));
                }
            }
        }
        private bool TryToSave(SamplingPlanSubsector samplingPlanSubsector)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                samplingPlanSubsector.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
        public bool Update(SamplingPlanSubsector samplingPlanSubsector)
        {
            samplingPlanSubsector.ValidationResults = Validate(new ValidationContext(samplingPlanSubsector), ActionDBTypeEnum.Update);
            if (samplingPlanSubsector.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.SamplingPlanSubsectors.Update(samplingPlanSubsector);

            if (!TryToSave(samplingPlanSubsector))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        // Fill
        public string FillSamplingPlanSubsector(SamplingPlanSubsector samplingPlanSubsector, SamplingPlanSubsectorModel samplingPlanSubsectorModel, ContactOK contactOK)
        {
            samplingPlanSubsector.DBCommand          = (int)samplingPlanSubsectorModel.DBCommand;
            samplingPlanSubsector.SamplingPlanID     = samplingPlanSubsectorModel.SamplingPlanID;
            samplingPlanSubsector.SubsectorTVItemID  = samplingPlanSubsectorModel.SubsectorTVItemID;
            samplingPlanSubsector.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                samplingPlanSubsector.LastUpdateContactTVItemID = 2;
            }
            else
            {
                samplingPlanSubsector.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Exemplo n.º 10
0
        public void SamplingPlanSubsector_Controller_GetSamplingPlanSubsectorWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanSubsectorController samplingPlanSubsectorController = new SamplingPlanSubsectorController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanSubsectorController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanSubsectorController.DatabaseType);

                    SamplingPlanSubsector samplingPlanSubsectorFirst = new SamplingPlanSubsector();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(new Query(), db, ContactID);
                        samplingPlanSubsectorFirst = (from c in db.SamplingPlanSubsectors select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanSubsector info
                    IHttpActionResult jsonRet = samplingPlanSubsectorController.GetSamplingPlanSubsectorWithID(samplingPlanSubsectorFirst.SamplingPlanSubsectorID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanSubsector> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    SamplingPlanSubsector samplingPlanSubsectorRet        = Ret.Content;
                    Assert.AreEqual(samplingPlanSubsectorFirst.SamplingPlanSubsectorID, samplingPlanSubsectorRet.SamplingPlanSubsectorID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = samplingPlanSubsectorController.GetSamplingPlanSubsectorWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNull(samplingPlanSubsectorRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Exemplo n.º 11
0
        public IHttpActionResult Delete([FromBody] SamplingPlanSubsector samplingPlanSubsector, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!samplingPlanSubsectorService.Delete(samplingPlanSubsector))
                {
                    return(BadRequest(String.Join("|||", samplingPlanSubsector.ValidationResults)));
                }
                else
                {
                    samplingPlanSubsector.ValidationResults = null;
                    return(Ok(samplingPlanSubsector));
                }
            }
        }
        public void GetSamplingPlanSubsectorList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    SamplingPlanSubsector samplingPlanSubsector = (from c in dbTestDB.SamplingPlanSubsectors select c).FirstOrDefault();
                    Assert.IsNotNull(samplingPlanSubsector);

                    List <SamplingPlanSubsector> samplingPlanSubsectorDirectQueryList = new List <SamplingPlanSubsector>();
                    samplingPlanSubsectorDirectQueryList = (from c in dbTestDB.SamplingPlanSubsectors select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SamplingPlanSubsector> samplingPlanSubsectorList = new List <SamplingPlanSubsector>();
                            samplingPlanSubsectorList = samplingPlanSubsectorService.GetSamplingPlanSubsectorList().ToList();
                            CheckSamplingPlanSubsectorFields(samplingPlanSubsectorList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        private SamplingPlanSubsector GetFilledRandomSamplingPlanSubsector(string OmitPropName)
        {
            SamplingPlanSubsector samplingPlanSubsector = new SamplingPlanSubsector();

            if (OmitPropName != "SamplingPlanID")
            {
                samplingPlanSubsector.SamplingPlanID = 1;
            }
            if (OmitPropName != "SubsectorTVItemID")
            {
                samplingPlanSubsector.SubsectorTVItemID = 11;
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                samplingPlanSubsector.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                samplingPlanSubsector.LastUpdateContactTVItemID = 2;
            }

            return(samplingPlanSubsector);
        }
        public void SamplingPlanSubsector_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(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 = samplingPlanSubsectorService.GetSamplingPlanSubsectorList().Count();

                    SamplingPlanSubsector samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // samplingPlanSubsector.SamplingPlanSubsectorID   (Int32)
                    // -----------------------------------

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.SamplingPlanSubsectorID = 0;
                    samplingPlanSubsectorService.Update(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanSubsectorID"), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.SamplingPlanSubsectorID = 10000000;
                    samplingPlanSubsectorService.Update(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsector", "SamplingPlanSubsectorID", samplingPlanSubsector.SamplingPlanSubsectorID.ToString()), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "SamplingPlan", ExistPlurial = "s", ExistFieldID = "SamplingPlanID", AllowableTVtypeList = )]
                    // samplingPlanSubsector.SamplingPlanID   (Int32)
                    // -----------------------------------

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.SamplingPlanID = 0;
                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlanSubsector.SamplingPlanID.ToString()), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Subsector)]
                    // samplingPlanSubsector.SubsectorTVItemID   (Int32)
                    // -----------------------------------

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.SubsectorTVItemID = 0;
                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", samplingPlanSubsector.SubsectorTVItemID.ToString()), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.SubsectorTVItemID = 1;
                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);


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

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

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

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.LastUpdateContactTVItemID = 0;
                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanSubsector.LastUpdateContactTVItemID.ToString()), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);

                    samplingPlanSubsector = null;
                    samplingPlanSubsector = GetFilledRandomSamplingPlanSubsector("");
                    samplingPlanSubsector.LastUpdateContactTVItemID = 1;
                    samplingPlanSubsectorService.Add(samplingPlanSubsector);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), samplingPlanSubsector.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string retStr = "";
            Enums  enums  = new Enums(LanguageRequest);
            SamplingPlanSubsectorSite samplingPlanSubsectorSite = validationContext.ObjectInstance as SamplingPlanSubsectorSite;

            samplingPlanSubsectorSite.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID == 0)
                {
                    samplingPlanSubsectorSite.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanSubsectorSiteID"), new[] { "SamplingPlanSubsectorSiteID" }));
                }

                if (!(from c in db.SamplingPlanSubsectorSites select c).Where(c => c.SamplingPlanSubsectorSiteID == samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID).Any())
                {
                    samplingPlanSubsectorSite.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsectorSite", "SamplingPlanSubsectorSiteID", samplingPlanSubsectorSite.SamplingPlanSubsectorSiteID.ToString()), new[] { "SamplingPlanSubsectorSiteID" }));
                }
            }

            SamplingPlanSubsector SamplingPlanSubsectorSamplingPlanSubsectorID = (from c in db.SamplingPlanSubsectors where c.SamplingPlanSubsectorID == samplingPlanSubsectorSite.SamplingPlanSubsectorID select c).FirstOrDefault();

            if (SamplingPlanSubsectorSamplingPlanSubsectorID == null)
            {
                samplingPlanSubsectorSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanSubsector", "SamplingPlanSubsectorID", samplingPlanSubsectorSite.SamplingPlanSubsectorID.ToString()), new[] { "SamplingPlanSubsectorID" }));
            }

            TVItem TVItemMWQMSiteTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlanSubsectorSite.MWQMSiteTVItemID select c).FirstOrDefault();

            if (TVItemMWQMSiteTVItemID == null)
            {
                samplingPlanSubsectorSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", samplingPlanSubsectorSite.MWQMSiteTVItemID.ToString()), new[] { "MWQMSiteTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.MWQMSite,
                };
                if (!AllowableTVTypes.Contains(TVItemMWQMSiteTVItemID.TVType))
                {
                    samplingPlanSubsectorSite.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), new[] { "MWQMSiteTVItemID" }));
                }
            }

            if (samplingPlanSubsectorSite.LastUpdateDate_UTC.Year == 1)
            {
                samplingPlanSubsectorSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (samplingPlanSubsectorSite.LastUpdateDate_UTC.Year < 1980)
                {
                    samplingPlanSubsectorSite.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == samplingPlanSubsectorSite.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                samplingPlanSubsectorSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanSubsectorSite.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    samplingPlanSubsectorSite.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                samplingPlanSubsectorSite.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Exemplo n.º 16
0
        public void SamplingPlanSubsector_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanSubsectorController samplingPlanSubsectorController = new SamplingPlanSubsectorController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanSubsectorController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanSubsectorController.DatabaseType);

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

                        SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(query, db, ContactID);
                        samplingPlanSubsectorLast = (from c in db.SamplingPlanSubsectors select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanSubsector info
                    IHttpActionResult jsonRet = samplingPlanSubsectorController.GetSamplingPlanSubsectorWithID(samplingPlanSubsectorLast.SamplingPlanSubsectorID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanSubsector> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    SamplingPlanSubsector samplingPlanSubsectorRet        = Ret.Content;
                    Assert.AreEqual(samplingPlanSubsectorLast.SamplingPlanSubsectorID, samplingPlanSubsectorRet.SamplingPlanSubsectorID);

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

                    // Post to return CSSPError because SamplingPlanSubsectorID exist
                    IHttpActionResult jsonRet2 = samplingPlanSubsectorController.Post(samplingPlanSubsectorRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNull(samplingPlanSubsectorRet2);

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

                    // Post to return newly added SamplingPlanSubsector
                    samplingPlanSubsectorRet.SamplingPlanSubsectorID   = 0;
                    samplingPlanSubsectorController.Request            = new System.Net.Http.HttpRequestMessage();
                    samplingPlanSubsectorController.Request.RequestUri = new System.Uri("http://localhost:5000/api/samplingPlanSubsector");
                    IHttpActionResult jsonRet3 = samplingPlanSubsectorController.Post(samplingPlanSubsectorRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet3 = jsonRet3 as CreatedNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNotNull(samplingPlanSubsectorRet3);

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

                    IHttpActionResult jsonRet4 = samplingPlanSubsectorController.Delete(samplingPlanSubsectorRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <SamplingPlanSubsector> samplingPlanSubsectorRet4 = jsonRet4 as OkNegotiatedContentResult <SamplingPlanSubsector>;
                    Assert.IsNotNull(samplingPlanSubsectorRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Exemplo n.º 17
0
 public SamplingPlanSubsectorTest()
 {
     samplingPlanSubsector       = new SamplingPlanSubsector();
     samplingPlanSubsectorExtraA = new SamplingPlanSubsectorExtraA();
     samplingPlanSubsectorExtraB = new SamplingPlanSubsectorExtraB();
 }
Exemplo n.º 18
0
        public void SamplingPlanSubsector_Controller_GetSamplingPlanSubsectorList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanSubsectorController samplingPlanSubsectorController = new SamplingPlanSubsectorController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanSubsectorController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanSubsectorController.DatabaseType);

                    SamplingPlanSubsector samplingPlanSubsectorFirst = new SamplingPlanSubsector();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(query, db, ContactID);
                        samplingPlanSubsectorFirst = (from c in db.SamplingPlanSubsectors select c).FirstOrDefault();
                        count = (from c in db.SamplingPlanSubsectors select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with SamplingPlanSubsector info
                    IHttpActionResult jsonRet = samplingPlanSubsectorController.GetSamplingPlanSubsectorList();
                    Assert.IsNotNull(jsonRet);

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

                    List <SamplingPlanSubsector> samplingPlanSubsectorList = new List <SamplingPlanSubsector>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanSubsectorService samplingPlanSubsectorService = new SamplingPlanSubsectorService(query, db, ContactID);
                        samplingPlanSubsectorList = (from c in db.SamplingPlanSubsectors select c).OrderBy(c => c.SamplingPlanSubsectorID).Skip(0).Take(2).ToList();
                        count = (from c in db.SamplingPlanSubsectors select c).Count();
                    }

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

                        // ok with SamplingPlanSubsector info
                        jsonRet = samplingPlanSubsectorController.GetSamplingPlanSubsectorList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlanSubsector> >;
                        Assert.AreEqual(samplingPlanSubsectorList[0].SamplingPlanSubsectorID, ret.Content[0].SamplingPlanSubsectorID);
                        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 SamplingPlanSubsector info
                            IHttpActionResult jsonRet2 = samplingPlanSubsectorController.GetSamplingPlanSubsectorList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <SamplingPlanSubsector> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SamplingPlanSubsector> >;
                            Assert.AreEqual(samplingPlanSubsectorList[1].SamplingPlanSubsectorID, ret2.Content[0].SamplingPlanSubsectorID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }