Esempio n. 1
0
        public async Task Create_Bad_Recipe()
        {
            var controller = new RecipesController(_service.Object);

            controller.ModelState.AddModelError(string.Empty, string.Empty);

            var result = await controller.Create(_recipe);

            Assert.IsType <BadRequestObjectResult>(result);
        }
        public void Create_ShouldReturn201_WhenSucceeded()
        {
            var recipeRequest = TestDataRepository.BuildCreateNewRecipeRequest();

            var result = _recipesController.Create(recipeRequest);

            var res = result.Result as CreatedAtActionResult;

            Assert.IsNotNull(res);

            var value = (CreateNewRecipeResponse)res.Value;

            Assert.IsNotNull(value);

            Assert.AreEqual(value.Recipe.Name, recipeRequest.Name);
            Assert.AreEqual(value.Recipe.Instructions, recipeRequest.Instructions);
            Assert.AreEqual(value.Recipe.Ingredients, recipeRequest.Ingredients);
            Assert.AreEqual(value.Recipe.URL, recipeRequest.URL);
            Assert.AreEqual(value.Recipe.Author, _user);
        }
Esempio n. 3
0
        public async Task Create()
        {
            var controller = new RecipesController(_service.Object);

            var result = await controller.Create(_recipe);

            var okObjectResult = Assert.IsType <OkObjectResult>(result);
            var model          = Assert.IsAssignableFrom <Recipe>(okObjectResult.Value);

            Assert.Equal(_recipe.Id, model.Id);
        }
Esempio n. 4
0
        public async Task PostCreateProductController()
        {
            //Getting Everything To Make This Unit Test Work
            FormCollection      form               = GetFormCollection();
            IFormFile           formFile           = GetFormFile();
            IHostingEnvironment hostingEnvironment = GetHostingEnvironment();
            DatabaseContext     context            = GetInMemoryDbMetData();

            var controller = new RecipesController(context, hostingEnvironment);

            var result = await controller.Create(recipes[0], formFile, form);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
Esempio n. 5
0
        public void Create()
        {
            var mock = new Mock <IDbContext>();

            mock.Setup(x => x.Set <Recipe>()).Returns(new FakeDbSet <Recipe>());

            var obj    = mock.Object;
            var newObj = new Recipe
            {
                RecipeId    = 1,
                Name        = "Zupa pomidorowa",
                Description = "asfagaghahahadh",
                Difficulty  = DifficultyEnum.easy,
                PublishDate = DateTime.Now
            };

            var controller = new RecipesController(mock.Object);
            var result     = controller.Create(newObj);

            Assert.IsNotNull(obj.Set <Recipe>().FirstOrDefault(p => p.RecipeId == newObj.RecipeId));
        }