Exemplo n.º 1
0
        public async Task TestEditIngredientToItem()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var ingredientrRepository = new EfRepository <Ingredient>(new ApplicationDbContext(options.Options));
            var itemRepository        = new EfRepository <Item>(new ApplicationDbContext(options.Options));

            ingredientrRepository.AddAsync(new Ingredient {
                Name = "Eggs", Quantity = 5
            }).GetAwaiter().GetResult();
            ingredientrRepository.SaveChangesAsync().GetAwaiter().GetResult();

            itemRepository.AddAsync(new Item {
                Name = "Meatball"
            }).GetAwaiter().GetResult();
            itemRepository.SaveChangesAsync().GetAwaiter().GetResult();

            var item       = itemRepository.All().Where(x => x.Name == "Meatball").FirstOrDefault();
            var ingredient = ingredientrRepository.All().Where(x => x.Name == "Eggs").FirstOrDefault();

            var ingredientService = new IngredientService(itemRepository, ingredientrRepository);
            //AutoMapperConfig.RegisterMappings(typeof(MyTestIngredient).Assembly);

            await ingredientService.AddIngredientToItem(ingredient.Name, ingredient.Quantity, item.Name);

            await ingredientService.EditIngredientToItem("Milk", 10, item.Name, 1);

            Assert.Equal(10, ingredient.Quantity);
            Assert.Equal("Milk", ingredient.Name);

            ingredientrRepository.Delete(ingredient);
        }