public IHttpActionResult GetSamplingPlanEmailList([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))
     {
         SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Beispiel #2
0
        public void SamplingPlanEmail_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanEmailController samplingPlanEmailController = new SamplingPlanEmailController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanEmailController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanEmailController.DatabaseType);

                    SamplingPlanEmail samplingPlanEmailLast = new SamplingPlanEmail();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(query, db, ContactID);
                        samplingPlanEmailLast = (from c in db.SamplingPlanEmails select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanEmail info
                    IHttpActionResult jsonRet = samplingPlanEmailController.GetSamplingPlanEmailWithID(samplingPlanEmailLast.SamplingPlanEmailID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanEmail> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanEmail>;
                    SamplingPlanEmail samplingPlanEmailRet            = Ret.Content;
                    Assert.AreEqual(samplingPlanEmailLast.SamplingPlanEmailID, samplingPlanEmailRet.SamplingPlanEmailID);

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

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

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNotNull(samplingPlanEmailRet2);

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

                    // Put to return CSSPError because SamplingPlanEmailID of 0 does not exist
                    samplingPlanEmailRet.SamplingPlanEmailID = 0;
                    IHttpActionResult jsonRet3 = samplingPlanEmailController.Put(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet3 = jsonRet3 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNull(samplingPlanEmailRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Beispiel #3
0
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     _AppTaskService                   = new AppTaskService(LanguageRequest, User);
     _SamplingPlanService              = new SamplingPlanService(LanguageRequest, User);
     _SamplingPlanEmailService         = new SamplingPlanEmailService(LanguageRequest, User);
     _SamplingPlanSubsectorService     = new SamplingPlanSubsectorService(LanguageRequest, User);
     _SamplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(LanguageRequest, User);
     _TVFileService   = new TVFileService(LanguageRequest, User);
     _LabSheetService = new LabSheetService(LanguageRequest, User);
     _BaseEnumService = new BaseEnumService(LanguageRequest);
 }
        public void SamplingPlanEmail_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

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

                    SamplingPlanEmail samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");

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

                    count = samplingPlanEmailService.GetSamplingPlanEmailList().Count();

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

                    samplingPlanEmailService.Add(samplingPlanEmail);
                    if (samplingPlanEmail.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, samplingPlanEmailService.GetSamplingPlanEmailList().Where(c => c == samplingPlanEmail).Any());
                    samplingPlanEmailService.Update(samplingPlanEmail);
                    if (samplingPlanEmail.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, samplingPlanEmailService.GetSamplingPlanEmailList().Count());
                    samplingPlanEmailService.Delete(samplingPlanEmail);
                    if (samplingPlanEmail.HasErrors)
                    {
                        Assert.AreEqual("", samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, samplingPlanEmailService.GetSamplingPlanEmailList().Count());
                }
            }
        }
        public IHttpActionResult GetSamplingPlanEmailWithID([FromUri] int SamplingPlanEmailID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                samplingPlanEmailService.Query = samplingPlanEmailService.FillQuery(typeof(SamplingPlanEmail), lang, 0, 1, "", "", extra);

                if (samplingPlanEmailService.Query.Extra == "A")
                {
                    SamplingPlanEmailExtraA samplingPlanEmailExtraA = new SamplingPlanEmailExtraA();
                    samplingPlanEmailExtraA = samplingPlanEmailService.GetSamplingPlanEmailExtraAWithSamplingPlanEmailID(SamplingPlanEmailID);

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

                    return(Ok(samplingPlanEmailExtraA));
                }
                else if (samplingPlanEmailService.Query.Extra == "B")
                {
                    SamplingPlanEmailExtraB samplingPlanEmailExtraB = new SamplingPlanEmailExtraB();
                    samplingPlanEmailExtraB = samplingPlanEmailService.GetSamplingPlanEmailExtraBWithSamplingPlanEmailID(SamplingPlanEmailID);

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

                    return(Ok(samplingPlanEmailExtraB));
                }
                else
                {
                    SamplingPlanEmail samplingPlanEmail = new SamplingPlanEmail();
                    samplingPlanEmail = samplingPlanEmailService.GetSamplingPlanEmailWithSamplingPlanEmailID(SamplingPlanEmailID);

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

                    return(Ok(samplingPlanEmail));
                }
            }
        }
Beispiel #6
0
        public void SamplingPlanEmail_Controller_GetSamplingPlanEmailWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanEmailController samplingPlanEmailController = new SamplingPlanEmailController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanEmailController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanEmailController.DatabaseType);

                    SamplingPlanEmail samplingPlanEmailFirst = new SamplingPlanEmail();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query(), db, ContactID);
                        samplingPlanEmailFirst = (from c in db.SamplingPlanEmails select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanEmail info
                    IHttpActionResult jsonRet = samplingPlanEmailController.GetSamplingPlanEmailWithID(samplingPlanEmailFirst.SamplingPlanEmailID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanEmail> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanEmail>;
                    SamplingPlanEmail samplingPlanEmailRet            = Ret.Content;
                    Assert.AreEqual(samplingPlanEmailFirst.SamplingPlanEmailID, samplingPlanEmailRet.SamplingPlanEmailID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = samplingPlanEmailController.GetSamplingPlanEmailWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNull(samplingPlanEmailRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([FromBody] SamplingPlanEmail samplingPlanEmail, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

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

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    SamplingPlanEmail samplingPlanEmail = (from c in dbTestDB.SamplingPlanEmails select c).FirstOrDefault();
                    Assert.IsNotNull(samplingPlanEmail);

                    List <SamplingPlanEmail> samplingPlanEmailDirectQueryList = new List <SamplingPlanEmail>();
                    samplingPlanEmailDirectQueryList = (from c in dbTestDB.SamplingPlanEmails select c).Take(200).ToList();

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

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SamplingPlanEmail> samplingPlanEmailList = new List <SamplingPlanEmail>();
                            samplingPlanEmailList = samplingPlanEmailService.GetSamplingPlanEmailList().ToList();
                            CheckSamplingPlanEmailFields(samplingPlanEmailList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public void GetSamplingPlanEmailList_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"
                    })
                    {
                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
                        {
                            Lang = culture.TwoLetterISOLanguageName
                        }, dbTestDB, ContactID);

                        samplingPlanEmailService.Query = samplingPlanEmailService.FillQuery(typeof(SamplingPlanEmail), culture.TwoLetterISOLanguageName, 0, 10000, "", "", "SamplingPlanEmailID,GT,2|SamplingPlanEmailID,LT,5", extra);

                        List <SamplingPlanEmail> samplingPlanEmailDirectQueryList = new List <SamplingPlanEmail>();
                        samplingPlanEmailDirectQueryList = (from c in dbTestDB.SamplingPlanEmails select c).Where(c => c.SamplingPlanEmailID > 2 && c.SamplingPlanEmailID < 5).ToList();

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <SamplingPlanEmail> samplingPlanEmailList = new List <SamplingPlanEmail>();
                            samplingPlanEmailList = samplingPlanEmailService.GetSamplingPlanEmailList().ToList();
                            CheckSamplingPlanEmailFields(samplingPlanEmailList);
                            Assert.AreEqual(samplingPlanEmailDirectQueryList[0].SamplingPlanEmailID, samplingPlanEmailList[0].SamplingPlanEmailID);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
        public void SamplingPlanEmail_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(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 = samplingPlanEmailService.GetSamplingPlanEmailList().Count();

                    SamplingPlanEmail samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");

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


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // samplingPlanEmail.SamplingPlanEmailID   (Int32)
                    // -----------------------------------

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.SamplingPlanEmailID = 0;
                    samplingPlanEmailService.Update(samplingPlanEmail);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanEmailID"), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.SamplingPlanEmailID = 10000000;
                    samplingPlanEmailService.Update(samplingPlanEmail);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlanEmail", "SamplingPlanEmailID", samplingPlanEmail.SamplingPlanEmailID.ToString()), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.SamplingPlanID = 0;
                    samplingPlanEmailService.Add(samplingPlanEmail);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", samplingPlanEmail.SamplingPlanID.ToString()), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [DataType(DataType.EmailAddress)]
                    // [StringLength(150))]
                    // samplingPlanEmail.Email   (String)
                    // -----------------------------------

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("Email");
                    Assert.AreEqual(false, samplingPlanEmailService.Add(samplingPlanEmail));
                    Assert.AreEqual(1, samplingPlanEmail.ValidationResults.Count());
                    Assert.IsTrue(samplingPlanEmail.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Email")).Any());
                    Assert.AreEqual(null, samplingPlanEmail.Email);
                    Assert.AreEqual(count, samplingPlanEmailService.GetSamplingPlanEmailList().Count());

                    samplingPlanEmail       = null;
                    samplingPlanEmail       = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.Email = GetRandomString("", 151);
                    Assert.AreEqual(false, samplingPlanEmailService.Add(samplingPlanEmail));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Email", "150"), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, samplingPlanEmailService.GetSamplingPlanEmailList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // samplingPlanEmail.IsContractor   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // samplingPlanEmail.LabSheetHasValueOver500   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // samplingPlanEmail.LabSheetReceived   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // samplingPlanEmail.LabSheetAccepted   (Boolean)
                    // -----------------------------------


                    // -----------------------------------
                    // Is NOT Nullable
                    // samplingPlanEmail.LabSheetRejected   (Boolean)
                    // -----------------------------------


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

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

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

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.LastUpdateContactTVItemID = 0;
                    samplingPlanEmailService.Add(samplingPlanEmail);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", samplingPlanEmail.LastUpdateContactTVItemID.ToString()), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);

                    samplingPlanEmail = null;
                    samplingPlanEmail = GetFilledRandomSamplingPlanEmail("");
                    samplingPlanEmail.LastUpdateContactTVItemID = 1;
                    samplingPlanEmailService.Add(samplingPlanEmail);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), samplingPlanEmail.ValidationResults.FirstOrDefault().ErrorMessage);


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

                    // No testing requied

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

                    // No testing requied
                }
            }
        }
        public IHttpActionResult GetSamplingPlanEmailList([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))
            {
                SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (samplingPlanEmailService.Query.HasErrors)
                    {
                        return(Ok(new List <SamplingPlanEmail>()
                        {
                            new SamplingPlanEmail()
                            {
                                HasErrors = samplingPlanEmailService.Query.HasErrors,
                                ValidationResults = samplingPlanEmailService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(samplingPlanEmailService.GetSamplingPlanEmailList().ToList()));
                    }
                }
            }
        }
Beispiel #12
0
        public void SamplingPlanEmail_Controller_GetSamplingPlanEmailList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanEmailController samplingPlanEmailController = new SamplingPlanEmailController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanEmailController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanEmailController.DatabaseType);

                    SamplingPlanEmail samplingPlanEmailFirst = new SamplingPlanEmail();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(query, db, ContactID);
                        samplingPlanEmailFirst = (from c in db.SamplingPlanEmails select c).FirstOrDefault();
                        count = (from c in db.SamplingPlanEmails select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with SamplingPlanEmail info
                    IHttpActionResult jsonRet = samplingPlanEmailController.GetSamplingPlanEmailList();
                    Assert.IsNotNull(jsonRet);

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

                    List <SamplingPlanEmail> samplingPlanEmailList = new List <SamplingPlanEmail>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(query, db, ContactID);
                        samplingPlanEmailList = (from c in db.SamplingPlanEmails select c).OrderBy(c => c.SamplingPlanEmailID).Skip(0).Take(2).ToList();
                        count = (from c in db.SamplingPlanEmails select c).Count();
                    }

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

                        // ok with SamplingPlanEmail info
                        jsonRet = samplingPlanEmailController.GetSamplingPlanEmailList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlanEmail> >;
                        Assert.AreEqual(samplingPlanEmailList[0].SamplingPlanEmailID, ret.Content[0].SamplingPlanEmailID);
                        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 SamplingPlanEmail info
                            IHttpActionResult jsonRet2 = samplingPlanEmailController.GetSamplingPlanEmailList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <SamplingPlanEmail> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SamplingPlanEmail> >;
                            Assert.AreEqual(samplingPlanEmailList[1].SamplingPlanEmailID, ret2.Content[0].SamplingPlanEmailID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public void SamplingPlanEmail_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanEmailController samplingPlanEmailController = new SamplingPlanEmailController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanEmailController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanEmailController.DatabaseType);

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

                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(query, db, ContactID);
                        samplingPlanEmailLast = (from c in db.SamplingPlanEmails select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanEmail info
                    IHttpActionResult jsonRet = samplingPlanEmailController.GetSamplingPlanEmailWithID(samplingPlanEmailLast.SamplingPlanEmailID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanEmail> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanEmail>;
                    SamplingPlanEmail samplingPlanEmailRet            = Ret.Content;
                    Assert.AreEqual(samplingPlanEmailLast.SamplingPlanEmailID, samplingPlanEmailRet.SamplingPlanEmailID);

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

                    // Post to return CSSPError because SamplingPlanEmailID exist
                    IHttpActionResult jsonRet2 = samplingPlanEmailController.Post(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNull(samplingPlanEmailRet2);

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

                    // Post to return newly added SamplingPlanEmail
                    samplingPlanEmailRet.SamplingPlanEmailID       = 0;
                    samplingPlanEmailController.Request            = new System.Net.Http.HttpRequestMessage();
                    samplingPlanEmailController.Request.RequestUri = new System.Uri("http://localhost:5000/api/samplingPlanEmail");
                    IHttpActionResult jsonRet3 = samplingPlanEmailController.Post(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet3 = jsonRet3 as CreatedNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNotNull(samplingPlanEmailRet3);

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

                    IHttpActionResult jsonRet4 = samplingPlanEmailController.Delete(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet4 = jsonRet4 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNotNull(samplingPlanEmailRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }