public void Post_Creates_New_Recipes() { var newRecipe = new Recipe(1, "New title", "New calorie", "New instructions"); var recipeList = new List <Recipe>(); recipeRepo.When(t => t.Create(newRecipe)) .Do(t => recipeList.Add(newRecipe)); recipeRepo.GetAll().Returns(recipeList); var result = underTest.Post(newRecipe); Assert.Contains(newRecipe, result); }
public void PostRecipe_Success() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.CreateRecipe(recipe)).Returns(true); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Post(recipe); var okObjectResult = result as AcceptedResult; //Assert Assert.NotNull(result); Assert.Equal(202, okObjectResult?.StatusCode); }
public void PostRecipe_Failed() { //Arrange Recipe recipe = new Recipe(); _recipeService.Setup(c => c.CreateRecipe(recipe)).Returns(false); RecipeController recipeController = new RecipeController(_recipeService.Object); //Act var result = recipeController.Post(recipe); var okObjectResult = result as BadRequestResult; //Assert Assert.NotNull(result); Assert.Equal(400, okObjectResult?.StatusCode); }
public void Add_ValidObject_Then_Get_Should_bring_Something() { // 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); FilterModel fm = new FilterModel(); //Act recipecontroller.Post(new MockDBHandler().buildMockRecipeView()); var okResult = recipecontroller.Get(fm); // Assert var retObj = Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResult); Assert.Equal(2, retObj.Value.Items.ToList().Count); } }
public void Add_ValidObjectPassed_ReturnedResponseHasCreatedItem() { // 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); AuthenticateController aut = new AuthenticateController(_usermanager); RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager); // Act IActionResult actionResult = recipecontroller.Post(new MockDBHandler().buildMockRecipeView()); var createdResult = actionResult as CreatedAtRouteResult; // Assert Assert.NotNull(createdResult); Assert.Equal("N", ((RecipeViewModel)createdResult.Value).Name); Assert.Equal(2, ((RecipeViewModel)createdResult.Value).Ingredients.Count); } }