public async void CanDeleteRecipe() { DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanDeleteRecipe").Options; using (CookBookDbContext context = new CookBookDbContext(options)) { //Arrange Recipes recipe = new Recipes(); recipe.ID = 1; recipe.Name = "Sketti n Ketchup"; Recipes recipe2 = new Recipes(); recipe2.ID = 2; recipe2.Name = "Bread n Water"; //Act RecipesController recipesController = new RecipesController(context, configuration); await recipesController.Post(recipe); await recipesController.Post(recipe2); await recipesController.Delete(recipe.ID); var result = context.Recipes.FirstOrDefault(c => c.ID == recipe.ID); //Assert Assert.Null(result); } }
public async void CanGetCollectionOfRecipes() { DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGetCollectionOfRecipes").Options; using (CookBookDbContext context = new CookBookDbContext(options)) { //Arrange Recipes recipe = new Recipes(); recipe.ID = 1; recipe.Name = "Sketti n Ketchup"; Recipes recipe2 = new Recipes(); recipe2.ID = 2; recipe2.Name = "Bread n Water"; Recipes recipe3 = new Recipes(); recipe3.ID = 3; recipe3.Name = "Knuckle Sandwich"; //Act RecipesController recipesController = new RecipesController(context, configuration); await recipesController.Post(recipe); await recipesController.Post(recipe2); await recipesController.Post(recipe3); var data = recipesController.Get().ToList(); //Assert Assert.Equal(3, data.Count); } }
public async void CanGetOneRecipeNotFound() { DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGettRecipeOk").Options; using (CookBookDbContext context = new CookBookDbContext(options)) { //Arrange Recipes recipe = new Recipes(); recipe.ID = 1; recipe.Name = "Sketti n Ketchup"; Recipes recipe2 = new Recipes(); recipe2.ID = 2; recipe2.Name = "Bread n Water"; Recipes recipe3 = new Recipes(); recipe3.ID = 3; recipe3.Name = "Knuckle Sandwich"; //Act RecipesController recipesController = new RecipesController(context, configuration); await recipesController.Post(recipe); await recipesController.Post(recipe2); var data = recipesController.Get(6); //Assert Assert.IsType <NotFoundResult>(data); } }
public void Post_ModelStateIsNotValid_ShouldReturnBadRequest() { _controller.ModelState.AddModelError("test", "test"); var result = _controller.Post(_recipe); Assert.That(result, Is.TypeOf <BadRequestObjectResult>()); }
public void TestPostRecipe() { var repository = new Mock <IRepository <Recipe> >(); var recipe = new Recipe() { recipeId = 1, userId = 1, categoryId = 2, calories = 500, preparation = "zazaaza" }; repository.Setup(x => x.Add(recipe)).Returns(true).Verifiable(); var controller = new RecipesController(repository.Object); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Post(recipe); Recipe s; Assert.IsTrue(response.TryGetContentValue <Recipe>(out s)); Assert.AreEqual(recipe, s); Assert.AreNotEqual(10, s.recipeId); }