예제 #1
0
        public void InsertRecipe()
        {
            var recipe = new PrivateRecipe();

            var item1= new RecipeItem {Description = "Step 1"};
            var item2= new RecipeItem {Description = "Step 2"};
            recipe.Add(item1);
            recipe.Add(item2);

            privateRecipeRepository.Insert(recipe);
        }
 public void AddShouldAppendItemToTheEnd()
 {
     var recipe = new PrivateRecipe(_author, _title);
     var mockRecipeItem = new Mock<RecipeItem>(_itemDescription, recipe);
     recipe.Add(mockRecipeItem.Object);
     recipe.Items[recipe.Items.Count - 1].ShouldBeSameAs(mockRecipeItem.Object);
 }
        public void ConvertShouldConvertPrivateRecipeToPublicRecipe()
        {
            var privateRecipe = new PrivateRecipe(_testAuthor, _testTitle);
            privateRecipe.Add(new RecipeItem("test1", privateRecipe));
            privateRecipe.Add(new RecipeItem("test2", privateRecipe));
            privateRecipe.Add(new RecipeItem("test3", privateRecipe));

            var sut = PublicRecipe.ConvertFromPrivateRecipe(privateRecipe);

            sut.Id.ShouldEqual(0);
            sut.Author.ShouldEqual(privateRecipe.Author);
            sut.Title.ShouldEqual(privateRecipe.Title);
            sut.TimeCreated.ShouldEqual(privateRecipe.TimeCreated);
            sut.TimeLastModified.ShouldEqual(privateRecipe.TimeLastModified);
            sut.Items.Count.ShouldEqual(privateRecipe.Items.Count);
            sut.Items[1].Description.ShouldEqual(privateRecipe.Items[1].Description);
            sut.Items[1].Description.ShouldNotEqual(privateRecipe.Items[0].Description);
        }
        public void ClearShouldRemoveAllItems()
        {
            var sut = new PrivateRecipe(_author, _title);
            var recipeItem1 = new RecipeItem(_itemDescription, sut);
            var recipeItem2 = new RecipeItem(_itemDescription, sut);
            sut.Add(recipeItem1);
            sut.Add(recipeItem2);

            sut.Clear();

            sut.Items.Count.ShouldEqual(0);
        }
        public void AddShouldUpdateTimeLastModified()
        {
            var sut = new PrivateRecipe(_author, _title);
            var mockRecipeItem = new Mock<RecipeItem>(_itemDescription, sut);
            var oldTime = sut.TimeLastModified;

            Thread.Sleep(100);
            sut.Add(mockRecipeItem.Object);
            var newTime = sut.TimeLastModified;

            newTime.ShouldNotEqual(oldTime);
        }
        public void AddShouldAddNewItem()
        {
            var recipe = new PrivateRecipe(_author, _title);
            var mockRecipeItem = new Mock<RecipeItem>(_itemDescription, recipe);

            recipe.Add(mockRecipeItem.Object);

            recipe.Items.Count.ShouldEqual(1);
            recipe.Items[0].ShouldBeSameAs(mockRecipeItem.Object);
            recipe.RecipeStatus.ShouldEqual("Yet to start");
            recipe.TimeLastModified.ShouldBeInRange(DateTime.UtcNow.CreateTimeConstraintLowerBound(), DateTime.UtcNow.CreateTimeConstraintUpperBound());
        }
        public void ClearShouldUpdateLastModifiedTime()
        {
            var sut = new PrivateRecipe(_author, _title);
            var recipeItem1 = new RecipeItem(_itemDescription, sut);
            var recipeItem2 = new RecipeItem(_itemDescription, sut);
            sut.Add(recipeItem1);
            sut.Add(recipeItem2);
            var oldTime = sut.TimeLastModified;
            Thread.Sleep(100);

            sut.Clear();
            var newTime = sut.TimeLastModified;

            newTime.ShouldNotEqual(oldTime);
        }
        public void RemoveShouldRemoveItem()
        {
            var sut = new PrivateRecipe(_author, _title);
            var recipeItem1 = new RecipeItem(_itemDescription, sut);
            var recipeItem2 = new RecipeItem(_itemDescription, sut);
            sut.Add(recipeItem1);
            sut.Add(recipeItem2);

            sut.Remove(recipeItem1);

            sut.Items.Count.ShouldEqual(1);
            sut.Items[0].ShouldBeSameAs(recipeItem2);
        }
        public void InsertShouldInsertItemAtSpecifiedIndex()
        {
            var sut = new PrivateRecipe(_author, _title);
            var recipeItem1 = new RecipeItem(_itemDescription, sut);
            var recipeItem2 = new RecipeItem(_itemDescription, sut);

            sut.Add(recipeItem1);
            sut.Insert(recipeItem2, 0);

            sut.Items[0].ShouldBeSameAs(recipeItem2);
        }