private MWQMSite GetFilledRandomMWQMSite(string OmitPropName)
        {
            MWQMSite mwqmSite = new MWQMSite();

            if (OmitPropName != "MWQMSiteTVItemID")
            {
                mwqmSite.MWQMSiteTVItemID = 44;
            }
            if (OmitPropName != "MWQMSiteNumber")
            {
                mwqmSite.MWQMSiteNumber = GetRandomString("", 5);
            }
            if (OmitPropName != "MWQMSiteDescription")
            {
                mwqmSite.MWQMSiteDescription = GetRandomString("", 5);
            }
            if (OmitPropName != "MWQMSiteLatestClassification")
            {
                mwqmSite.MWQMSiteLatestClassification = (MWQMSiteLatestClassificationEnum)GetRandomEnumType(typeof(MWQMSiteLatestClassificationEnum));
            }
            if (OmitPropName != "Ordinal")
            {
                mwqmSite.Ordinal = GetRandomInt(0, 1000);
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                mwqmSite.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                mwqmSite.LastUpdateContactTVItemID = 2;
            }

            return(mwqmSite);
        }
Пример #2
0
        public MWQMSite GetMWQMSiteWithMWQMSiteIDDB(int MWQMSiteID)
        {
            MWQMSite MWQMSite = (from c in db.MWQMSites
                                 where c.MWQMSiteID == MWQMSiteID
                                 select c).FirstOrDefault <MWQMSite>();

            return(MWQMSite);
        }
Пример #3
0
        public void MWQMSite_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSiteController mwqmSiteController = new MWQMSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteController.DatabaseType);

                    MWQMSite mwqmSiteLast = new MWQMSite();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMSiteService mwqmSiteService = new MWQMSiteService(query, db, ContactID);
                        mwqmSiteLast = (from c in db.MWQMSites select c).FirstOrDefault();
                    }

                    // ok with MWQMSite info
                    IHttpActionResult jsonRet = mwqmSiteController.GetMWQMSiteWithID(mwqmSiteLast.MWQMSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSite> Ret = jsonRet as OkNegotiatedContentResult <MWQMSite>;
                    MWQMSite mwqmSiteRet = Ret.Content;
                    Assert.AreEqual(mwqmSiteLast.MWQMSiteID, mwqmSiteRet.MWQMSiteID);

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

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

                    OkNegotiatedContentResult <MWQMSite> mwqmSiteRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSite>;
                    Assert.IsNotNull(mwqmSiteRet2);

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

                    // Put to return CSSPError because MWQMSiteID of 0 does not exist
                    mwqmSiteRet.MWQMSiteID = 0;
                    IHttpActionResult jsonRet3 = mwqmSiteController.Put(mwqmSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMSite> mwqmSiteRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMSite>;
                    Assert.IsNull(mwqmSiteRet3);

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

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

                    MWQMSite mwqmSite = GetFilledRandomMWQMSite("");

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

                    count = mwqmSiteService.GetMWQMSiteList().Count();

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

                    mwqmSiteService.Add(mwqmSite);
                    if (mwqmSite.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, mwqmSiteService.GetMWQMSiteList().Where(c => c == mwqmSite).Any());
                    mwqmSiteService.Update(mwqmSite);
                    if (mwqmSite.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, mwqmSiteService.GetMWQMSiteList().Count());
                    mwqmSiteService.Delete(mwqmSite);
                    if (mwqmSite.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());
                }
            }
        }
