public async Task ThrowException_WhenCategoryAlreadyExists() { var categoryName = "category"; CategoryTestUtils.GetContextWithCategory(nameof(ThrowException_WhenCategoryAlreadyExists), categoryName); using (var assertContext = new AlphaHotelDbContext(CategoryTestUtils.GetOptions(nameof(ThrowException_WhenCategoryAlreadyExists)))) { var categoryService = new CategoryService(assertContext); await Assert.ThrowsExceptionAsync <ArgumentException>( async() => await categoryService.AddCategory(categoryName)); } }
public async Task AddCategory_Return_WhenAllParametersArePassed() { var categoryName = "category"; //CategoryTestUtils.GetContextWithCategory(nameof(AddCategory_Return_WhenCategoryAllParametersArePassed), categoryName); using (var assertContext = new AlphaHotelDbContext(CategoryTestUtils.GetOptions(nameof(AddCategory_Return_WhenAllParametersArePassed)))) { var categoryService = new CategoryService(assertContext); await categoryService.AddCategory(categoryName); var category = await assertContext.Categories.FirstOrDefaultAsync(c => c.Name == categoryName); Assert.AreEqual(categoryName, category.Name); } }
public async Task ReturnAllCategories() { var categoryId = 1; CategoryTestUtils.ResetAutoMapper(); CategoryTestUtils.InitializeAutoMapper(); CategoryTestUtils.GetContextWithCategories(nameof(ReturnAllCategories), categoryId); using (var assertContext = new AlphaHotelDbContext(CategoryTestUtils.GetOptions(nameof(ReturnAllCategories)))) { var categoryService = new CategoryService(assertContext); var categories = await categoryService.ListAllCategoriesAsync(); Assert.AreEqual(1, categories.Count); } }