private void SetupTest(ContactModel contactModelToDo, CultureInfo culture, string actionStr)
        {
            LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

            if (contactModelToDo == null)
            {
                user = null;
            }
            else
            {
                user = new GenericPrincipal(new GenericIdentity(contactModelToDo.LoginEmail, "Forms"), null);
            }
            routeData = new RouteData();
            routeData.Values.Add("culture", culture);
            routeData.Values.Add("controller", "MikeScenario");
            routeData.Values.Add("action", actionStr);

            stubHttpContext            = new StubHttpContextBase();
            stubHttpRequestBase        = new StubHttpRequestBase();
            stubHttpContext.RequestGet = () => stubHttpRequestBase;
            requestContext             = new RequestContext(stubHttpContext, routeData);
            controller     = new MikeScenarioController();
            controller.Url = new UrlHelper(requestContext);
            controller.ControllerContext = new ControllerContext(stubHttpContext, routeData, controller);
            stubHttpContext.UserGet      = () => user;
            randomService  = new RandomService(languageEnum, user);
            mapInfoService = new MapInfoService(languageEnum, user);
            tvItemService  = new TVItemService(languageEnum, user);
            mikeBoundaryConditionService = new MikeBoundaryConditionService(languageEnum, user);
            appTaskService            = new AppTaskService(languageEnum, user);
            mikeScenarioService       = new MikeScenarioService(languageEnum, user);
            tvFileService             = new TVFileService(languageEnum, user);
            mikeSourceService         = new MikeSourceService(languageEnum, user);
            mikeSourceStartEndService = new MikeSourceStartEndService(languageEnum, user);

            controller.SetRequestContext(requestContext);

            // Assert
            Assert.IsNotNull(controller);
            Assert.AreEqual(2, controller.CultureListAllowable.Count);
            Assert.AreEqual("en-CA", controller.CultureListAllowable[0]);
            Assert.AreEqual("fr-CA", controller.CultureListAllowable[1]);
            Assert.IsNotNull(controller._ContactService);
            Assert.IsNotNull(controller._RequestContext);
            Assert.IsNotNull(controller._MikeScenarioService);
            Assert.IsNotNull(culture.Name, controller._RequestContext.RouteData.Values["culture"].ToString());
            Assert.IsNotNull("MikeScenario", controller._RequestContext.RouteData.Values["controller"].ToString());
            Assert.IsNotNull(actionStr, controller._RequestContext.RouteData.Values["action"].ToString());
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.LanguageRequest);
            Assert.AreEqual((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), controller.ViewBag.Language);
            Assert.AreEqual(culture.Name, controller.CultureRequest);
            Assert.AreEqual(culture.Name, controller.ViewBag.Culture);
            if (contactModelToDo != null)
            {
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.IsAdmin);
                Assert.AreEqual(contactModelToDo.IsAdmin, controller.ViewBag.IsAdmin);
            }
            Assert.AreEqual(true, controller.Debug);
            Assert.AreEqual(true, controller.ViewBag.Debug);
        }
