using System; using System.Collections.Generic; using System.Linq; using System.Text; using Chefbook.DataObjects; using NUnit.Framework; using Rhino.Mocks; using Chefbook.UserActions; using Chefbook.ViewModels; namespace UnitTests.UserActionsTests { [TestFixture] internal class SaveRecipeActionFixture { private MockRepository mocks; private IUserAction action; private CategoryViewModel category; private RecipeViewModel tempRecipe, realRecipe; private IngredientViewModel ingredient; [SetUp] public void Init() { mocks = new MockRepository(); category = new CategoryViewModel(new Category(null)) { Name = "root" }; realRecipe = new RecipeViewModel(new Recipe(category.CategoryModel)) { Name = "OldName", Description = "oldDesc", Directions = "oldDir", CookTimeMinutes=5, CookTimeHours=0, PrepTimeHours=0, PrepTimeMinutes=65 }; tempRecipe = new RecipeViewModel(new Recipe(category.CategoryModel)) { Name = "MyRecipe" }; tempRecipe.Description = "My Old Description"; tempRecipe.CookTimeMinutes = 35; ingredient = new IngredientViewModel(new Ingredient(tempRecipe.RecipeModel)); ingredient.Name = "Teh Beef"; Assert.AreEqual("My Old Description", tempRecipe.Description); Assert.AreEqual(35, tempRecipe.CookTimeMinutes); Assert.Contains(ingredient, tempRecipe.Ingredients); Assert.AreEqual("Teh Beef", ingredient.Name); Assert.AreEqual(1, tempRecipe.Ingredients.Count); Assert.Contains(category, tempRecipe.Categories); Assert.Contains(tempRecipe, category.Recipes); action = new SaveRecipeAction(realRecipe,tempRecipe) ; } [Test] public void DoActionTest() { action.DoAction(); Assert.Contains(category, realRecipe.Categories); Assert.Contains(realRecipe, category.Recipes); Assert.True(realRecipe.ValueEquals(tempRecipe)); } [Test] public void UndoActionTest() { action.DoAction(); action.UndoAction(); Assert.AreEqual("OldName", realRecipe.Name); Assert.AreEqual("oldDesc", realRecipe.Description); Assert.AreEqual("oldDir", realRecipe.Directions); Assert.AreEqual(TimeSpan.FromMinutes(5), realRecipe.RecipeModel.CookTime); Assert.AreEqual(TimeSpan.FromMinutes(65), realRecipe.RecipeModel.PrepTime); Assert.Contains(category, realRecipe.Categories); Assert.Contains(realRecipe, category.Recipes); } [Test] public void UndoActionWithoutDoingTest() { UserActionTestsHelper.UndoActionWithoutDoingTest(action); } [Test] public void UndoActionTwiceAfterDoingTest() { UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action); } [Test] public void DoActionTwiceTest() { UserActionTestsHelper.DoActionTwiceTest(action); } [Test] public void ActionNameTest() { Assert.AreEqual(string.Format("Save Recipe '{0}'", tempRecipe), action.ToString()); } } }