public async void TestCreate_InvalidFavoriteCategory_ShouldFail() { // Arrange FavoriteCategoriesController controller = new FavoriteCategoriesController(_context); InitializeFavoriteCategory(); favoriteCategory.UserId = 99; favoriteCategory.GameCategoryId = 99; try { // Act var result = await controller.Create(favoriteCategory); // Assert Assert.IsType <ViewResult>(result); ViewResult viewResult = (ViewResult)result; Assert.NotNull(viewResult.ViewData.ModelState); Assert.NotEmpty(viewResult.ViewData.ModelState.Keys); foreach (string item in viewResult.ViewData.ModelState.Keys) { Assert.Equal("", item); } } catch (Exception ex) { Assert.Equal("Microsoft.EntityFrameworkCore.DbUpdateException", ex.GetType().ToString()); } }
public async void TestEdit_InvalidFavoriteCategory_ShouldFail(string value) { // Arrange FavoriteCategoriesController controller = new FavoriteCategoriesController(_context); int userId = int.Parse(value); // Act FavoriteCategory replayCategory = await _context.FavoriteCategory .FirstOrDefaultAsync(a => a.UserId == userId); replayCategory.GameCategoryId = 0; try { var result = await controller.Edit(replayCategory.UserId, replayCategory); // Assert Assert.IsType <ViewResult>(result); ViewResult viewResult = (ViewResult)result; Assert.NotNull(viewResult.ViewData.ModelState); Assert.NotEmpty(viewResult.ViewData.ModelState.Keys); foreach (string item in viewResult.ViewData.ModelState.Keys) { Assert.Equal("", item); } } catch (Exception ex) { Assert.Equal("System.InvalidOperationException", ex.GetType().ToString()); } }
public async void TestDelete_InvalidFavoriteCategory_ShouldFail(string value) { // Arrange FavoriteCategoriesController controller = new FavoriteCategoriesController(_context); int userId = int.Parse(value.Substring(0, value.IndexOf(","))); int categoryId = int.Parse(value.Substring(value.IndexOf(",") + 1, value.Length - value.IndexOf(",") - 1)); try { // Act var result = await controller.DeleteConfirmed(userId, categoryId); } // Assert catch (Exception ex) { Assert.Equal("System.ArgumentNullException", ex.GetType().ToString()); } }