Example #1
0
        private MWQMLookupMPN GetFilledRandomMWQMLookupMPN(string OmitPropName)
        {
            MWQMLookupMPN mwqmLookupMPN = new MWQMLookupMPN();

            if (OmitPropName != "Tubes10")
            {
                mwqmLookupMPN.Tubes10 = GetRandomInt(2, 5);
            }
            if (OmitPropName != "Tubes1")
            {
                mwqmLookupMPN.Tubes1 = GetRandomInt(2, 5);
            }
            if (OmitPropName != "Tubes01")
            {
                mwqmLookupMPN.Tubes01 = GetRandomInt(2, 5);
            }
            if (OmitPropName != "MPN_100ml")
            {
                mwqmLookupMPN.MPN_100ml = 14;
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                mwqmLookupMPN.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                mwqmLookupMPN.LastUpdateContactTVItemID = 2;
            }

            return(mwqmLookupMPN);
        }
        public MWQMLookupMPN GetMWQMLookupMPNWithMWQMLookupMPNIDDB(int MWQMLookupMPNID)
        {
            MWQMLookupMPN mwqmLookupMPN = (from c in db.MWQMLookupMPNs
                                           where c.MWQMLookupMPNID == MWQMLookupMPNID
                                           select c).FirstOrDefault <MWQMLookupMPN>();

            return(mwqmLookupMPN);
        }
        public void MWQMLookupMPN_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

                    MWQMLookupMPN mwqmLookupMPNLast = new MWQMLookupMPN();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNLast = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNLast.MWQMLookupMPNID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>;
                    MWQMLookupMPN mwqmLookupMPNRet = Ret.Content;
                    Assert.AreEqual(mwqmLookupMPNLast.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID);

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

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

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNotNull(mwqmLookupMPNRet2);

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

                    // Put to return CSSPError because MWQMLookupMPNID of 0 does not exist
                    mwqmLookupMPNRet.MWQMLookupMPNID = 0;
                    IHttpActionResult jsonRet3 = mwqmLookupMPNController.Put(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNull(mwqmLookupMPNRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
        public MWQMLookupMPN GetMWQMLookupMPNExistDB(int Tubes10, int Tubes1, int Tubes01, int MPN_100ml)
        {
            MWQMLookupMPN mwqmLookupMPN = (from c in db.MWQMLookupMPNs
                                           where c.Tubes10 == Tubes10 &&
                                           c.Tubes1 == Tubes1 &&
                                           c.Tubes01 == Tubes01 &&
                                           c.MPN_100ml == MPN_100ml
                                           select c).FirstOrDefault <MWQMLookupMPN>();

            return(mwqmLookupMPN);
        }
Example #5
0
        public void MWQMLookupMPN_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    MWQMLookupMPN mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");

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

                    count = mwqmLookupMPNService.GetMWQMLookupMPNList().Count();

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

                    mwqmLookupMPNService.Add(mwqmLookupMPN);
                    if (mwqmLookupMPN.HasErrors)
                    {
                        Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, mwqmLookupMPNService.GetMWQMLookupMPNList().Where(c => c == mwqmLookupMPN).Any());
                    mwqmLookupMPNService.Update(mwqmLookupMPN);
                    if (mwqmLookupMPN.HasErrors)
                    {
                        Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                    mwqmLookupMPNService.Delete(mwqmLookupMPN);
                    if (mwqmLookupMPN.HasErrors)
                    {
                        Assert.AreEqual("", mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                }
            }
        }
        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);
            mwqmLookupMPNService  = new MWQMLookupMPNService((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);
            mwqmLookupMPNModelNew = new MWQMLookupMPNModel();
            mwqmLookupMPN         = new MWQMLookupMPN();
        }
        // Post
        public MWQMLookupMPNModel PostAddMWQMLookupMPNDB(MWQMLookupMPNModel mwqmLookupMPNModel)
        {
            string retStr = MWQMLookupMPNModelOK(mwqmLookupMPNModel);

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

            ContactOK contactOK = IsContactOK();

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

            MWQMLookupMPN mwqmLookupMPNExist = GetMWQMLookupMPNExistDB(mwqmLookupMPNModel.Tubes10, mwqmLookupMPNModel.Tubes1, mwqmLookupMPNModel.Tubes01, mwqmLookupMPNModel.MPN_100ml);

            if (mwqmLookupMPNExist != null)
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.MWQMLookupMPN)));
            }

            MWQMLookupMPN mwqmLookupMPNNew = new MWQMLookupMPN();

            retStr = FillMWQMLookupMPN(mwqmLookupMPNNew, mwqmLookupMPNModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("MWQMLookupMPNs", mwqmLookupMPNNew.MWQMLookupMPNID, LogCommandEnum.Add, mwqmLookupMPNNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetMWQMLookupMPNModelWithMWQMLookupMPNIDDB(mwqmLookupMPNNew.MWQMLookupMPNID));
        }
