Example #1
0
        public void SamplingPlan_Controller_Delete_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;
                        query.Asc      = "";
                        query.Desc     = "";

                        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);

                    // Post to return newly added SamplingPlan
                    samplingPlanRet.SamplingPlanID            = 0;
                    samplingPlanRet.SamplingPlanName          = samplingPlanRet.SamplingPlanName.Replace(".txt", "_a.txt");
                    samplingPlanController.Request            = new System.Net.Http.HttpRequestMessage();
                    samplingPlanController.Request.RequestUri = new System.Uri("http://localhost:5000/api/samplingPlan");
                    IHttpActionResult jsonRet3 = samplingPlanController.Post(samplingPlanRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SamplingPlan> samplingPlanRet3 = jsonRet3 as CreatedNegotiatedContentResult <SamplingPlan>;
                    Assert.IsNotNull(samplingPlanRet3);
                    SamplingPlan samplingPlan = samplingPlanRet3.Content;

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

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

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

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

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

                    OkNegotiatedContentResult <SamplingPlan> samplingPlanRet4 = jsonRet4 as OkNegotiatedContentResult <SamplingPlan>;
                    Assert.IsNull(samplingPlanRet4);

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