예제 #1
0
        public async Task AddAsyncTest_ShouldContainNewProduct()
        {
            _configuration = new ConfigurationBuilder().Build();
            var options = new DbContextOptionsBuilder <NorthWeirdDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new NorthWeirdDbContext(options))
            {
                var service      = new SqlProductData(context, _configuration, _mapper);
                var productToAdd = new ProductDto {
                    ProductName = "Lososij", ProductId = 4
                };
                await service.AddAsync(productToAdd);
            }

            using (var context = new NorthWeirdDbContext(options))
            {
                var product = context.Products.First();

                Assert.AreEqual(1, context.Products.Count());
                Assert.AreEqual(4, product.ProductId);
                Assert.AreEqual("Lososij", product.ProductName);
            }
        }
예제 #2
0
 public SqlProductData(
     NorthWeirdDbContext context,
     IConfiguration configuration,
     IMapper mapper
     )
 {
     _context       = context;
     _configuration = configuration;
     _mapper        = mapper;
 }
예제 #3
0
        public static NorthWeirdDbContext Create()
        {
            var options = new DbContextOptionsBuilder <NorthWeirdDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;
            var context = new NorthWeirdDbContext(options);

            context.Database.EnsureCreated();

            context.Suppliers.AddRange(new List <Supplier>
            {
                new Supplier {
                    SupplierId = 1, CompanyName = "Dumpling boutique"
                },
                new Supplier {
                    SupplierId = 2, CompanyName = "Washington Bread Factory №2"
                },
                new Supplier {
                    SupplierId = 3, CompanyName = "Alaska fishing inс"
                }
            });

            context.Categories.AddRange(new List <Category>
            {
                new Category {
                    CategoryId = 1, CategoryName = "Fish"
                },
                new Category {
                    CategoryId = 2, CategoryName = "Meat"
                },
                new Category {
                    CategoryId = 3, CategoryName = "Vegetables"
                }
            });

            context.Products.AddRange(new List <Product>
            {
                new Product {
                    ProductId = 1, ProductName = "Frutella", CategoryId = 1, SupplierId = 1
                },
                new Product {
                    ProductId = 2, ProductName = "Mars", CategoryId = 2, SupplierId = 2
                },
                new Product {
                    ProductId = 3, ProductName = "Onion", CategoryId = 3, SupplierId = 3
                }
            });

            context.SaveChanges();
            return(context);
        }
예제 #4
0
 public static void Destroy(NorthWeirdDbContext context)
 {
     context.Database.EnsureDeleted();
     context.Dispose();
 }
예제 #5
0
 public void Setup()
 {
     _context = NorthWeirdDbContextFactory.Create();
     _mapper  = new MapperConfiguration(c => c.AddMaps(typeof(ProductMappingProfile))).CreateMapper();
 }
예제 #6
0
 public SqlSupplierData(NorthWeirdDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
예제 #7
0
 public SqlCategoryData(NorthWeirdDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }