Пример #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 async Task AddSubCategory_WithNonExistingMainCategory_ShouldReturnFalse()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var subCategoryService = new SubCategoryService(context);

            string categoryId = "fakeCategoryId";

            SubCategoryBindingModel model = new SubCategoryBindingModel
            {
                CategoryId = categoryId,
                Name       = "NewSubCategory",
            };

            var methodResult = await subCategoryService.AddSubCategory(model);

            Assert.False(methodResult, "The method did not return false upon wrong data input for creation.");
        }
Пример #3
0
        public async Task AddSubCategory_WithCorrectData_ShouldCreateSubCategorySuccessfully()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var subCategoryService = new SubCategoryService(context);

            // Seed only one main category
            var categoryId = await this.SeedCategory(context);

            SubCategoryBindingModel model = new SubCategoryBindingModel
            {
                CategoryId = categoryId,
                Name       = "NewSubCategory",
            };

            var methodResult = await subCategoryService.AddSubCategory(model);

            Assert.True(methodResult, "The method returned false on correct input for creation.");

            var subCategoryFromDatabase = await context.SubCategories.FirstOrDefaultAsync(c => c.Name == model.Name);

            AssertExtensions.NotNullWithMessage(subCategoryFromDatabase, "The subCategory was not found in the database.");
        }
Пример #4
0
 // Thêm
 public bool AddSubCategory(SubCategoryDTO pSubCategoryDTO)
 {
     return(service.AddSubCategory(pSubCategoryDTO));
 }