示例#1
0
        public VPAmbientModel PostDeleteVPAmbientDB(int VPScenarioID, int Row)
        {
            ContactOK contactOK = IsContactOK();

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

            VPAmbient vpAmbientToDelete = GetVPAmbientWithVPScenarioIDAndRowDB(VPScenarioID, Row);

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

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

                LogModel logModel = _LogService.PostAddLogForObj("VPAmbients", vpAmbientToDelete.VPAmbientID, LogCommandEnum.Delete, vpAmbientToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
示例#2
0
        // Fill
        public string FillVPAmbient(VPAmbient vpAmbient, VPAmbientModel vpAmbientModel, ContactOK contactOK)
        {
            vpAmbient.DBCommand            = (int)vpAmbientModel.DBCommand;
            vpAmbient.VPScenarioID         = vpAmbientModel.VPScenarioID;
            vpAmbient.Row                  = vpAmbientModel.Row;
            vpAmbient.MeasurementDepth_m   = vpAmbientModel.MeasurementDepth_m;
            vpAmbient.CurrentSpeed_m_s     = vpAmbientModel.CurrentSpeed_m_s;
            vpAmbient.CurrentDirection_deg = vpAmbientModel.CurrentDirection_deg;
            vpAmbient.AmbientSalinity_PSU  = vpAmbientModel.AmbientSalinity_PSU;
            vpAmbient.AmbientTemperature_C = vpAmbientModel.AmbientTemperature_C;
            vpAmbient.BackgroundConcentration_MPN_100ml = vpAmbientModel.BackgroundConcentration_MPN_100ml;
            vpAmbient.PollutantDecayRate_per_day        = vpAmbientModel.PollutantDecayRate_per_day;
            vpAmbient.FarFieldCurrentSpeed_m_s          = vpAmbientModel.FarFieldCurrentSpeed_m_s;
            vpAmbient.FarFieldCurrentDirection_deg      = vpAmbientModel.FarFieldCurrentDirection_deg;
            vpAmbient.FarFieldDiffusionCoefficient      = vpAmbientModel.FarFieldDiffusionCoefficient;
            vpAmbient.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                vpAmbient.LastUpdateContactTVItemID = 2;
            }
            else
            {
                vpAmbient.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

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

                    VPAmbient vpAmbientLast = new VPAmbient();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        VPAmbientService vpAmbientService = new VPAmbientService(query, db, ContactID);
                        vpAmbientLast = (from c in db.VPAmbients select c).FirstOrDefault();
                    }

                    // ok with VPAmbient info
                    IHttpActionResult jsonRet = vpAmbientController.GetVPAmbientWithID(vpAmbientLast.VPAmbientID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPAmbient> Ret = jsonRet as OkNegotiatedContentResult <VPAmbient>;
                    VPAmbient vpAmbientRet = Ret.Content;
                    Assert.AreEqual(vpAmbientLast.VPAmbientID, vpAmbientRet.VPAmbientID);

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

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

                    OkNegotiatedContentResult <VPAmbient> vpAmbientRet2 = jsonRet2 as OkNegotiatedContentResult <VPAmbient>;
                    Assert.IsNotNull(vpAmbientRet2);

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

                    // Put to return CSSPError because VPAmbientID of 0 does not exist
                    vpAmbientRet.VPAmbientID = 0;
                    IHttpActionResult jsonRet3 = vpAmbientController.Put(vpAmbientRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <VPAmbient> vpAmbientRet3 = jsonRet3 as OkNegotiatedContentResult <VPAmbient>;
                    Assert.IsNull(vpAmbientRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
示例#4
0
        public VPAmbient GetVPAmbientWithVPScenarioIDAndRowDB(int VPScenarioID, int Row)
        {
            VPAmbient vpAmbient = (from c in db.VPAmbients
                                   where c.VPScenarioID == VPScenarioID &&
                                   c.Row == Row
                                   select c).FirstOrDefault <VPAmbient>();

            return(vpAmbient);
        }
示例#5
0
        // Post
        public VPAmbientModel PostAddVPAmbientDB(VPAmbientModel vpAmbientModel)
        {
            string retStr = VPAmbientModelOK(vpAmbientModel);

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

            ContactOK contactOK = IsContactOK();

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

            VPAmbient vpAmbientExist = GetVPAmbientWithVPScenarioIDAndRowDB(vpAmbientModel.VPScenarioID, vpAmbientModel.Row);

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

            VPAmbient vpAmbientNew = new VPAmbient();

            retStr = FillVPAmbient(vpAmbientNew, vpAmbientModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("VPAmbients", vpAmbientNew.VPAmbientID, LogCommandEnum.Add, vpAmbientNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetVPAmbientModelWithVPScenarioIDAndRowDB(vpAmbientNew.VPScenarioID, vpAmbientNew.Row));
        }
示例#6
0
        public IHttpActionResult GetVPAmbientWithID([FromUri] int VPAmbientID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                VPAmbientService vpAmbientService = new VPAmbientService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                vpAmbientService.Query = vpAmbientService.FillQuery(typeof(VPAmbient), lang, 0, 1, "", "", extra);

                if (vpAmbientService.Query.Extra == "A")
                {
                    VPAmbientExtraA vpAmbientExtraA = new VPAmbientExtraA();
                    vpAmbientExtraA = vpAmbientService.GetVPAmbientExtraAWithVPAmbientID(VPAmbientID);

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

                    return(Ok(vpAmbientExtraA));
                }
                else if (vpAmbientService.Query.Extra == "B")
                {
                    VPAmbientExtraB vpAmbientExtraB = new VPAmbientExtraB();
                    vpAmbientExtraB = vpAmbientService.GetVPAmbientExtraBWithVPAmbientID(VPAmbientID);

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

                    return(Ok(vpAmbientExtraB));
                }
                else
                {
                    VPAmbient vpAmbient = new VPAmbient();
                    vpAmbient = vpAmbientService.GetVPAmbientWithVPAmbientID(VPAmbientID);

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

                    return(Ok(vpAmbient));
                }
            }
        }
示例#7
0
        public VPAmbientModel PostUpdateVPAmbientDB(VPAmbientModel vpAmbientModel)
        {
            string retStr = VPAmbientModelOK(vpAmbientModel);

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

            ContactOK contactOK = IsContactOK();

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

            VPAmbient vpAmbientToUpdate = GetVPAmbientWithVPScenarioIDAndRowDB(vpAmbientModel.VPScenarioID, vpAmbientModel.Row);

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

            retStr = FillVPAmbient(vpAmbientToUpdate, vpAmbientModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

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

                LogModel logModel = _LogService.PostAddLogForObj("VPAmbients", vpAmbientToUpdate.VPAmbientID, LogCommandEnum.Change, vpAmbientToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetVPAmbientModelWithVPScenarioIDAndRowDB(vpAmbientToUpdate.VPScenarioID, vpAmbientToUpdate.Row));
        }
        private bool TryToSave(VPAmbient vpAmbient)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                vpAmbient.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

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

            db.VPAmbients.Update(vpAmbient);

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

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

                    VPAmbient vpAmbientFirst = new VPAmbient();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        VPAmbientService vpAmbientService = new VPAmbientService(new Query(), db, ContactID);
                        vpAmbientFirst = (from c in db.VPAmbients select c).FirstOrDefault();
                    }

                    // ok with VPAmbient info
                    IHttpActionResult jsonRet = vpAmbientController.GetVPAmbientWithID(vpAmbientFirst.VPAmbientID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPAmbient> Ret = jsonRet as OkNegotiatedContentResult <VPAmbient>;
                    VPAmbient vpAmbientRet = Ret.Content;
                    Assert.AreEqual(vpAmbientFirst.VPAmbientID, vpAmbientRet.VPAmbientID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = vpAmbientController.GetVPAmbientWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPAmbient> vpAmbientRet2 = jsonRet2 as OkNegotiatedContentResult <VPAmbient>;
                    Assert.IsNull(vpAmbientRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
示例#11
0
        public IHttpActionResult Delete([FromBody] VPAmbient vpAmbient, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                VPAmbientService vpAmbientService = new VPAmbientService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!vpAmbientService.Delete(vpAmbient))
                {
                    return(BadRequest(String.Join("|||", vpAmbient.ValidationResults)));
                }
                else
                {
                    vpAmbient.ValidationResults = null;
                    return(Ok(vpAmbient));
                }
            }
        }
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string    retStr    = "";
            Enums     enums     = new Enums(LanguageRequest);
            VPAmbient vpAmbient = validationContext.ObjectInstance as VPAmbient;

            vpAmbient.HasErrors = false;

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

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

            VPScenario VPScenarioVPScenarioID = (from c in db.VPScenarios where c.VPScenarioID == vpAmbient.VPScenarioID select c).FirstOrDefault();

            if (VPScenarioVPScenarioID == null)
            {
                vpAmbient.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "VPScenario", "VPScenarioID", vpAmbient.VPScenarioID.ToString()), new[] { "VPScenarioID" }));
            }

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

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

            if (vpAmbient.CurrentSpeed_m_s != null)
            {
                if (vpAmbient.CurrentSpeed_m_s < 0 || vpAmbient.CurrentSpeed_m_s > 10)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CurrentSpeed_m_s", "0", "10"), new[] { "CurrentSpeed_m_s" }));
                }
            }

            if (vpAmbient.CurrentDirection_deg != null)
            {
                if (vpAmbient.CurrentDirection_deg < -180 || vpAmbient.CurrentDirection_deg > 180)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "CurrentDirection_deg", "-180", "180"), new[] { "CurrentDirection_deg" }));
                }
            }

            if (vpAmbient.AmbientSalinity_PSU != null)
            {
                if (vpAmbient.AmbientSalinity_PSU < 0 || vpAmbient.AmbientSalinity_PSU > 40)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "AmbientSalinity_PSU", "0", "40"), new[] { "AmbientSalinity_PSU" }));
                }
            }

            if (vpAmbient.AmbientTemperature_C != null)
            {
                if (vpAmbient.AmbientTemperature_C < -10 || vpAmbient.AmbientTemperature_C > 40)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "AmbientTemperature_C", "-10", "40"), new[] { "AmbientTemperature_C" }));
                }
            }

            if (vpAmbient.BackgroundConcentration_MPN_100ml != null)
            {
                if (vpAmbient.BackgroundConcentration_MPN_100ml < 0 || vpAmbient.BackgroundConcentration_MPN_100ml > 10000000)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "BackgroundConcentration_MPN_100ml", "0", "10000000"), new[] { "BackgroundConcentration_MPN_100ml" }));
                }
            }

            if (vpAmbient.PollutantDecayRate_per_day != null)
            {
                if (vpAmbient.PollutantDecayRate_per_day < 0 || vpAmbient.PollutantDecayRate_per_day > 100)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "PollutantDecayRate_per_day", "0", "100"), new[] { "PollutantDecayRate_per_day" }));
                }
            }

            if (vpAmbient.FarFieldCurrentSpeed_m_s != null)
            {
                if (vpAmbient.FarFieldCurrentSpeed_m_s < 0 || vpAmbient.FarFieldCurrentSpeed_m_s > 10)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldCurrentSpeed_m_s", "0", "10"), new[] { "FarFieldCurrentSpeed_m_s" }));
                }
            }

            if (vpAmbient.FarFieldCurrentDirection_deg != null)
            {
                if (vpAmbient.FarFieldCurrentDirection_deg < -180 || vpAmbient.FarFieldCurrentDirection_deg > 180)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldCurrentDirection_deg", "-180", "180"), new[] { "FarFieldCurrentDirection_deg" }));
                }
            }

            if (vpAmbient.FarFieldDiffusionCoefficient != null)
            {
                if (vpAmbient.FarFieldDiffusionCoefficient < 0 || vpAmbient.FarFieldDiffusionCoefficient > 1)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "FarFieldDiffusionCoefficient", "0", "1"), new[] { "FarFieldDiffusionCoefficient" }));
                }
            }

            if (vpAmbient.LastUpdateDate_UTC.Year == 1)
            {
                vpAmbient.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (vpAmbient.LastUpdateDate_UTC.Year < 1980)
                {
                    vpAmbient.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == vpAmbient.LastUpdateContactTVItemID select c).FirstOrDefault();

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

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                vpAmbient.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
        public void VPAmbient_Controller_GetVPAmbientList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPAmbientController vpAmbientController = new VPAmbientController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpAmbientController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpAmbientController.DatabaseType);

                    VPAmbient vpAmbientFirst = new VPAmbient();
                    int       count          = -1;
                    Query     query          = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        VPAmbientService vpAmbientService = new VPAmbientService(query, db, ContactID);
                        vpAmbientFirst = (from c in db.VPAmbients select c).FirstOrDefault();
                        count          = (from c in db.VPAmbients select c).Count();
                        count          = (query.Take > count ? count : query.Take);
                    }

                    // ok with VPAmbient info
                    IHttpActionResult jsonRet = vpAmbientController.GetVPAmbientList();
                    Assert.IsNotNull(jsonRet);

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

                    List <VPAmbient> vpAmbientList = new List <VPAmbient>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        VPAmbientService vpAmbientService = new VPAmbientService(query, db, ContactID);
                        vpAmbientList = (from c in db.VPAmbients select c).OrderBy(c => c.VPAmbientID).Skip(0).Take(2).ToList();
                        count         = (from c in db.VPAmbients select c).Count();
                    }

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

                        // ok with VPAmbient info
                        jsonRet = vpAmbientController.GetVPAmbientList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <VPAmbient> >;
                        Assert.AreEqual(vpAmbientList[0].VPAmbientID, ret.Content[0].VPAmbientID);
                        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 VPAmbient info
                            IHttpActionResult jsonRet2 = vpAmbientController.GetVPAmbientList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <VPAmbient> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <VPAmbient> >;
                            Assert.AreEqual(vpAmbientList[1].VPAmbientID, ret2.Content[0].VPAmbientID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
        public void VPAmbient_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    VPAmbientController vpAmbientController = new VPAmbientController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(vpAmbientController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, vpAmbientController.DatabaseType);

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

                        VPAmbientService vpAmbientService = new VPAmbientService(query, db, ContactID);
                        vpAmbientLast = (from c in db.VPAmbients select c).FirstOrDefault();
                    }

                    // ok with VPAmbient info
                    IHttpActionResult jsonRet = vpAmbientController.GetVPAmbientWithID(vpAmbientLast.VPAmbientID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <VPAmbient> Ret = jsonRet as OkNegotiatedContentResult <VPAmbient>;
                    VPAmbient vpAmbientRet = Ret.Content;
                    Assert.AreEqual(vpAmbientLast.VPAmbientID, vpAmbientRet.VPAmbientID);

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

                    // Post to return CSSPError because VPAmbientID exist
                    IHttpActionResult jsonRet2 = vpAmbientController.Post(vpAmbientRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <VPAmbient> vpAmbientRet2 = jsonRet2 as OkNegotiatedContentResult <VPAmbient>;
                    Assert.IsNull(vpAmbientRet2);

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

                    // Post to return newly added VPAmbient
                    vpAmbientRet.VPAmbientID               = 0;
                    vpAmbientController.Request            = new System.Net.Http.HttpRequestMessage();
                    vpAmbientController.Request.RequestUri = new System.Uri("http://localhost:5000/api/vpAmbient");
                    IHttpActionResult jsonRet3 = vpAmbientController.Post(vpAmbientRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <VPAmbient> vpAmbientRet3 = jsonRet3 as CreatedNegotiatedContentResult <VPAmbient>;
                    Assert.IsNotNull(vpAmbientRet3);

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

                    IHttpActionResult jsonRet4 = vpAmbientController.Delete(vpAmbientRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <VPAmbient> vpAmbientRet4 = jsonRet4 as OkNegotiatedContentResult <VPAmbient>;
                    Assert.IsNotNull(vpAmbientRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
示例#15
0
 public VPAmbientTest()
 {
     vPAmbient       = new VPAmbient();
     vPAmbientExtraA = new VPAmbientExtraA();
     vPAmbientExtraB = new VPAmbientExtraB();
 }