Beispiel #1
0
        public void SamplingPlan_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanController samplingPlanController = new SamplingPlanController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanController.DatabaseType);

                    SamplingPlan samplingPlanLast = new SamplingPlan();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        SamplingPlanService samplingPlanService = new SamplingPlanService(query, db, ContactID);
                        samplingPlanLast = (from c in db.SamplingPlans select c).FirstOrDefault();
                    }

                    // ok with SamplingPlan info
                    IHttpActionResult jsonRet = samplingPlanController.GetSamplingPlanWithID(samplingPlanLast.SamplingPlanID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlan> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlan>;
                    SamplingPlan samplingPlanRet = Ret.Content;
                    Assert.AreEqual(samplingPlanLast.SamplingPlanID, samplingPlanRet.SamplingPlanID);

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

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

                    OkNegotiatedContentResult <SamplingPlan> samplingPlanRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlan>;
                    Assert.IsNotNull(samplingPlanRet2);

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

                    // Put to return CSSPError because SamplingPlanID of 0 does not exist
                    samplingPlanRet.SamplingPlanID = 0;
                    IHttpActionResult jsonRet3 = samplingPlanController.Put(samplingPlanRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <SamplingPlan> samplingPlanRet3 = jsonRet3 as OkNegotiatedContentResult <SamplingPlan>;
                    Assert.IsNull(samplingPlanRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }