Пример #1
0
        public async Task DeleteByMealIdAsync_Test()
        {
            // In-memory database only exists while the connection is open

            _connection.Open();

            try
            {
                var options = CreateOptionAndEnsureCreated();

                // Add an identity to the in memory database
                using (var context = new ProductContext(options))
                {
                    context.MealFood.Add(_testMealFood);
                    await context.SaveChangesAsync();
                }

                // Run the test against one instance of the context
                using (var context = new ProductContext(options))
                {
                    var repository = new EFMealFoodRepository(context);
                    await repository.DeleteByMealIdAsync(1);

                    await context.SaveChangesAsync();
                }

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = new ProductContext(options))
                {
                    var entityCount = await context.MealFood.CountAsync();

                    Assert.Equal(0, entityCount);
                }
            }
            finally
            {
                _connection.Close();
            }
        }
Пример #2
0
        public async Task AddAsync_Test()
        {
            // In-memory database only exists while the connection is open

            _connection.Open();

            try
            {
                var options = CreateOptionAndEnsureCreated();

                // Run the test against one instance of the context
                using (var context = new ProductContext(options))
                {
                    var repository = new EFMealFoodRepository(context);
                    await repository.AddAsync(_testMealFood);

                    context.SaveChanges();
                }

                // Use a separate instance of the context to verify correct data was saved to database
                using (var context = new ProductContext(options))
                {
                    var mealFoods   = context.MealFood;
                    var entityCount = await mealFoods.CountAsync();

                    var mf = await mealFoods.SingleAsync();

                    Assert.Equal(1, entityCount);
                    AssertEntityEqual(mf, _testMealFood);
                }
            }
            finally
            {
                _connection.Close();
            }
        }