Esempio n. 1
0
        public async Task PutRecipe_Returns_StatusCode()
        {
            // Arrange
            var mockRepository = new Mock <IRecipesRepository>();
            var controller     = new RecipesController(mockRepository.Object);

            // Act
            Task <IHttpActionResult> actionResult = controller.PutRecipe(_testData.RecipeData);
            var statusCode = await actionResult as StatusCodeResult;

            // Assert
            Assert.IsNotNull(statusCode);
            Assert.AreEqual(HttpStatusCode.NoContent, statusCode.StatusCode);
        }
Esempio n. 2
0
        public async Task TestPutRecipeUpdate()
        {
            using (var context = new MyRecipesContext(options))
            {
                // Given
                string name    = "putRecipe";
                Recipe recipe1 = context.Recipe.Where(x => x.Name == recipeNames[0]).Single();
                recipe1.Name = name;

                // When
                RecipesController recipeController = new RecipesController(context, configuration);
                IActionResult     result           = await recipeController.PutRecipe(recipe1.Id, recipe1) as IActionResult;

                // Then
                recipe1 = context.Recipe.Where(x => x.Name == name).Single();
            }
        }
Esempio n. 3
0
        public async Task TestPutRecipeNoContentStatusCode()
        {
            using (var context = new MyRecipesContext(options))
            {
                // Given
                string name    = "putRecipe";
                Recipe recipe1 = context.Recipe.Where(x => x.Name == recipeNames[0]).Single();
                recipe1.Name = name;

                // When
                RecipesController recipeController = new RecipesController(context, configuration);
                IActionResult     result           = await recipeController.PutRecipe(recipe1.Id, recipe1) as IActionResult;

                // Then
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
        public void PutRecipeTest()
        {
            string userId = "user1";
            var    recipe = new Recipe()
            {
                Id     = 1,
                UserId = userId
            };

            _recipesService.Setup(i => i.GetRecipe(It.IsAny <int>())).Returns(recipe);
            _recipesService.Setup(i => i.UpdateRecipe(recipe, userId)).Returns(new MyResponse(true));

            var result = _recipesController.PutRecipe(recipe);

            _recipesService.Verify(i => i.UpdateRecipe(recipe, userId), Times.Once);

            Assert.IsNotNull(result);
        }