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 Insert(PrivateRecipe t) { using (var ctx = new RecipeTraderModelContext()) { ctx.PrivateRecipes.Add(t); ctx.SaveChanges(); } }
public string CreateNewPrivateRecipe(string recipeTitle) { if (_privateRecipeRepo.GetUserRecipes(UserId).Exists(r => String.Equals(r.Title, recipeTitle, StringComparison.CurrentCultureIgnoreCase))) { return $"{recipeTitle} already exists. Choose another title"; } var recipe = new PrivateRecipe(UserId, recipeTitle); _privateRecipeRepo.Insert(recipe); return String.Empty; }
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 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 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 static PublicRecipe ConvertFromPrivateRecipe(PrivateRecipe privateRecipe) { if (privateRecipe == null) return null; var pubRecipe = new PublicRecipe(); pubRecipe.Title = privateRecipe.Title; pubRecipe.Author = privateRecipe.Author; pubRecipe.TimeCreated = privateRecipe.TimeCreated; pubRecipe.TimeLastModified = privateRecipe.TimeLastModified; pubRecipe.Items = privateRecipe.Items.ConvertAll(item => item.DeepCopy(false, pubRecipe)); return pubRecipe; }
public string Publish(PrivateRecipe privateRecipe, decimal price) { if (privateRecipe == null) return "The recipe does not exist"; price = price <= 0 ? 1 : price; //Check if user already sold this recipe var existingRecipe = _publicRecipeRepo.GetByUserIdAndTitle(privateRecipe.Author, privateRecipe.Title); if (existingRecipe != null) return "This recipe has been published already."; var pubR = PublicRecipe.ConvertFromPrivateRecipe(privateRecipe); pubR.Price = price; pubR.TimePublished = DateTime.UtcNow; _publicRecipeRepo.Insert(pubR); return string.Empty; }
public void Insert(PrivateRecipe t) { var random = new Random(); if (t.Id == default(int)) t.Id = random.Next(1, int.MaxValue); if (t.Items != null && t.Items.Count > 0) { foreach (var recipeItem in t.Items) { if (recipeItem.Id == default(int)) { recipeItem.Id = random.Next(1, int.MaxValue); } } } _currentPrivateRecipeState.Add(t); }
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 Update(PrivateRecipe t) { throw new NotImplementedException(); }
public void Update(PrivateRecipe t) { var existing = _currentPrivateRecipeState.SingleOrDefault(a => a.Id == t.Id); if (existing != null) { _currentPrivateRecipeState.Remove(existing); //_currentPrivateRecipeState.Add(t); Insert(t); } }
public void ConstructorShouldCreatePrivateRecipeWithCorrectInformation() { var recipe = new PrivateRecipe(_author, _title); recipe.IsPurchased.ShouldBeFalse(); recipe.RecipeStatus.Should().Equal("Recipe is empty"); recipe.TimeCreated.ShouldBeInRange(DateTime.UtcNow.CreateTimeConstraintLowerBound(), DateTime.UtcNow.CreateTimeConstraintUpperBound()); recipe.TimeLastModified.ShouldEqual(recipe.TimeCreated); recipe.Author.ShouldEqual(_author); recipe.Title.ShouldEqual(_title); recipe.Items.ShouldNotBeNull(); recipe.Items.ShouldBeEmpty(); }
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); }
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 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); }