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 Put([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.Update(samplingPlanEmail))
                {
                    return(BadRequest(String.Join("|||", samplingPlanEmail.ValidationResults)));
                }
                else
                {
                    samplingPlanEmail.ValidationResults = null;
                    return(Ok(samplingPlanEmail));
                }
            }
        }
        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
                }
            }
        }