public IHttpActionResult GetMWQMSubsectorLanguageList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                       [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
 {
     using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
     {
         MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Example #2
0
        public void MWQMSubsectorLanguage_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSubsectorLanguageController mwqmSubsectorLanguageController = new MWQMSubsectorLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSubsectorLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSubsectorLanguageController.DatabaseType);

                    MWQMSubsectorLanguage mwqmSubsectorLanguageLast = new MWQMSubsectorLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(query, db, ContactID);
                        mwqmSubsectorLanguageLast = (from c in db.MWQMSubsectorLanguages select c).FirstOrDefault();
                    }

                    // ok with MWQMSubsectorLanguage info
                    IHttpActionResult jsonRet = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageWithID(mwqmSubsectorLanguageLast.MWQMSubsectorLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> Ret = jsonRet as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    MWQMSubsectorLanguage mwqmSubsectorLanguageRet        = Ret.Content;
                    Assert.AreEqual(mwqmSubsectorLanguageLast.MWQMSubsectorLanguageID, mwqmSubsectorLanguageRet.MWQMSubsectorLanguageID);

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

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

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNotNull(mwqmSubsectorLanguageRet2);

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

                    // Put to return CSSPError because MWQMSubsectorLanguageID of 0 does not exist
                    mwqmSubsectorLanguageRet.MWQMSubsectorLanguageID = 0;
                    IHttpActionResult jsonRet3 = mwqmSubsectorLanguageController.Put(mwqmSubsectorLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNull(mwqmSubsectorLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Example #3
0
        public void MWQMSubsectorLanguage_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    MWQMSubsectorLanguage mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");

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

                    count = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count();

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

                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    if (mwqmSubsectorLanguage.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Where(c => c == mwqmSubsectorLanguage).Any());
                    mwqmSubsectorLanguageService.Update(mwqmSubsectorLanguage);
                    if (mwqmSubsectorLanguage.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count());
                    mwqmSubsectorLanguageService.Delete(mwqmSubsectorLanguage);
                    if (mwqmSubsectorLanguage.HasErrors)
                    {
                        Assert.AreEqual("", mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count());
                }
            }
        }
Example #4
0
        public IHttpActionResult GetMWQMSubsectorLanguageWithID([FromUri] int MWQMSubsectorLanguageID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mwqmSubsectorLanguageService.Query = mwqmSubsectorLanguageService.FillQuery(typeof(MWQMSubsectorLanguage), lang, 0, 1, "", "", extra);

                if (mwqmSubsectorLanguageService.Query.Extra == "A")
                {
                    MWQMSubsectorLanguageExtraA mwqmSubsectorLanguageExtraA = new MWQMSubsectorLanguageExtraA();
                    mwqmSubsectorLanguageExtraA = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageExtraAWithMWQMSubsectorLanguageID(MWQMSubsectorLanguageID);

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

                    return(Ok(mwqmSubsectorLanguageExtraA));
                }
                else if (mwqmSubsectorLanguageService.Query.Extra == "B")
                {
                    MWQMSubsectorLanguageExtraB mwqmSubsectorLanguageExtraB = new MWQMSubsectorLanguageExtraB();
                    mwqmSubsectorLanguageExtraB = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageExtraBWithMWQMSubsectorLanguageID(MWQMSubsectorLanguageID);

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

                    return(Ok(mwqmSubsectorLanguageExtraB));
                }
                else
                {
                    MWQMSubsectorLanguage mwqmSubsectorLanguage = new MWQMSubsectorLanguage();
                    mwqmSubsectorLanguage = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageWithMWQMSubsectorLanguageID(MWQMSubsectorLanguageID);

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

                    return(Ok(mwqmSubsectorLanguage));
                }
            }
        }
Example #5
0
        public void SetupTest(ContactModel contactModelToDo, CultureInfo culture)
        {
            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

            contactModel                  = contactModelToDo;
            user                          = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null);
            mwqmSubsectorService          = new MWQMSubsectorService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            mwqmSubsectorLanguageService  = new MWQMSubsectorLanguageService((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);
            mwqmSubsectorLanguageModelNew = new MWQMSubsectorLanguageModel();
            mwqmSubsectorLanguage         = new MWQMSubsectorLanguage();
            mwqmSubsectorServiceTest      = new MWQMSubsectorServiceTest();
            mwqmSubsectorServiceTest.SetupTest(contactModelToDo, culture);
        }
Example #6
0
        public void MWQMSubsectorLanguage_Controller_GetMWQMSubsectorLanguageWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSubsectorLanguageController mwqmSubsectorLanguageController = new MWQMSubsectorLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSubsectorLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSubsectorLanguageController.DatabaseType);

                    MWQMSubsectorLanguage mwqmSubsectorLanguageFirst = new MWQMSubsectorLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(new Query(), db, ContactID);
                        mwqmSubsectorLanguageFirst = (from c in db.MWQMSubsectorLanguages select c).FirstOrDefault();
                    }

                    // ok with MWQMSubsectorLanguage info
                    IHttpActionResult jsonRet = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageWithID(mwqmSubsectorLanguageFirst.MWQMSubsectorLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> Ret = jsonRet as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    MWQMSubsectorLanguage mwqmSubsectorLanguageRet        = Ret.Content;
                    Assert.AreEqual(mwqmSubsectorLanguageFirst.MWQMSubsectorLanguageID, mwqmSubsectorLanguageRet.MWQMSubsectorLanguageID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNull(mwqmSubsectorLanguageRet2);

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

                if (!mwqmSubsectorLanguageService.Delete(mwqmSubsectorLanguage))
                {
                    return(BadRequest(String.Join("|||", mwqmSubsectorLanguage.ValidationResults)));
                }
                else
                {
                    mwqmSubsectorLanguage.ValidationResults = null;
                    return(Ok(mwqmSubsectorLanguage));
                }
            }
        }
Example #8
0
        public void MWQMSubsectorLanguageService_PostAddMWQMSubsectorLanguageDB_UserEmailNotValidated_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    MWQMSubsectorModel mwqmSubsectorModelRet = mwqmSubsectorServiceTest.AddMWQMSubsectorModel();

                    LanguageEnum LangToAdd = LanguageEnum.es;

                    ContactModel contactModelBad = contactModelListGood[2];
                    IPrincipal   userBad         = new GenericPrincipal(new GenericIdentity(contactModelBad.LoginEmail, "Forms"), null);
                    mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), userBad);

                    MWQMSubsectorLanguageModel mwqmSubsectorLanguageModelRet = AddMWQMSubsectorLanguageModel(LangToAdd, mwqmSubsectorModelRet);
                    Assert.AreEqual(ServiceRes.EmailRequiresValidation, mwqmSubsectorLanguageModelRet.Error);
                }
            }
        }
Example #9
0
        public void GetMWQMSubsectorLanguageList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    MWQMSubsectorLanguage mwqmSubsectorLanguage = (from c in dbTestDB.MWQMSubsectorLanguages select c).FirstOrDefault();
                    Assert.IsNotNull(mwqmSubsectorLanguage);

                    List <MWQMSubsectorLanguage> mwqmSubsectorLanguageDirectQueryList = new List <MWQMSubsectorLanguage>();
                    mwqmSubsectorLanguageDirectQueryList = (from c in dbTestDB.MWQMSubsectorLanguages select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MWQMSubsectorLanguage> mwqmSubsectorLanguageList = new List <MWQMSubsectorLanguage>();
                            mwqmSubsectorLanguageList = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().ToList();
                            CheckMWQMSubsectorLanguageFields(mwqmSubsectorLanguageList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Example #10
0
        public void GetMWQMSubsectorLanguageList_2Where_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                        mwqmSubsectorLanguageService.Query = mwqmSubsectorLanguageService.FillQuery(typeof(MWQMSubsectorLanguage), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "MWQMSubsectorLanguageID,GT,2|MWQMSubsectorLanguageID,LT,5", extra);

                        List <MWQMSubsectorLanguage> mwqmSubsectorLanguageDirectQueryList = new List <MWQMSubsectorLanguage>();
                        mwqmSubsectorLanguageDirectQueryList = (from c in dbTestDB.MWQMSubsectorLanguages select c).Where(c => c.MWQMSubsectorLanguageID > 2 && c.MWQMSubsectorLanguageID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <MWQMSubsectorLanguage> mwqmSubsectorLanguageList = new List <MWQMSubsectorLanguage>();
                            mwqmSubsectorLanguageList = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().ToList();
                            CheckMWQMSubsectorLanguageFields(mwqmSubsectorLanguageList);
                            Assert.AreEqual(mwqmSubsectorLanguageDirectQueryList[0].MWQMSubsectorLanguageID, mwqmSubsectorLanguageList[0].MWQMSubsectorLanguageID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Example #11
0
        public void MWQMSubsectorLanguage_Controller_GetMWQMSubsectorLanguageList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSubsectorLanguageController mwqmSubsectorLanguageController = new MWQMSubsectorLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSubsectorLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSubsectorLanguageController.DatabaseType);

                    MWQMSubsectorLanguage mwqmSubsectorLanguageFirst = new MWQMSubsectorLanguage();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(query, db, ContactID);
                        mwqmSubsectorLanguageFirst = (from c in db.MWQMSubsectorLanguages select c).FirstOrDefault();
                        count = (from c in db.MWQMSubsectorLanguages select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MWQMSubsectorLanguage info
                    IHttpActionResult jsonRet = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MWQMSubsectorLanguage> mwqmSubsectorLanguageList = new List <MWQMSubsectorLanguage>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(query, db, ContactID);
                        mwqmSubsectorLanguageList = (from c in db.MWQMSubsectorLanguages select c).OrderBy(c => c.MWQMSubsectorLanguageID).Skip(0).Take(2).ToList();
                        count = (from c in db.MWQMSubsectorLanguages select c).Count();
                    }

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

                        // ok with MWQMSubsectorLanguage info
                        jsonRet = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MWQMSubsectorLanguage> >;
                        Assert.AreEqual(mwqmSubsectorLanguageList[0].MWQMSubsectorLanguageID, ret.Content[0].MWQMSubsectorLanguageID);
                        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 MWQMSubsectorLanguage info
                            IHttpActionResult jsonRet2 = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MWQMSubsectorLanguage> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMSubsectorLanguage> >;
                            Assert.AreEqual(mwqmSubsectorLanguageList[1].MWQMSubsectorLanguageID, ret2.Content[0].MWQMSubsectorLanguageID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Example #12
0
        public void MWQMSubsectorLanguage_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSubsectorLanguageController mwqmSubsectorLanguageController = new MWQMSubsectorLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSubsectorLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSubsectorLanguageController.DatabaseType);

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

                        MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(query, db, ContactID);
                        mwqmSubsectorLanguageLast = (from c in db.MWQMSubsectorLanguages select c).FirstOrDefault();
                    }

                    // ok with MWQMSubsectorLanguage info
                    IHttpActionResult jsonRet = mwqmSubsectorLanguageController.GetMWQMSubsectorLanguageWithID(mwqmSubsectorLanguageLast.MWQMSubsectorLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> Ret = jsonRet as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    MWQMSubsectorLanguage mwqmSubsectorLanguageRet        = Ret.Content;
                    Assert.AreEqual(mwqmSubsectorLanguageLast.MWQMSubsectorLanguageID, mwqmSubsectorLanguageRet.MWQMSubsectorLanguageID);

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

                    // Post to return CSSPError because MWQMSubsectorLanguageID exist
                    IHttpActionResult jsonRet2 = mwqmSubsectorLanguageController.Post(mwqmSubsectorLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNull(mwqmSubsectorLanguageRet2);

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

                    // Post to return newly added MWQMSubsectorLanguage
                    mwqmSubsectorLanguageRet.MWQMSubsectorLanguageID   = 0;
                    mwqmSubsectorLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmSubsectorLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmSubsectorLanguage");
                    IHttpActionResult jsonRet3 = mwqmSubsectorLanguageController.Post(mwqmSubsectorLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNotNull(mwqmSubsectorLanguageRet3);

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

                    IHttpActionResult jsonRet4 = mwqmSubsectorLanguageController.Delete(mwqmSubsectorLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMSubsectorLanguage> mwqmSubsectorLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMSubsectorLanguage>;
                    Assert.IsNotNull(mwqmSubsectorLanguageRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Example #13
0
        public void MWQMSubsectorLanguage_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(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 = mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count();

                    MWQMSubsectorLanguage mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // mwqmSubsectorLanguage.MWQMSubsectorLanguageID   (Int32)
                    // -----------------------------------

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.MWQMSubsectorLanguageID = 0;
                    mwqmSubsectorLanguageService.Update(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "MWQMSubsectorLanguageID"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.MWQMSubsectorLanguageID = 10000000;
                    mwqmSubsectorLanguageService.Update(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSubsectorLanguage", "MWQMSubsectorLanguageID", mwqmSubsectorLanguage.MWQMSubsectorLanguageID.ToString()), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "MWQMSubsector", ExistPlurial = "s", ExistFieldID = "MWQMSubsectorID", AllowableTVtypeList = )]
                    // mwqmSubsectorLanguage.MWQMSubsectorID   (Int32)
                    // -----------------------------------

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.MWQMSubsectorID = 0;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "MWQMSubsector", "MWQMSubsectorID", mwqmSubsectorLanguage.MWQMSubsectorID.ToString()), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // mwqmSubsectorLanguage.Language   (LanguageEnum)
                    // -----------------------------------

                    mwqmSubsectorLanguage          = null;
                    mwqmSubsectorLanguage          = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.Language = (LanguageEnum)1000000;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "Language"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(250))]
                    // mwqmSubsectorLanguage.SubsectorDesc   (String)
                    // -----------------------------------

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("SubsectorDesc");
                    Assert.AreEqual(false, mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage));
                    Assert.AreEqual(1, mwqmSubsectorLanguage.ValidationResults.Count());
                    Assert.IsTrue(mwqmSubsectorLanguage.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "SubsectorDesc")).Any());
                    Assert.AreEqual(null, mwqmSubsectorLanguage.SubsectorDesc);
                    Assert.AreEqual(count, mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count());

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.SubsectorDesc = GetRandomString("", 251);
                    Assert.AreEqual(false, mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "SubsectorDesc", "250"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPEnumType]
                    // mwqmSubsectorLanguage.TranslationStatusSubsectorDesc   (TranslationStatusEnum)
                    // -----------------------------------

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.TranslationStatusSubsectorDesc = (TranslationStatusEnum)1000000;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusSubsectorDesc"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is Nullable
                    // mwqmSubsectorLanguage.LogBook   (String)
                    // -----------------------------------


                    // -----------------------------------
                    // Is Nullable
                    // [CSSPEnumType]
                    // mwqmSubsectorLanguage.TranslationStatusLogBook   (TranslationStatusEnum)
                    // -----------------------------------

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.TranslationStatusLogBook = (TranslationStatusEnum)1000000;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "TranslationStatusLogBook"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

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

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

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.LastUpdateContactTVItemID = 0;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", mwqmSubsectorLanguage.LastUpdateContactTVItemID.ToString()), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);

                    mwqmSubsectorLanguage = null;
                    mwqmSubsectorLanguage = GetFilledRandomMWQMSubsectorLanguage("");
                    mwqmSubsectorLanguage.LastUpdateContactTVItemID = 1;
                    mwqmSubsectorLanguageService.Add(mwqmSubsectorLanguage);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), mwqmSubsectorLanguage.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
Example #14
0
        public IHttpActionResult GetMWQMSubsectorLanguageList([FromUri] string lang = "en", [FromUri] int skip  = 0, [FromUri] int take      = 200,
                                                              [FromUri] string asc  = "", [FromUri] string desc = "", [FromUri] string where = "", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MWQMSubsectorLanguageService mwqmSubsectorLanguageService = new MWQMSubsectorLanguageService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (mwqmSubsectorLanguageService.Query.HasErrors)
                    {
                        return(Ok(new List <MWQMSubsectorLanguage>()
                        {
                            new MWQMSubsectorLanguage()
                            {
                                HasErrors = mwqmSubsectorLanguageService.Query.HasErrors,
                                ValidationResults = mwqmSubsectorLanguageService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mwqmSubsectorLanguageService.GetMWQMSubsectorLanguageList().ToList()));
                    }
                }
            }
        }