Пример #1
0
        public async void DeleteProduct(string expectedName)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestDeleteItemDb").Options;

            var id      = Guid.NewGuid();
            var product = new Product
            {
                Id          = id,
                Name        = "Keyboard",
                Quantity    = 20,
                Description = "",
                Enable      = true
            };

            using (var context = new ApplicationDbContext(options))
            {
                var _productService = new EntityService <Product>(context);
                await _productService.CreateAsync(product);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var _productService = new EntityService <Product>(context);
                await _productService.DisableAsync(product);

                var result = await _productService.FindByConditionAsync(p => p.Enable);

                var result1 = await _productService.GetAllAsync();

                Assert.Empty(result);
                Assert.NotEmpty(result1);
                Assert.Equal(expectedName, result1.First().Name);
                Assert.False(result1.First().Enable);
            }
        }