Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
        /// <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();
        }
Esempio n. 4
0
        /// <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);
        }