コード例 #1
0
        public void UpdateSubCategoryOfMainCategoryDescriptionSuccess()
        {
            var config     = new HttpConfiguration();
            var request    = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/user/44300");
            var route      = config.Routes.MapHttpRoute("Default", "api/{controller}/UpdateDescription/");
            var controller = new CategoryController
            {
                Request = request,
            };

            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            MainCategoryService.AddMainCategory("unit test", "unit test");
            SubCategoryService.AddSubCategory("unit test", "unit_test");
            SwapDbConnection db        = new SwapDbConnection();
            main_category    test_main = db.main_category.Where(x => x.name == "unit test").FirstOrDefault();
            sub_category     test_sub  = db.sub_category.Where(x => x.name == "unit test").FirstOrDefault();

            CategoryService.AddMainAndSubRelationship(test_main.main_id, test_sub.sub_id, "unit test", "unit test");
            Assert.AreEqual(controller.UpdateSubCategoryOfMainCategoryDescription(new MainAndSubRelationshipDTO()
            {
                main_id = test_main.main_id, sub_id = test_sub.sub_id, descrition = "test"
            }).StatusCode, HttpStatusCode.OK);
            delete_main_category.DeleteMainCategorySuccess();
            delete_sub_category.DeleteSubCategorySuccess();
        }
コード例 #2
0
 public HttpResponseMessage AddMainAndSubRelationship([FromBody] MainAndSubRelationshipDTO req)
 {
     try
     {
         MainAndSubRelationshipDTO object_add;
         if (req.main_id == null || req.sub_name == null || req.google_value == null || req.descrition == null)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Illegal parameters"));
         }
         object_add = CategoryService.AddMainAndSubRelationship(req.main_id, req.sub_name, req.google_value, req.descrition);
         return(Request.CreateResponse(HttpStatusCode.OK, object_add));
     }
     //handle of errors in exceptions
     catch (Exception error)
     {
         if (typeof(InvalidOperationException) == error.GetType())
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, error.Message));
         }
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + error));
     }
 }