public async void UpdateRecipeProductChanges_AtInitializedDbTable_UpdatedRecipeProductChangesEqualExpectedRecipeProductChanges() { // arrange var recipeProductChanges = GetRecipeProductChanges(); fixture.db.Add(recipeProductChanges); await fixture.db.SaveChangesAsync(); var expected = new RecipeProductChanges { ProductId = recipeProductChanges.ProductId, RecipeId = recipeProductChanges.RecipeId, Quantity = (decimal)78.9012, Type = ProductCatalogTypes.Product }; // act await logic.UpdateDataModelAsync(expected); // assert var actual = await fixture.db.RecipeProductChanges.FirstOrDefaultAsync(i => i.ProductId == recipeProductChanges.ProductId && i.RecipeId == recipeProductChanges.RecipeId); Assert.Equal(expected.ProductId, actual.ProductId); Assert.Equal(expected.RecipeId, actual.RecipeId); Assert.Equal(expected.Quantity, actual.Quantity); Assert.Equal(expected.Type, actual.Type); }
/// <summary> /// Update product recipe relation. /// </summary> /// <param name="model">Updated product recipe relation information</param> public async Task UpdateDataModelAsync(RecipeProductChanges model) { var currentModel = await db.RecipeProductChanges.FirstOrDefaultAsync(i => i.RecipeId == model.RecipeId && i.ProductId == model.ProductId); db.Entry(currentModel).CurrentValues.SetValues(model); await db.SaveChangesAsync(); }
/// <summary> /// Delete product recipe relation. /// </summary> /// <param name="model">Model of recipe product relation containing key information (ProductId and RecipeId) to find recipe product changes</param> public async Task RemoveDataModelAsync(RecipeProductChanges model) { var entity = await db.RecipeProductChanges.SingleAsync(i => i.RecipeId == model.RecipeId && i.ProductId == model.ProductId && i.Type == model.Type); db.RecipeProductChanges.Remove(entity); await db.SaveChangesAsync(); }
/// <summary> /// Add new product recipe relation. /// </summary> /// <param name="model">Product recipe relation to be added</param> /// <returns>Added product recipe relation with correct key(ProductId, RecipeId) value</returns> public async Task <RecipeProductChanges> AddDataModelAsync(RecipeProductChanges model) { var entity = db.Add(model); await db.SaveChangesAsync(); return(entity.Entity); }