Пример #5
0
        public MWQMSiteModel PostAddMWQMSiteDB(MWQMSiteModel mwqmSiteModel)
        {
            string retStr = MWQMSiteModelOK(mwqmSiteModel);

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

            ContactOK contactOK = IsContactOK();

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

            TVItemModel tvItemModelExist = _TVItemService.GetTVItemModelWithTVItemIDDB(mwqmSiteModel.MWQMSiteTVItemID);

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

            MWQMSite mwqmSiteNew = new MWQMSite();

            retStr = FillMWQMSite(mwqmSiteNew, mwqmSiteModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("MWQMSites", mwqmSiteNew.MWQMSiteID, LogCommandEnum.Add, mwqmSiteNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetMWQMSiteModelWithMWQMSiteIDDB(mwqmSiteNew.MWQMSiteID));
        }
Пример #6
0
        public IHttpActionResult GetMWQMSiteWithID([FromUri] int MWQMSiteID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mwqmSiteService.Query = mwqmSiteService.FillQuery(typeof(MWQMSite), lang, 0, 1, "", "", extra);

                if (mwqmSiteService.Query.Extra == "A")
                {
                    MWQMSiteExtraA mwqmSiteExtraA = new MWQMSiteExtraA();
                    mwqmSiteExtraA = mwqmSiteService.GetMWQMSiteExtraAWithMWQMSiteID(MWQMSiteID);

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

                    return(Ok(mwqmSiteExtraA));
                }
                else if (mwqmSiteService.Query.Extra == "B")
                {
                    MWQMSiteExtraB mwqmSiteExtraB = new MWQMSiteExtraB();
                    mwqmSiteExtraB = mwqmSiteService.GetMWQMSiteExtraBWithMWQMSiteID(MWQMSiteID);

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

                    return(Ok(mwqmSiteExtraB));
                }
                else
                {
                    MWQMSite mwqmSite = new MWQMSite();
                    mwqmSite = mwqmSiteService.GetMWQMSiteWithMWQMSiteID(MWQMSiteID);

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

                    return(Ok(mwqmSite));
                }
            }
        }
Пример #7
0
        public MWQMSiteModel PostUpdateMWQMSiteDB(MWQMSiteModel mwqmSiteModel)
        {
            string retStr = MWQMSiteModelOK(mwqmSiteModel);

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

            ContactOK contactOK = IsContactOK();

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

            MWQMSite mwqmSiteToUpdate = GetMWQMSiteWithMWQMSiteIDDB(mwqmSiteModel.MWQMSiteID);

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

            retStr = FillMWQMSite(mwqmSiteToUpdate, mwqmSiteModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("MWQMSites", mwqmSiteToUpdate.MWQMSiteID, LogCommandEnum.Change, mwqmSiteToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetMWQMSiteModelWithMWQMSiteIDDB(mwqmSiteToUpdate.MWQMSiteID));
        }
        private bool TryToSave(MWQMSite mwqmSite)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                mwqmSite.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

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

            db.MWQMSites.Update(mwqmSite);

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

            return(true);
        }
Пример #10
0
        public void MWQMSite_Controller_GetMWQMSiteWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSiteController mwqmSiteController = new MWQMSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteController.DatabaseType);

                    MWQMSite mwqmSiteFirst = new MWQMSite();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query(), db, ContactID);
                        mwqmSiteFirst = (from c in db.MWQMSites select c).FirstOrDefault();
                    }

                    // ok with MWQMSite info
                    IHttpActionResult jsonRet = mwqmSiteController.GetMWQMSiteWithID(mwqmSiteFirst.MWQMSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSite> Ret = jsonRet as OkNegotiatedContentResult <MWQMSite>;
                    MWQMSite mwqmSiteRet = Ret.Content;
                    Assert.AreEqual(mwqmSiteFirst.MWQMSiteID, mwqmSiteRet.MWQMSiteID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mwqmSiteController.GetMWQMSiteWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSite> mwqmSiteRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSite>;
                    Assert.IsNull(mwqmSiteRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Пример #11
0
        // Fill
        public string FillMWQMSite(MWQMSite mwqmSite, MWQMSiteModel mwqmSiteModel, ContactOK contactOK)
        {
            mwqmSite.DBCommand                    = (int)mwqmSiteModel.DBCommand;
            mwqmSite.MWQMSiteTVItemID             = mwqmSiteModel.MWQMSiteTVItemID;
            mwqmSite.MWQMSiteNumber               = mwqmSiteModel.MWQMSiteNumber;
            mwqmSite.MWQMSiteDescription          = mwqmSiteModel.MWQMSiteDescription;
            mwqmSite.MWQMSiteLatestClassification = (int)mwqmSiteModel.MWQMSiteLatestClassification;
            mwqmSite.Ordinal            = mwqmSiteModel.Ordinal;
            mwqmSite.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                mwqmSite.LastUpdateContactTVItemID = 2;
            }
            else
            {
                mwqmSite.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Пример #12
0
        public IHttpActionResult Delete([FromBody] MWQMSite mwqmSite, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

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

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMSiteService mwqmSiteService = new MWQMSiteService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    MWQMSite mwqmSite = (from c in dbTestDB.MWQMSites select c).FirstOrDefault();
                    Assert.IsNotNull(mwqmSite);

                    List <MWQMSite> mwqmSiteDirectQueryList = new List <MWQMSite>();
                    mwqmSiteDirectQueryList = (from c in dbTestDB.MWQMSites select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MWQMSite> mwqmSiteList = new List <MWQMSite>();
                            mwqmSiteList = mwqmSiteService.GetMWQMSiteList().ToList();
                            CheckMWQMSiteFields(mwqmSiteList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public void MWQMSite_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMSiteService mwqmSiteService = new MWQMSiteService(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 = mwqmSiteService.GetMWQMSiteList().Count();

                    MWQMSite mwqmSite = GetFilledRandomMWQMSite("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // mwqmSite.MWQMSiteID   (Int32)
                    // -----------------------------------

                    mwqmSite            = null;
                    mwqmSite            = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteID = 0;
                    mwqmSiteService.Update(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteID"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmSite            = null;
                    mwqmSite            = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteID = 10000000;
                    mwqmSiteService.Update(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSite", "MWQMSiteID", mwqmSite.MWQMSiteID.ToString()), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = MWQMSite)]
                    // mwqmSite.MWQMSiteTVItemID   (Int32)
                    // -----------------------------------

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteTVItemID = 0;
                    mwqmSiteService.Add(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMSiteTVItemID", mwqmSite.MWQMSiteTVItemID.ToString()), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteTVItemID = 1;
                    mwqmSiteService.Add(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMSiteTVItemID", "MWQMSite"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(8))]
                    // mwqmSite.MWQMSiteNumber   (String)
                    // -----------------------------------

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("MWQMSiteNumber");
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(1, mwqmSite.ValidationResults.Count());
                    Assert.IsTrue(mwqmSite.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "MWQMSiteNumber")).Any());
                    Assert.AreEqual(null, mwqmSite.MWQMSiteNumber);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteNumber = GetRandomString("", 9);
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "MWQMSiteNumber", "8"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(200))]
                    // mwqmSite.MWQMSiteDescription   (String)
                    // -----------------------------------

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("MWQMSiteDescription");
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(1, mwqmSite.ValidationResults.Count());
                    Assert.IsTrue(mwqmSite.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "MWQMSiteDescription")).Any());
                    Assert.AreEqual(null, mwqmSite.MWQMSiteDescription);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteDescription = GetRandomString("", 201);
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "MWQMSiteDescription", "200"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // mwqmSite.MWQMSiteLatestClassification   (MWQMSiteLatestClassificationEnum)
                    // -----------------------------------

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.MWQMSiteLatestClassification = (MWQMSiteLatestClassificationEnum)1000000;
                    mwqmSiteService.Add(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteLatestClassification"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    mwqmSite         = null;
                    mwqmSite         = GetFilledRandomMWQMSite("");
                    mwqmSite.Ordinal = -1;
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());
                    mwqmSite         = null;
                    mwqmSite         = GetFilledRandomMWQMSite("");
                    mwqmSite.Ordinal = 1001;
                    Assert.AreEqual(false, mwqmSiteService.Add(mwqmSite));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmSiteService.GetMWQMSiteList().Count());

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

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

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

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.LastUpdateContactTVItemID = 0;
                    mwqmSiteService.Add(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSite.LastUpdateContactTVItemID.ToString()), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmSite = null;
                    mwqmSite = GetFilledRandomMWQMSite("");
                    mwqmSite.LastUpdateContactTVItemID = 1;
                    mwqmSiteService.Add(mwqmSite);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmSite.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
Пример #15
0
        public MWQMSiteModel PostDeleteMWQMSiteDB(int MWQMSiteID)
        {
            ContactOK contactOK = IsContactOK();

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

            MWQMSite mwqmSiteToDelete = GetMWQMSiteWithMWQMSiteIDDB(MWQMSiteID);

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

            int TVItemIDToDelete = mwqmSiteToDelete.MWQMSiteTVItemID;

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

                LogModel logModel = _LogService.PostAddLogForObj("MWQMSites", mwqmSiteToDelete.MWQMSiteID, LogCommandEnum.Delete, mwqmSiteToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                List <MWQMSiteStartEndDateModel> mwqmsiteStartEndDateModelList = _MWQMSiteStartEndDateService.GetMWQMSiteStartEndDateModelListWithMWQMSiteTVItemIDDB(mwqmSiteToDelete.MWQMSiteTVItemID);

                foreach (MWQMSiteStartEndDateModel mwqmSiteStartEndDateModel in mwqmsiteStartEndDateModelList)
                {
                    MWQMSiteStartEndDateModel mwqmSiteStartEndDateModelRet = _MWQMSiteStartEndDateService.PostDeleteMWQMSiteStartEndDateDB(mwqmSiteStartEndDateModel.MWQMSiteStartEndDateID);
                    if (!string.IsNullOrWhiteSpace(mwqmSiteStartEndDateModelRet.Error))
                    {
                        return(ReturnError(mwqmSiteStartEndDateModelRet.Error));
                    }
                }

                List <MapInfoModel> mapInfoModelList = _MapInfoService.GetMapInfoModelListWithTVItemIDDB(mwqmSiteToDelete.MWQMSiteID);

                foreach (MapInfoModel mapInfoModel in mapInfoModelList)
                {
                    MapInfoModel mapInfoModelRet = _MapInfoService.PostDeleteMapInfoDB(mapInfoModel.MapInfoID);
                    if (!string.IsNullOrWhiteSpace(mapInfoModelRet.Error))
                    {
                        return(ReturnError(mapInfoModelRet.Error));
                    }
                }

                TVItemModel tvItemModelRet = _TVItemService.PostDeleteTVItemWithTVItemIDDB(TVItemIDToDelete);
                if (!string.IsNullOrWhiteSpace(tvItemModelRet.Error))
                {
                    return(ReturnError(tvItemModelRet.Error));
                }

                ts.Complete();
            }

            return(ReturnError(""));
        }
Пример #16
0
        public void MWQMSite_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSiteController mwqmSiteController = new MWQMSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteController.DatabaseType);

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

                        MWQMSiteService mwqmSiteService = new MWQMSiteService(query, db, ContactID);
                        mwqmSiteLast = (from c in db.MWQMSites select c).FirstOrDefault();
                    }

                    // ok with MWQMSite info
                    IHttpActionResult jsonRet = mwqmSiteController.GetMWQMSiteWithID(mwqmSiteLast.MWQMSiteID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSite> Ret = jsonRet as OkNegotiatedContentResult <MWQMSite>;
                    MWQMSite mwqmSiteRet = Ret.Content;
                    Assert.AreEqual(mwqmSiteLast.MWQMSiteID, mwqmSiteRet.MWQMSiteID);

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

                    // Post to return CSSPError because MWQMSiteID exist
                    IHttpActionResult jsonRet2 = mwqmSiteController.Post(mwqmSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSite> mwqmSiteRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSite>;
                    Assert.IsNull(mwqmSiteRet2);

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

                    // Post to return newly added MWQMSite
                    mwqmSiteRet.MWQMSiteID                = 0;
                    mwqmSiteController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmSiteController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmSite");
                    IHttpActionResult jsonRet3 = mwqmSiteController.Post(mwqmSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMSite> mwqmSiteRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMSite>;
                    Assert.IsNotNull(mwqmSiteRet3);

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

                    IHttpActionResult jsonRet4 = mwqmSiteController.Delete(mwqmSiteRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMSite> mwqmSiteRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMSite>;
                    Assert.IsNotNull(mwqmSiteRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string   retStr   = "";
            Enums    enums    = new Enums(LanguageRequest);
            MWQMSite mwqmSite = validationContext.ObjectInstance as MWQMSite;

            mwqmSite.HasErrors = false;

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

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

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

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

            if (string.IsNullOrWhiteSpace(mwqmSite.MWQMSiteNumber))
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteNumber"), new[] { "MWQMSiteNumber" }));
            }

            if (!string.IsNullOrWhiteSpace(mwqmSite.MWQMSiteNumber) && mwqmSite.MWQMSiteNumber.Length > 8)
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "MWQMSiteNumber", "8"), new[] { "MWQMSiteNumber" }));
            }

            if (string.IsNullOrWhiteSpace(mwqmSite.MWQMSiteDescription))
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteDescription"), new[] { "MWQMSiteDescription" }));
            }

            if (!string.IsNullOrWhiteSpace(mwqmSite.MWQMSiteDescription) && mwqmSite.MWQMSiteDescription.Length > 200)
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "MWQMSiteDescription", "200"), new[] { "MWQMSiteDescription" }));
            }

            retStr = enums.EnumTypeOK(typeof(MWQMSiteLatestClassificationEnum), (int?)mwqmSite.MWQMSiteLatestClassification);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "MWQMSiteLatestClassification"), new[] { "MWQMSiteLatestClassification" }));
            }

            if (mwqmSite.Ordinal < 0 || mwqmSite.Ordinal > 1000)
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Ordinal", "0", "1000"), new[] { "Ordinal" }));
            }

            if (mwqmSite.LastUpdateDate_UTC.Year == 1)
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (mwqmSite.LastUpdateDate_UTC.Year < 1980)
                {
                    mwqmSite.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 == mwqmSite.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSite.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    mwqmSite.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
            {
                mwqmSite.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Пример #18
0
        public void MWQMSite_Controller_GetMWQMSiteList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSiteController mwqmSiteController = new MWQMSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSiteController.DatabaseType);

                    MWQMSite mwqmSiteFirst = new MWQMSite();
                    int      count         = -1;
                    Query    query         = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSiteService mwqmSiteService = new MWQMSiteService(query, db, ContactID);
                        mwqmSiteFirst = (from c in db.MWQMSites select c).FirstOrDefault();
                        count         = (from c in db.MWQMSites select c).Count();
                        count         = (query.Take > count ? count : query.Take);
                    }

                    // ok with MWQMSite info
                    IHttpActionResult jsonRet = mwqmSiteController.GetMWQMSiteList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MWQMSite> mwqmSiteList = new List <MWQMSite>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSiteService mwqmSiteService = new MWQMSiteService(query, db, ContactID);
                        mwqmSiteList = (from c in db.MWQMSites select c).OrderBy(c => c.MWQMSiteID).Skip(0).Take(2).ToList();
                        count        = (from c in db.MWQMSites select c).Count();
                    }

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

                        // ok with MWQMSite info
                        jsonRet = mwqmSiteController.GetMWQMSiteList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MWQMSite> >;
                        Assert.AreEqual(mwqmSiteList[0].MWQMSiteID, ret.Content[0].MWQMSiteID);
                        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 MWQMSite info
                            IHttpActionResult jsonRet2 = mwqmSiteController.GetMWQMSiteList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MWQMSite> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMSite> >;
                            Assert.AreEqual(mwqmSiteList[1].MWQMSiteID, ret2.Content[0].MWQMSiteID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Пример #19
0
 public MWQMSiteTest()
 {
     mWQMSite       = new MWQMSite();
     mWQMSiteExtraA = new MWQMSiteExtraA();
     mWQMSiteExtraB = new MWQMSiteExtraB();
 }