public async Task <IActionResult> SingleItem(string key) { int id = Int32.Parse(key); var statusMessage = await logicValidation.CheckGetSingleDataModelAsync(id); if (statusMessage.IsCompleted) { var model = await logic.GetSingleDataModelAsync(id); return(View(model)); } else { return(View("CustomError", statusMessage)); } }
public async void GetRecipeModel_FromInitializedDbTables_LogicRecipeModelEqualExpectedRecipeModel() { // arrange var recipe = GetRecipes(); var recipeInheritance = GetRecipeInheritances(); var productsCatalog = GetProductsCatalog(); var recipeProductsChanges = GetRecipeProductsChanges(); var facilities = GetFacilities(); var techProcesses = GetTechProcesses(); fixture.db.Recipe.AddRange(recipe); fixture.db.RecipeInheritance.AddRange(recipeInheritance); fixture.db.ProductCatalog.AddRange(productsCatalog); fixture.db.RecipeProductChanges.AddRange(recipeProductsChanges); fixture.db.Facility.AddRange(facilities); fixture.db.TechProcess.AddRange(techProcesses); await fixture.db.SaveChangesAsync(); var expected = new RecipeModel { Id = 44440, Content = "I am recipe #1", GovApproved = true, TechApproved = true, ParentRecipe = null, ChildRecipes = new List <int> { 44441 }, RecipeProducts = new List <RecipeProductContainer> { new RecipeProductContainer { ProductId = 44440, ProductName = "Testesteron", CAS = 4040404, Quantity = 10, Type = ProductCatalogTypes.Product }, new RecipeProductContainer { ProductId = 44441, ProductName = "Testin", CAS = 4040414, Quantity = (decimal)12.3456, Type = ProductCatalogTypes.Material }, new RecipeProductContainer { ProductId = 44442, ProductName = "Testonion", CAS = 4041404, Quantity = (decimal)12.3456, Type = ProductCatalogTypes.Material }, }, RelatedFacilities = new List <Facility> { new Facility { Name = "Facility #1", Id = 44440 }, new Facility { Name = "Facility #2", Id = 44441 } } }; // act var actual = await logic.GetSingleDataModelAsync(expected.Id); // assert Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Content, actual.Content); Assert.Equal(expected.GovApproved, actual.GovApproved); Assert.Equal(expected.TechApproved, actual.TechApproved); Assert.Equal(expected.ParentRecipe, actual.ParentRecipe); Assert.Equal(expected.ChildRecipes.Single(), actual.ChildRecipes.Single()); foreach (var expectedItem in expected.RecipeProducts) { Assert.Contains(actual.RecipeProducts, actualItem => expectedItem.ProductId == actualItem.ProductId && expectedItem.ProductName == actualItem.ProductName && expectedItem.CAS == actualItem.CAS && expectedItem.Quantity == actualItem.Quantity && expectedItem.Type == actualItem.Type); } foreach (var expectedItem in expected.RelatedFacilities) { Assert.Contains(actual.RelatedFacilities, actualItem => expectedItem.Id == actualItem.Id && expectedItem.Name == actualItem.Name); } }