Exemple #1
0
        public void EditRecipe()
        {
            Recipe expectedRecipe = new Recipe
            {
                Id         = 3,
                UserId     = "2",
                Text       = "Edited text",
                CreateDate = recipe3.CreateDate,
                ImageUrl   = "Some url3",
                Name       = "Recipe3",
                Tags       = "first, second, third3"
            };

            ViewResult result = controller.Edit(new RecipeAddModel
            {
                Id               = 3,
                UserId           = "2",
                Text             = "Edited text",
                Name             = "Recipe3",
                IngridietsString = "first, second, third",
                ImageFile        = null
            }) as ViewResult;

            var updated = db.FindRecipe(3);

            Assert.AreEqual(expectedRecipe.Text, updated.Text);
        }
        public void BeforeAll()
        {
            // Set up dependencies for controller
            this._recipeFromProvider = Builder<Recipe>.CreateNew().Build();
            var recipeProvider = MockRepository.GenerateStub<IRepository<Recipe,string>>();
            recipeProvider.Stub(p => p.Get(this._recipeFromProvider.RecipeId)).Return(this._recipeFromProvider);

            this._categoriesFromProvider = Builder<Category>.CreateListOfSize(20).Build();
            var categoryProvider = MockRepository.GenerateStub<IRepository<Category,string>>();
            categoryProvider.Stub(p => p.Get()).Return(this._categoriesFromProvider);

            var controller = new RecipeController(recipeProvider,
                                                  categoryProvider,
                                                  new AutoMapperMapper<Recipe, RecipeViewModel>(),
                                                  new AutoMapperMapper<RecipeViewModel, Recipe>(),
                                                  new AutoMapperMapper<Category, CategoryViewModel>(),
                                                  MockRepository.GenerateStub<IImageProvider>(),
                                                  MockRepository.GenerateStub<IFileProvider>(),
                                                  MockRepository.GenerateStub<IFeatureUsageNotifier>()
                );

            this._viewResult = controller.Edit(this._recipeFromProvider.RecipeId);
            this._viewModel = this._viewResult.Model as SelectedRecipeViewModel;
        }