Example #8
0
        public IHttpActionResult GetMWQMLookupMPNWithID([FromUri] int MWQMLookupMPNID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mwqmLookupMPNService.Query = mwqmLookupMPNService.FillQuery(typeof(MWQMLookupMPN), lang, 0, 1, "", "", extra);

                if (mwqmLookupMPNService.Query.Extra == "A")
                {
                    MWQMLookupMPNExtraA mwqmLookupMPNExtraA = new MWQMLookupMPNExtraA();
                    mwqmLookupMPNExtraA = mwqmLookupMPNService.GetMWQMLookupMPNExtraAWithMWQMLookupMPNID(MWQMLookupMPNID);

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

                    return(Ok(mwqmLookupMPNExtraA));
                }
                else if (mwqmLookupMPNService.Query.Extra == "B")
                {
                    MWQMLookupMPNExtraB mwqmLookupMPNExtraB = new MWQMLookupMPNExtraB();
                    mwqmLookupMPNExtraB = mwqmLookupMPNService.GetMWQMLookupMPNExtraBWithMWQMLookupMPNID(MWQMLookupMPNID);

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

                    return(Ok(mwqmLookupMPNExtraB));
                }
                else
                {
                    MWQMLookupMPN mwqmLookupMPN = new MWQMLookupMPN();
                    mwqmLookupMPN = mwqmLookupMPNService.GetMWQMLookupMPNWithMWQMLookupMPNID(MWQMLookupMPNID);

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

                    return(Ok(mwqmLookupMPN));
                }
            }
        }
        public MWQMLookupMPNModel PostUpdateMWQMLookupMPNDB(MWQMLookupMPNModel mwqmLookupMPNModel)
        {
            string retStr = MWQMLookupMPNModelOK(mwqmLookupMPNModel);

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

            ContactOK contactOK = IsContactOK();

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

            MWQMLookupMPN mwqmLookupMPNToUpdate = GetMWQMLookupMPNWithMWQMLookupMPNIDDB(mwqmLookupMPNModel.MWQMLookupMPNID);

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

            retStr = FillMWQMLookupMPN(mwqmLookupMPNToUpdate, mwqmLookupMPNModel, 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("MWQMLookupMPNs", mwqmLookupMPNToUpdate.MWQMLookupMPNID, LogCommandEnum.Change, mwqmLookupMPNToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetMWQMLookupMPNModelWithMWQMLookupMPNIDDB(mwqmLookupMPNToUpdate.MWQMLookupMPNID));
        }
Example #10
0
        private bool TryToSave(MWQMLookupMPN mwqmLookupMPN)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                mwqmLookupMPN.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
Example #11
0
        public bool Update(MWQMLookupMPN mwqmLookupMPN)
        {
            mwqmLookupMPN.ValidationResults = Validate(new ValidationContext(mwqmLookupMPN), ActionDBTypeEnum.Update);
            if (mwqmLookupMPN.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.MWQMLookupMPNs.Update(mwqmLookupMPN);

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

            return(true);
        }
        // Fill
        public string FillMWQMLookupMPN(MWQMLookupMPN mwqmLookupMPNNew, MWQMLookupMPNModel mwqmLookupMPNModel, ContactOK contactOK)
        {
            mwqmLookupMPNNew.DBCommand          = (int)mwqmLookupMPNModel.DBCommand;
            mwqmLookupMPNNew.Tubes01            = mwqmLookupMPNModel.Tubes01;
            mwqmLookupMPNNew.Tubes1             = mwqmLookupMPNModel.Tubes1;
            mwqmLookupMPNNew.Tubes10            = mwqmLookupMPNModel.Tubes10;
            mwqmLookupMPNNew.MPN_100ml          = mwqmLookupMPNModel.MPN_100ml;
            mwqmLookupMPNNew.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                mwqmLookupMPNNew.LastUpdateContactTVItemID = 2;
            }
            else
            {
                mwqmLookupMPNNew.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
        public void MWQMLookupMPN_Controller_GetMWQMLookupMPNWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

                    MWQMLookupMPN mwqmLookupMPNFirst = new MWQMLookupMPN();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query(), db, ContactID);
                        mwqmLookupMPNFirst = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNFirst.MWQMLookupMPNID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>;
                    MWQMLookupMPN mwqmLookupMPNRet = Ret.Content;
                    Assert.AreEqual(mwqmLookupMPNFirst.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mwqmLookupMPNController.GetMWQMLookupMPNWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNull(mwqmLookupMPNRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Example #14
0
        public IHttpActionResult Delete([FromBody] MWQMLookupMPN mwqmLookupMPN, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

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

                using (TransactionScope ts = new TransactionScope())
                {
                    List <MWQMLookupMPNModel> mwqmLookupMPNModelList = mwqmLookupMPNService.GetMWQMLookupMPNModelListDB();
                    foreach (MWQMLookupMPNModel mwqmLookupMPNModel in mwqmLookupMPNModelList)
                    {
                        MWQMLookupMPNModel mwqmLookupMPNModelRet4 = mwqmLookupMPNService.PostDeleteMWQMLookupMPNDB(mwqmLookupMPNModel.MWQMLookupMPNID);
                        Assert.AreEqual("", mwqmLookupMPNModelRet4.Error);
                    }

                    MWQMLookupMPNModel mwqmLookupMPNModelRet = AddMWQMLookupMPNModel();

                    MWQMLookupMPN mwqmLookupMPN = mwqmLookupMPNService.GetMWQMLookupMPNExistDB(mwqmLookupMPNModelRet.Tubes10, mwqmLookupMPNModelRet.Tubes1, mwqmLookupMPNModelRet.Tubes01, mwqmLookupMPNModelRet.MPN_100ml);
                    Assert.AreEqual(mwqmLookupMPNModelRet.MWQMLookupMPNID, mwqmLookupMPN.MWQMLookupMPNID);
                }
            }
        }
Example #16
0
        public void GetMWQMLookupMPNList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    MWQMLookupMPN mwqmLookupMPN = (from c in dbTestDB.MWQMLookupMPNs select c).FirstOrDefault();
                    Assert.IsNotNull(mwqmLookupMPN);

                    List <MWQMLookupMPN> mwqmLookupMPNDirectQueryList = new List <MWQMLookupMPN>();
                    mwqmLookupMPNDirectQueryList = (from c in dbTestDB.MWQMLookupMPNs select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>();
                            mwqmLookupMPNList = mwqmLookupMPNService.GetMWQMLookupMPNList().ToList();
                            CheckMWQMLookupMPNFields(mwqmLookupMPNList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public MWQMLookupMPNModel PostDeleteMWQMLookupMPNDB(int MWQMLookupMPNID)
        {
            ContactOK contactOK = IsContactOK();

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

            MWQMLookupMPN MWQMLookupMPNToDelete = GetMWQMLookupMPNWithMWQMLookupMPNIDDB(MWQMLookupMPNID);

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

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

                LogModel logModel = _LogService.PostAddLogForObj("MWQMLookupMPNs", MWQMLookupMPNToDelete.MWQMLookupMPNID, LogCommandEnum.Delete, MWQMLookupMPNToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            return(ReturnError(""));
        }
Example #18
0
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string        retStr        = "";
            Enums         enums         = new Enums(LanguageRequest);
            MWQMLookupMPN mwqmLookupMPN = validationContext.ObjectInstance as MWQMLookupMPN;

            mwqmLookupMPN.HasErrors = false;

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

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

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

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

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

            if (mwqmLookupMPN.MPN_100ml < 1 || mwqmLookupMPN.MPN_100ml > 10000)
            {
                mwqmLookupMPN.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "MPN_100ml", "1", "10000"), new[] { "MPN_100ml" }));
            }

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

            if (TVItemLastUpdateContactTVItemID == null)
            {
                mwqmLookupMPN.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmLookupMPN.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    mwqmLookupMPN.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
            {
                mwqmLookupMPN.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
        public void MWQMLookupMPN_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

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

                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNLast = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNLast.MWQMLookupMPNID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>;
                    MWQMLookupMPN mwqmLookupMPNRet = Ret.Content;
                    Assert.AreEqual(mwqmLookupMPNLast.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID);

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

                    // Post to return newly added MWQMLookupMPN
                    mwqmLookupMPNRet.MWQMLookupMPNID           = 0;
                    mwqmLookupMPNRet.Tubes01                   = 1;
                    mwqmLookupMPNRet.Tubes1                    = 1;
                    mwqmLookupMPNRet.Tubes10                   = 1;
                    mwqmLookupMPNRet.MPN_100ml                 = 6;
                    mwqmLookupMPNController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmLookupMPNController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmLookupMPN");
                    IHttpActionResult jsonRet3 = mwqmLookupMPNController.Post(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNotNull(mwqmLookupMPNRet3);
                    MWQMLookupMPN mwqmLookupMPN = mwqmLookupMPNRet3.Content;

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

                    // Delete to return success
                    IHttpActionResult jsonRet2 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNotNull(mwqmLookupMPNRet2);

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

                    // Delete to return CSSPError because MWQMLookupMPNID of 0 does not exist
                    mwqmLookupMPNRet.MWQMLookupMPNID = 0;
                    IHttpActionResult jsonRet4 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNull(mwqmLookupMPNRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest4);
                }
            }
        }
        public void MWQMLookupMPN_Controller_GetMWQMLookupMPNList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

                    MWQMLookupMPN mwqmLookupMPNFirst = new MWQMLookupMPN();
                    int           count = -1;
                    Query         query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNFirst = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                        count = (from c in db.MWQMLookupMPNs select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNList = (from c in db.MWQMLookupMPNs select c).OrderBy(c => c.MWQMLookupMPNID).Skip(0).Take(2).ToList();
                        count             = (from c in db.MWQMLookupMPNs select c).Count();
                    }

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

                        // ok with MWQMLookupMPN info
                        jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MWQMLookupMPN> >;
                        Assert.AreEqual(mwqmLookupMPNList[0].MWQMLookupMPNID, ret.Content[0].MWQMLookupMPNID);
                        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 MWQMLookupMPN info
                            IHttpActionResult jsonRet2 = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MWQMLookupMPN> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMLookupMPN> >;
                            Assert.AreEqual(mwqmLookupMPNList[1].MWQMLookupMPNID, ret2.Content[0].MWQMLookupMPNID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Example #21
0
 public MWQMLookupMPNTest()
 {
     mWQMLookupMPN       = new MWQMLookupMPN();
     mWQMLookupMPNExtraA = new MWQMLookupMPNExtraA();
     mWQMLookupMPNExtraB = new MWQMLookupMPNExtraB();
 }
Example #22
0
        public void MWQMLookupMPN_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(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 = mwqmLookupMPNService.GetMWQMLookupMPNList().Count();

                    MWQMLookupMPN mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // mwqmLookupMPN.MWQMLookupMPNID   (Int32)
                    // -----------------------------------

                    mwqmLookupMPN = null;
                    mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.MWQMLookupMPNID = 0;
                    mwqmLookupMPNService.Update(mwqmLookupMPN);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMLookupMPNID"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmLookupMPN = null;
                    mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.MWQMLookupMPNID = 10000000;
                    mwqmLookupMPNService.Update(mwqmLookupMPN);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMLookupMPN", "MWQMLookupMPNID", mwqmLookupMPN.MWQMLookupMPNID.ToString()), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 5)]
                    // mwqmLookupMPN.Tubes10   (Int32)
                    // -----------------------------------

                    mwqmLookupMPN         = null;
                    mwqmLookupMPN         = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes10 = -1;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes10", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                    mwqmLookupMPN         = null;
                    mwqmLookupMPN         = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes10 = 6;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes10", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 5)]
                    // mwqmLookupMPN.Tubes1   (Int32)
                    // -----------------------------------

                    mwqmLookupMPN        = null;
                    mwqmLookupMPN        = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes1 = -1;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes1", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                    mwqmLookupMPN        = null;
                    mwqmLookupMPN        = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes1 = 6;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes1", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(0, 5)]
                    // mwqmLookupMPN.Tubes01   (Int32)
                    // -----------------------------------

                    mwqmLookupMPN         = null;
                    mwqmLookupMPN         = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes01 = -1;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes01", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                    mwqmLookupMPN         = null;
                    mwqmLookupMPN         = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.Tubes01 = 6;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Tubes01", "0", "5"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(1, 10000)]
                    // mwqmLookupMPN.MPN_100ml   (Int32)
                    // -----------------------------------

                    mwqmLookupMPN           = null;
                    mwqmLookupMPN           = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.MPN_100ml = 0;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "MPN_100ml", "1", "10000"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());
                    mwqmLookupMPN           = null;
                    mwqmLookupMPN           = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.MPN_100ml = 10001;
                    Assert.AreEqual(false, mwqmLookupMPNService.Add(mwqmLookupMPN));
                    Assert.AreEqual(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "MPN_100ml", "1", "10000"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmLookupMPNService.GetMWQMLookupMPNList().Count());

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

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

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

                    mwqmLookupMPN = null;
                    mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.LastUpdateContactTVItemID = 0;
                    mwqmLookupMPNService.Add(mwqmLookupMPN);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmLookupMPN.LastUpdateContactTVItemID.ToString()), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmLookupMPN = null;
                    mwqmLookupMPN = GetFilledRandomMWQMLookupMPN("");
                    mwqmLookupMPN.LastUpdateContactTVItemID = 1;
                    mwqmLookupMPNService.Add(mwqmLookupMPN);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmLookupMPN.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }