示例#1
0
        public async Task AddImageUrlsAsyncShouldAddImageUrls()
        {
            var options = new DbContextOptionsBuilder <PhotoparallelDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new PhotoparallelDbContext(options);

            var productService = new ProductsService(dbContext);

            var productName = "Canon M50";

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = productName
                },
                new Product {
                    Name = "Canon EOS200"
                },
                new Product {
                    Name = "Ikan Ms"
                },
                new Product {
                    Name = "canon Ef-M 55-200 lens"
                },
                new Product {
                    Name = "Dji Phantom 4"
                },
            });
            await dbContext.SaveChangesAsync();

            var productId = dbContext.Products.FirstOrDefault(x => x.Name == productName).Id;
            var imageUrls = new List <string> {
                "wwwroot/image1", "wwwroot/image2", "wwwroot/image3"
            };
            await productService.AddImageUrlsAsync(productId, imageUrls);

            var product = dbContext.Products.FirstOrDefault(x => x.Id == productId);

            Assert.Equal(3, product.Images.Count);
        }