Example #2
0
        public void MikeBoundaryCondition_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeBoundaryConditionController mikeBoundaryConditionController = new MikeBoundaryConditionController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeBoundaryConditionController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeBoundaryConditionController.DatabaseType);

                    MikeBoundaryCondition mikeBoundaryConditionLast = new MikeBoundaryCondition();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(query, db, ContactID);
                        mikeBoundaryConditionLast = (from c in db.MikeBoundaryConditions select c).FirstOrDefault();
                    }

                    // ok with MikeBoundaryCondition info
                    IHttpActionResult jsonRet = mikeBoundaryConditionController.GetMikeBoundaryConditionWithID(mikeBoundaryConditionLast.MikeBoundaryConditionID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeBoundaryCondition> Ret = jsonRet as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    MikeBoundaryCondition mikeBoundaryConditionRet        = Ret.Content;
                    Assert.AreEqual(mikeBoundaryConditionLast.MikeBoundaryConditionID, mikeBoundaryConditionRet.MikeBoundaryConditionID);

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

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

                    OkNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet2 = jsonRet2 as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNotNull(mikeBoundaryConditionRet2);

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

                    // Put to return CSSPError because MikeBoundaryConditionID of 0 does not exist
                    mikeBoundaryConditionRet.MikeBoundaryConditionID = 0;
                    IHttpActionResult jsonRet3 = mikeBoundaryConditionController.Put(mikeBoundaryConditionRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet3 = jsonRet3 as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNull(mikeBoundaryConditionRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Example #3
0
 public IHttpActionResult GetMikeBoundaryConditionList([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))
     {
         MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Example #4
0
        public IHttpActionResult GetMikeBoundaryConditionWithID([FromUri] int MikeBoundaryConditionID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mikeBoundaryConditionService.Query = mikeBoundaryConditionService.FillQuery(typeof(MikeBoundaryCondition), lang, 0, 1, "", "", extra);

                if (mikeBoundaryConditionService.Query.Extra == "A")
                {
                    MikeBoundaryConditionExtraA mikeBoundaryConditionExtraA = new MikeBoundaryConditionExtraA();
                    mikeBoundaryConditionExtraA = mikeBoundaryConditionService.GetMikeBoundaryConditionExtraAWithMikeBoundaryConditionID(MikeBoundaryConditionID);

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

                    return(Ok(mikeBoundaryConditionExtraA));
                }
                else if (mikeBoundaryConditionService.Query.Extra == "B")
                {
                    MikeBoundaryConditionExtraB mikeBoundaryConditionExtraB = new MikeBoundaryConditionExtraB();
                    mikeBoundaryConditionExtraB = mikeBoundaryConditionService.GetMikeBoundaryConditionExtraBWithMikeBoundaryConditionID(MikeBoundaryConditionID);

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

                    return(Ok(mikeBoundaryConditionExtraB));
                }
                else
                {
                    MikeBoundaryCondition mikeBoundaryCondition = new MikeBoundaryCondition();
                    mikeBoundaryCondition = mikeBoundaryConditionService.GetMikeBoundaryConditionWithMikeBoundaryConditionID(MikeBoundaryConditionID);

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

                    return(Ok(mikeBoundaryCondition));
                }
            }
        }
Example #5
0
        public void MikeBoundaryCondition_Controller_GetMikeBoundaryConditionWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeBoundaryConditionController mikeBoundaryConditionController = new MikeBoundaryConditionController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeBoundaryConditionController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeBoundaryConditionController.DatabaseType);

                    MikeBoundaryCondition mikeBoundaryConditionFirst = new MikeBoundaryCondition();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(new Query(), db, ContactID);
                        mikeBoundaryConditionFirst = (from c in db.MikeBoundaryConditions select c).FirstOrDefault();
                    }

                    // ok with MikeBoundaryCondition info
                    IHttpActionResult jsonRet = mikeBoundaryConditionController.GetMikeBoundaryConditionWithID(mikeBoundaryConditionFirst.MikeBoundaryConditionID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeBoundaryCondition> Ret = jsonRet as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    MikeBoundaryCondition mikeBoundaryConditionRet        = Ret.Content;
                    Assert.AreEqual(mikeBoundaryConditionFirst.MikeBoundaryConditionID, mikeBoundaryConditionRet.MikeBoundaryConditionID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mikeBoundaryConditionController.GetMikeBoundaryConditionWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet2 = jsonRet2 as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNull(mikeBoundaryConditionRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Example #6
0
        public IHttpActionResult Delete([FromBody] MikeBoundaryCondition mikeBoundaryCondition, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!mikeBoundaryConditionService.Delete(mikeBoundaryCondition))
                {
                    return(BadRequest(String.Join("|||", mikeBoundaryCondition.ValidationResults)));
                }
                else
                {
                    mikeBoundaryCondition.ValidationResults = null;
                    return(Ok(mikeBoundaryCondition));
                }
            }
        }
Example #7
0
        public void MikeBoundaryCondition_Controller_GetMikeBoundaryConditionList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeBoundaryConditionController mikeBoundaryConditionController = new MikeBoundaryConditionController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeBoundaryConditionController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeBoundaryConditionController.DatabaseType);

                    MikeBoundaryCondition mikeBoundaryConditionFirst = new MikeBoundaryCondition();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(query, db, ContactID);
                        mikeBoundaryConditionFirst = (from c in db.MikeBoundaryConditions select c).FirstOrDefault();
                        count = (from c in db.MikeBoundaryConditions select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MikeBoundaryCondition info
                    IHttpActionResult jsonRet = mikeBoundaryConditionController.GetMikeBoundaryConditionList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MikeBoundaryCondition> mikeBoundaryConditionList = new List <MikeBoundaryCondition>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(query, db, ContactID);
                        mikeBoundaryConditionList = (from c in db.MikeBoundaryConditions select c).OrderBy(c => c.MikeBoundaryConditionID).Skip(0).Take(2).ToList();
                        count = (from c in db.MikeBoundaryConditions select c).Count();
                    }

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

                        // ok with MikeBoundaryCondition info
                        jsonRet = mikeBoundaryConditionController.GetMikeBoundaryConditionList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MikeBoundaryCondition> >;
                        Assert.AreEqual(mikeBoundaryConditionList[0].MikeBoundaryConditionID, ret.Content[0].MikeBoundaryConditionID);
                        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 MikeBoundaryCondition info
                            IHttpActionResult jsonRet2 = mikeBoundaryConditionController.GetMikeBoundaryConditionList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MikeBoundaryCondition> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MikeBoundaryCondition> >;
                            Assert.AreEqual(mikeBoundaryConditionList[1].MikeBoundaryConditionID, ret2.Content[0].MikeBoundaryConditionID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Example #8
0
        public void MikeBoundaryCondition_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeBoundaryConditionController mikeBoundaryConditionController = new MikeBoundaryConditionController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeBoundaryConditionController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeBoundaryConditionController.DatabaseType);

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

                        MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(query, db, ContactID);
                        mikeBoundaryConditionLast = (from c in db.MikeBoundaryConditions select c).FirstOrDefault();
                    }

                    // ok with MikeBoundaryCondition info
                    IHttpActionResult jsonRet = mikeBoundaryConditionController.GetMikeBoundaryConditionWithID(mikeBoundaryConditionLast.MikeBoundaryConditionID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeBoundaryCondition> Ret = jsonRet as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    MikeBoundaryCondition mikeBoundaryConditionRet        = Ret.Content;
                    Assert.AreEqual(mikeBoundaryConditionLast.MikeBoundaryConditionID, mikeBoundaryConditionRet.MikeBoundaryConditionID);

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

                    // Post to return CSSPError because MikeBoundaryConditionID exist
                    IHttpActionResult jsonRet2 = mikeBoundaryConditionController.Post(mikeBoundaryConditionRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet2 = jsonRet2 as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNull(mikeBoundaryConditionRet2);

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

                    // Post to return newly added MikeBoundaryCondition
                    mikeBoundaryConditionRet.MikeBoundaryConditionID   = 0;
                    mikeBoundaryConditionController.Request            = new System.Net.Http.HttpRequestMessage();
                    mikeBoundaryConditionController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mikeBoundaryCondition");
                    IHttpActionResult jsonRet3 = mikeBoundaryConditionController.Post(mikeBoundaryConditionRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet3 = jsonRet3 as CreatedNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNotNull(mikeBoundaryConditionRet3);

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

                    IHttpActionResult jsonRet4 = mikeBoundaryConditionController.Delete(mikeBoundaryConditionRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MikeBoundaryCondition> mikeBoundaryConditionRet4 = jsonRet4 as OkNegotiatedContentResult <MikeBoundaryCondition>;
                    Assert.IsNotNull(mikeBoundaryConditionRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Example #9
0
        public IHttpActionResult GetMikeBoundaryConditionList([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))
            {
                MikeBoundaryConditionService mikeBoundaryConditionService = new MikeBoundaryConditionService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (mikeBoundaryConditionService.Query.HasErrors)
                    {
                        return(Ok(new List <MikeBoundaryCondition>()
                        {
                            new MikeBoundaryCondition()
                            {
                                HasErrors = mikeBoundaryConditionService.Query.HasErrors,
                                ValidationResults = mikeBoundaryConditionService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mikeBoundaryConditionService.GetMikeBoundaryConditionList().ToList()));
                    }
                }
            }
        }