public void CreateRecipe_Test()
        {
            mockRepo.Setup(repo => repo.Recipes.FindByCondition(c => c.Id == It.IsAny <int>())).Returns(GetRecipes());
            var controllerActionResult = recipeController.CreateRecipe(addRecipe);

            Assert.NotNull(controllerActionResult);
        }
        public async Task CreateRecipe_Returns_Ok_When_Arguments_Are_Valid()
        {
            // Arrange
            var recipesService = Substitute.For <IRecipesService>();

            recipesService
            .CreateAsync(Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <TimeSpan?>(), Arg.Any <int?>(), Arg.Any <string>(), Arg.Any <IList <Ingredient> >(), Arg.Any <IList <Step> >(), Arg.Any <IList <Tag> >())
            .Returns(Task.CompletedTask);
            var controller = new RecipesController(recipesService, AutoMapper.Mapper.Instance);
            var recipe     = new NewRecipeDTO {
                Title       = "Naleśniki",
                Description = "Naleśniki z serem",
                Image       = null,
                Duration    = TimeSpan.FromMinutes(30),
                Servings    = 12,
                Notes       = "Idealne na lekki głód",
                Ingredients = new List <NewRecipeIngredientDTO>(),
                Steps       = new List <NewRecipeStepDTO>(),
                Tags        = new List <NewRecipeTagDTO>()
            };

            // Act
            var result = await controller.CreateRecipe(recipe);

            // Assert
            Assert.True(result.GetType().IsAssignableFrom(typeof(OkResult)));
        }
Esempio n. 3
0
        public void CreateRecipe_ReturnsCorrectResourceType_WhenValidObjectSubmitted()
        {
            var controller = new RecipesController(mockRepo.Object, mapper);
            var result     = controller.CreateRecipe(new RecipeCreateDto {
            });

            Assert.IsInstanceOf <ActionResult <RecipeReadDto> >(result);
        }
Esempio n. 4
0
        public void CreateRecipe_WithValidationError_ReturnsBadRequestResult()
        {
            // Arrange
            recipesServiceMock = new Mock <IRecipesService>();
            recipesController  = new RecipesController(recipesServiceMock.Object, mapper);
            recipesController.ModelState.AddModelError("Some Key", "Some Error Message");

            // Act
            var result = recipesController.CreateRecipe(new RecipeForCreationDto());

            // Assert
            Assert.IsTrue(result.GetType() == typeof(BadRequestObjectResult));
        }
        public async Task CreateRecipe_Returns_BadRequest_When_Arguments_Are_Invalid()
        {
            // Arrange
            var recipesService = Substitute.For <IRecipesService>();

            recipesService
            .CreateAsync(Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <TimeSpan?>(), Arg.Any <int?>(), Arg.Any <string>(), Arg.Any <IList <Ingredient> >(), Arg.Any <IList <Step> >(), Arg.Any <IList <Tag> >())
            .Returns(Task.CompletedTask);
            var controller = new RecipesController(recipesService, AutoMapper.Mapper.Instance);
            var recipe     = new NewRecipeDTO();

            // Act
            var result = await controller.CreateRecipe(recipe);

            // Assert
            Assert.True(result.GetType().IsAssignableFrom(typeof(BadRequestResult)));
        }
        public void CreateRecipe_Returns201Created_WhenValidObjectSubmitted()
        {
            mockRepo.Setup(repo =>
                           repo.GetRecipeById(1)).Returns(new Recipe
            {
                Id           = 1,
                Title        = "mock",
                Ingredients  = "mock",
                Instructions = "mock",
                Description  = "mock",
                Source       = "mock",
                Rating       = 5,
                PrepTime     = "mock",
                ImageURL     = "sampleURL.com/image.jpg"
            });
            var controller = new RecipesController(mockRepo.Object, mapper);
            var result     = controller.CreateRecipe(new RecipeCreateDto {
            });

            Assert.IsType <CreatedAtRouteResult>(result.Result);
        }
Esempio n. 7
0
        public void CreateRecipe_WithTitleAndInstructions_ReturnsCreatedResult()
        {
            // Arrange
            recipesServiceMock = new Mock <IRecipesService>();
            recipesServiceMock
            .Setup(m => m.InsertRecipe(It.IsAny <RecipeDto>()))
            .Returns(1);
            recipesController = new RecipesController(recipesServiceMock.Object, mapper);

            var recipeForCreation = new RecipeForCreationDto
            {
                Title       = "Cooking is fun",
                Instruction = "You should cook the meal"
            };

            // Act
            var result = recipesController.CreateRecipe(recipeForCreation);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(CreatedAtRouteResult));
        }
Esempio n. 8
0
        public void CreateRecipe_SomethinWentWrongWhileInserting_Returns500InternalServerError()
        {
            // Arrange
            recipesServiceMock = new Mock <IRecipesService>();
            recipesServiceMock
            .Setup(m => m.InsertRecipe(It.IsAny <RecipeDto>()))
            .Returns(0);
            recipesController = new RecipesController(recipesServiceMock.Object, mapper);

            var recipeForCreation = new RecipeForCreationDto
            {
                Title       = "Cooking is fun",
                Instruction = "You should cook the meal"
            };

            // Act
            var result = recipesController.CreateRecipe(recipeForCreation);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(StatusCodeResult));
            Assert.IsTrue(((StatusCodeResult)result).StatusCode == StatusCodes.Status500InternalServerError);
        }