public async void GetListRecipeProductsDataModel_FromInitializedDbTables_LogicRecipeProductsDataModelsEqualExpectedRecipeProductsDataModels() { var recipeProductsChanges = GetRecipeProductsChanges(); var productsCatalog = GetProductsCatalog(); fixture.db.ProductCatalog.AddRange(productsCatalog); fixture.db.RecipeProductChanges.AddRange(recipeProductsChanges); await fixture.db.SaveChangesAsync(); var expected = new List <RecipeProductsDataModel> { new RecipeProductsDataModel { RecipeId = 44440, ProductId = 44440, Type = ProductCatalogTypes.Product, Quantity = 15, ProductName = "Testesteron", Cas = 4040404, LicenseRequired = false }, new RecipeProductsDataModel { RecipeId = 44440, ProductId = 44441, Type = ProductCatalogTypes.Material, Quantity = 9, ProductName = "Testin", Cas = 4040414, LicenseRequired = true }, new RecipeProductsDataModel { RecipeId = 44440, ProductId = 44442, Type = ProductCatalogTypes.Material, Quantity = 10, ProductName = "Testonion", Cas = 4041404, LicenseRequired = null } }; // act var actual = (await logic.GetAllDataModelAsync(expected.First().RecipeId)).ToList(); // assert foreach (var expectedItem in expected) { Assert.Contains(actual, actualItem => expectedItem.RecipeId == actualItem.RecipeId && expectedItem.ProductId == actualItem.ProductId && expectedItem.Type == actualItem.Type && expectedItem.Quantity == actualItem.Quantity && expectedItem.ProductName == actualItem.ProductName && expectedItem.Cas == actualItem.Cas && expectedItem.LicenseRequired == actualItem.LicenseRequired); } }
public async Task <IActionResult> Index(string key, int currentPage = 1, int itemsOnPage = 20) { int recipeId = Int32.Parse(key); var addedProducts = await logic.GetAllDataModelAsync(recipeId); // collect products already used in recipe var ignoreProducts = addedProducts.Select(i => i.ProductId).Distinct(); // and collect all other products from catalog, which can be added var notAddedProducts = logic.GetProductsFromCatalog(ignoreProducts); // id of recipe in which these products used ViewData["RecipeId"] = recipeId; // form pagenation model, with added collection of unsed products from catalog var model = new CollectionPlusPagenation <RecipeProductsDataModel, ProductCatalog> { Collection = addedProducts, Pagenation = new Pagenation <ProductCatalog>(notAddedProducts, itemsOnPage, currentPage) }; return(View(model)); }