public void PutRecipe_success() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.UpdateRecipe(recipe)).Returns(true); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Put(recipe); var okObjectResult = result as AcceptedResult; //Assert Assert.NotNull(result); Assert.Equal(202, okObjectResult?.StatusCode); }
public void Put_Updates_An_Recipe() { var originalRecipe = new Recipe(1, "First Title", "First calorie", "first instruction"); var expectedRecipe = new List <Recipe>() { originalRecipe }; var updatedRecipe = new Recipe(1, "Updated Title", "Updated calorie", "Updated instruction"); recipeRepo.When(t => recipeRepo.Update(updatedRecipe)) .Do(Callback.First(t => expectedRecipe.Remove(originalRecipe)) .Then(t => expectedRecipe.Add(updatedRecipe))); recipeRepo.GetAll().Returns(expectedRecipe); var result = underTest.Put(updatedRecipe); Assert.All(result, item => Assert.Contains("Updated Recipe", item.Title)); }
public void Put_Null_Should_ReturnsBadRequest() { // Arrange DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { ICustomMapper _customMapper = new CustomMapper(context); IDataRepository <Recipe> mockRepository = new RecipeManager(context); RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager); //Act var badRequest = recipecontroller.Put(1, null); // Assert Assert.IsType <Microsoft.AspNetCore.Mvc.BadRequestObjectResult>(badRequest); } }
public void Put_Invalid_ID_Should_ReturnsNotFoundResult() { // Arrange DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build(); using (var context = new RepositoryContext(options)) { ICustomMapper _customMapper = new CustomMapper(context); IDataRepository <Recipe> mockRepository = new RecipeManager(context); RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager); //Act var forEdit = new MockDBHandler().buildMockRecipeView(); forEdit.ID = 1; // Because In mock it is something else and in equalation assert result to false var notFoundResult = recipecontroller.Put(68, forEdit); // Assert Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult); } }