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(); }
public async void CreateMainCategoryAsyncShouldCreateMainCategory() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "CreateMainCategoryAsyncShouldCreateMainCategory") .Options; var context = new TechAndToolsDbContext(options); IMainCategoryService mainCategoryService = new MainCategoryService(context); await mainCategoryService.CreateAsync(new MainCategoryServiceModel { Name = "PC" }); await mainCategoryService.CreateAsync(new MainCategoryServiceModel { Name = "Tools" }); MainCategory first = context.MainCategories.First(); MainCategory second = context.MainCategories.Last(); Assert.Equal(2, context.MainCategories.Count()); Assert.Equal("PC", first.Name); Assert.Equal("Tools", second.Name); Assert.NotNull(first); Assert.NotNull(first.Categories); Assert.NotNull(second); Assert.NotNull(second.Categories); }
public HttpResponseMessage GetAllMainCategoriesAdmin(bool test = false) { try { List <categoryDTO> list = MainCategoryService.GetAllMainCategories(); return(Request.CreateResponse(HttpStatusCode.OK, list)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e)); } }
public ManageCategoryController ( MainCategoryService _mainCategoryService, SubCategoryService _subCategoryService, TrackService _trackService, Services.CourseService _courseService ) { mainCategoryService = _mainCategoryService; subCategoryService = _subCategoryService; trackService = _trackService; courseService = _courseService; }
public DashBoardController( MainCategoryService _mainCategoryService, UserService _userService, TrackService _trackService, UserTrackService _userTrackService, AdminService _adminService, ConfigurationService _configService ) { mainCategoryService = _mainCategoryService; userService = _userService; trackService = _trackService; userTrackService = _userTrackService; adminService = _adminService; ConfigService = _configService; }
public async void DeleteAsyncShouldDeleteMainCategoryFromDatabaseById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "DeleteAsyncShouldDeleteMainCategoryFromDatabaseById") .Options; var context = new TechAndToolsDbContext(options); await SeedData(context); IMainCategoryService mainCategoryService = new MainCategoryService(context); MainCategory mainCategoryFromDb = context.MainCategories.First(); bool result = await mainCategoryService.DeleteAsync(mainCategoryFromDb.Id); Assert.True(result); Assert.Equal(1, context.MainCategories.Count()); }
public async void GetAllMainCategoriesAsyncShouldReturnAllMainCategories() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "GetAllMainCategoriesAsyncShouldReturnAllMainCategories") .Options; var context = new TechAndToolsDbContext(options); await SeedData(context); IMainCategoryService mainCategoryService = new MainCategoryService(context); IEnumerable <MainCategoryServiceModel> mainCategories = mainCategoryService.GetAllMainCategories(); Assert.NotNull(mainCategories); Assert.Equal(2, mainCategories.Count()); Assert.Equal("PC", mainCategories.First().Name); Assert.Equal("Tools", mainCategories.Last().Name); }
public HomeController ( MainCategoryService _mainCategoryService, SubCategoryService _subCategoryService, TrackService _trackService, CourseService _courseService, UserTrackService _userTrackService, UserService _userService ) { mainCategoryService = _mainCategoryService; subCategoryService = _subCategoryService; trackService = _trackService; courseService = _courseService; userTrackService = _userTrackService; userService = _userService; Hub = GlobalHost.ConnectionManager.GetHubContext <WhatsLearnHub>(); }
public async void GetMainCategoryByIdShouldReturnServiceModelFromDatabaseById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "GetMainCategoryByIdShouldReturnServiceModelFromDatabaseById") .Options; var context = new TechAndToolsDbContext(options); await SeedData(context); IMainCategoryService mainCategoryService = new MainCategoryService(context); MainCategory expectedData = context.MainCategories.First(); MainCategoryServiceModel actualData = mainCategoryService.GetMainCategoryById(expectedData.Id); ; Assert.Equal(expectedData.Name, actualData.Name); Assert.Equal(expectedData.Id, actualData.Id); Assert.NotNull(actualData.Categories); Assert.Equal(expectedData.Categories.Count, actualData.Categories.Count); }
public async void EditAsyncShouldEditMainCategoryFromDatabaseById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "EditAsyncShouldEditMainCategoryFromDatabaseById") .Options; var context = new TechAndToolsDbContext(options); await SeedData(context); IMainCategoryService mainCategoryService = new MainCategoryService(context); MainCategory mainCategoryFromDb = context.MainCategories.First(); mainCategoryFromDb.Name = "New Name"; MainCategoryServiceModel expectedResult = mainCategoryFromDb.To <MainCategoryServiceModel>(); await mainCategoryService.EditAsync(expectedResult); var actualResult = context.MainCategories.First(); Assert.Equal(expectedResult.Name, actualResult.Name); }
public MainCategoryController(MainCategoryService _mainCategoryService) { mainCategoryService = _mainCategoryService; Hub = GlobalHost.ConnectionManager.GetHubContext <WhatsLearnHub>(); }