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);
        }
Ejemplo n.º 2
0
 public IHttpActionResult GetMikeSourceStartEndList([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))
     {
         MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(new Query()
         {
             Lang = lang
         }, db, ContactID);
Ejemplo n.º 3
0
        public void MikeSourceStartEnd_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeSourceStartEndController mikeSourceStartEndController = new MikeSourceStartEndController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeSourceStartEndController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeSourceStartEndController.DatabaseType);

                    MikeSourceStartEnd mikeSourceStartEndLast = new MikeSourceStartEnd();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(query, db, ContactID);
                        mikeSourceStartEndLast = (from c in db.MikeSourceStartEnds select c).FirstOrDefault();
                    }

                    // ok with MikeSourceStartEnd info
                    IHttpActionResult jsonRet = mikeSourceStartEndController.GetMikeSourceStartEndWithID(mikeSourceStartEndLast.MikeSourceStartEndID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeSourceStartEnd> Ret = jsonRet as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    MikeSourceStartEnd mikeSourceStartEndRet           = Ret.Content;
                    Assert.AreEqual(mikeSourceStartEndLast.MikeSourceStartEndID, mikeSourceStartEndRet.MikeSourceStartEndID);

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

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

                    OkNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet2 = jsonRet2 as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNotNull(mikeSourceStartEndRet2);

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

                    // Put to return CSSPError because MikeSourceStartEndID of 0 does not exist
                    mikeSourceStartEndRet.MikeSourceStartEndID = 0;
                    IHttpActionResult jsonRet3 = mikeSourceStartEndController.Put(mikeSourceStartEndRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet3 = jsonRet3 as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNull(mikeSourceStartEndRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult GetMikeSourceStartEndWithID([FromUri] int MikeSourceStartEndID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                mikeSourceStartEndService.Query = mikeSourceStartEndService.FillQuery(typeof(MikeSourceStartEnd), lang, 0, 1, "", "", extra);

                if (mikeSourceStartEndService.Query.Extra == "A")
                {
                    MikeSourceStartEndExtraA mikeSourceStartEndExtraA = new MikeSourceStartEndExtraA();
                    mikeSourceStartEndExtraA = mikeSourceStartEndService.GetMikeSourceStartEndExtraAWithMikeSourceStartEndID(MikeSourceStartEndID);

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

                    return(Ok(mikeSourceStartEndExtraA));
                }
                else if (mikeSourceStartEndService.Query.Extra == "B")
                {
                    MikeSourceStartEndExtraB mikeSourceStartEndExtraB = new MikeSourceStartEndExtraB();
                    mikeSourceStartEndExtraB = mikeSourceStartEndService.GetMikeSourceStartEndExtraBWithMikeSourceStartEndID(MikeSourceStartEndID);

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

                    return(Ok(mikeSourceStartEndExtraB));
                }
                else
                {
                    MikeSourceStartEnd mikeSourceStartEnd = new MikeSourceStartEnd();
                    mikeSourceStartEnd = mikeSourceStartEndService.GetMikeSourceStartEndWithMikeSourceStartEndID(MikeSourceStartEndID);

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

                    return(Ok(mikeSourceStartEnd));
                }
            }
        }
Ejemplo n.º 5
0
        public void MikeSourceStartEnd_Controller_GetMikeSourceStartEndWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeSourceStartEndController mikeSourceStartEndController = new MikeSourceStartEndController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeSourceStartEndController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeSourceStartEndController.DatabaseType);

                    MikeSourceStartEnd mikeSourceStartEndFirst = new MikeSourceStartEnd();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(new Query(), db, ContactID);
                        mikeSourceStartEndFirst = (from c in db.MikeSourceStartEnds select c).FirstOrDefault();
                    }

                    // ok with MikeSourceStartEnd info
                    IHttpActionResult jsonRet = mikeSourceStartEndController.GetMikeSourceStartEndWithID(mikeSourceStartEndFirst.MikeSourceStartEndID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeSourceStartEnd> Ret = jsonRet as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    MikeSourceStartEnd mikeSourceStartEndRet           = Ret.Content;
                    Assert.AreEqual(mikeSourceStartEndFirst.MikeSourceStartEndID, mikeSourceStartEndRet.MikeSourceStartEndID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = mikeSourceStartEndController.GetMikeSourceStartEndWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet2 = jsonRet2 as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNull(mikeSourceStartEndRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
Ejemplo n.º 6
0
        public IHttpActionResult Delete([FromBody] MikeSourceStartEnd mikeSourceStartEnd, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!mikeSourceStartEndService.Delete(mikeSourceStartEnd))
                {
                    return(BadRequest(String.Join("|||", mikeSourceStartEnd.ValidationResults)));
                }
                else
                {
                    mikeSourceStartEnd.ValidationResults = null;
                    return(Ok(mikeSourceStartEnd));
                }
            }
        }
Ejemplo n.º 7
0
        public void MikeSourceStartEnd_Controller_GetMikeSourceStartEndList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeSourceStartEndController mikeSourceStartEndController = new MikeSourceStartEndController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeSourceStartEndController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeSourceStartEndController.DatabaseType);

                    MikeSourceStartEnd mikeSourceStartEndFirst = new MikeSourceStartEnd();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(query, db, ContactID);
                        mikeSourceStartEndFirst = (from c in db.MikeSourceStartEnds select c).FirstOrDefault();
                        count = (from c in db.MikeSourceStartEnds select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MikeSourceStartEnd info
                    IHttpActionResult jsonRet = mikeSourceStartEndController.GetMikeSourceStartEndList();
                    Assert.IsNotNull(jsonRet);

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

                    List <MikeSourceStartEnd> mikeSourceStartEndList = new List <MikeSourceStartEnd>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(query, db, ContactID);
                        mikeSourceStartEndList = (from c in db.MikeSourceStartEnds select c).OrderBy(c => c.MikeSourceStartEndID).Skip(0).Take(2).ToList();
                        count = (from c in db.MikeSourceStartEnds select c).Count();
                    }

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

                        // ok with MikeSourceStartEnd info
                        jsonRet = mikeSourceStartEndController.GetMikeSourceStartEndList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MikeSourceStartEnd> >;
                        Assert.AreEqual(mikeSourceStartEndList[0].MikeSourceStartEndID, ret.Content[0].MikeSourceStartEndID);
                        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 MikeSourceStartEnd info
                            IHttpActionResult jsonRet2 = mikeSourceStartEndController.GetMikeSourceStartEndList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MikeSourceStartEnd> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MikeSourceStartEnd> >;
                            Assert.AreEqual(mikeSourceStartEndList[1].MikeSourceStartEndID, ret2.Content[0].MikeSourceStartEndID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void MikeSourceStartEnd_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MikeSourceStartEndController mikeSourceStartEndController = new MikeSourceStartEndController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mikeSourceStartEndController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mikeSourceStartEndController.DatabaseType);

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

                        MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(query, db, ContactID);
                        mikeSourceStartEndLast = (from c in db.MikeSourceStartEnds select c).FirstOrDefault();
                    }

                    // ok with MikeSourceStartEnd info
                    IHttpActionResult jsonRet = mikeSourceStartEndController.GetMikeSourceStartEndWithID(mikeSourceStartEndLast.MikeSourceStartEndID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MikeSourceStartEnd> Ret = jsonRet as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    MikeSourceStartEnd mikeSourceStartEndRet           = Ret.Content;
                    Assert.AreEqual(mikeSourceStartEndLast.MikeSourceStartEndID, mikeSourceStartEndRet.MikeSourceStartEndID);

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

                    // Post to return CSSPError because MikeSourceStartEndID exist
                    IHttpActionResult jsonRet2 = mikeSourceStartEndController.Post(mikeSourceStartEndRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet2 = jsonRet2 as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNull(mikeSourceStartEndRet2);

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

                    // Post to return newly added MikeSourceStartEnd
                    mikeSourceStartEndRet.MikeSourceStartEndID      = 0;
                    mikeSourceStartEndController.Request            = new System.Net.Http.HttpRequestMessage();
                    mikeSourceStartEndController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mikeSourceStartEnd");
                    IHttpActionResult jsonRet3 = mikeSourceStartEndController.Post(mikeSourceStartEndRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet3 = jsonRet3 as CreatedNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNotNull(mikeSourceStartEndRet3);

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

                    IHttpActionResult jsonRet4 = mikeSourceStartEndController.Delete(mikeSourceStartEndRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MikeSourceStartEnd> mikeSourceStartEndRet4 = jsonRet4 as OkNegotiatedContentResult <MikeSourceStartEnd>;
                    Assert.IsNotNull(mikeSourceStartEndRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Ejemplo n.º 9
0
        public IHttpActionResult GetMikeSourceStartEndList([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))
            {
                MikeSourceStartEndService mikeSourceStartEndService = new MikeSourceStartEndService(new Query()
                {
                    Lang = lang
                }, db, ContactID);

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

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

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

                    if (mikeSourceStartEndService.Query.HasErrors)
                    {
                        return(Ok(new List <MikeSourceStartEnd>()
                        {
                            new MikeSourceStartEnd()
                            {
                                HasErrors = mikeSourceStartEndService.Query.HasErrors,
                                ValidationResults = mikeSourceStartEndService.Query.ValidationResults,
                            },
                        }.ToList()));
                    }
                    else
                    {
                        return(Ok(mikeSourceStartEndService.GetMikeSourceStartEndList().ToList()));
                    }
                }
            }
        }