コード例 #1
0
        public void SpillLanguage_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

                    SpillLanguage spillLanguageLast = new SpillLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageLast = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageLast.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageLast.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

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

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet2);

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

                    // Put to return CSSPError because SpillLanguageID of 0 does not exist
                    spillLanguageRet.SpillLanguageID = 0;
                    IHttpActionResult jsonRet3 = spillLanguageController.Put(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
コード例 #2
0
        public void SpillLanguage_Controller_GetSpillLanguageWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

                    SpillLanguage spillLanguageFirst = new SpillLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        SpillLanguageService spillLanguageService = new SpillLanguageService(new Query(), db, ContactID);
                        spillLanguageFirst = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageFirst.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageFirst.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

                    // Not Found
                    IHttpActionResult jsonRet2 = spillLanguageController.GetSpillLanguageWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
コード例 #3
0
        public void SpillLanguage_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SpillLanguageController spillLanguageController = new SpillLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(spillLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, spillLanguageController.DatabaseType);

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

                        SpillLanguageService spillLanguageService = new SpillLanguageService(query, db, ContactID);
                        spillLanguageLast = (from c in db.SpillLanguages select c).FirstOrDefault();
                    }

                    // ok with SpillLanguage info
                    IHttpActionResult jsonRet = spillLanguageController.GetSpillLanguageWithID(spillLanguageLast.SpillLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SpillLanguage> Ret = jsonRet as OkNegotiatedContentResult <SpillLanguage>;
                    SpillLanguage spillLanguageRet = Ret.Content;
                    Assert.AreEqual(spillLanguageLast.SpillLanguageID, spillLanguageRet.SpillLanguageID);

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

                    // Post to return CSSPError because SpillLanguageID exist
                    IHttpActionResult jsonRet2 = spillLanguageController.Post(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNull(spillLanguageRet2);

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

                    // Post to return newly added SpillLanguage
                    spillLanguageRet.SpillLanguageID           = 0;
                    spillLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    spillLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/spillLanguage");
                    IHttpActionResult jsonRet3 = spillLanguageController.Post(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SpillLanguage> spillLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet3);

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

                    IHttpActionResult jsonRet4 = spillLanguageController.Delete(spillLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <SpillLanguage> spillLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <SpillLanguage>;
                    Assert.IsNotNull(spillLanguageRet4);

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