public async Task GetProductsReturnAllProducts() { //Arrange var options = new DbContextOptionsBuilder <ProductsDbContext>() .UseInMemoryDatabase(nameof(GetProductsReturnAllProducts)) .Options; var dbContext = new ProductsDbContext(options); SeedData(dbContext); var productProfile = new ProductProfile(); var config = new MapperConfiguration(cfg => cfg.AddProfile(productProfile)); var mapper = new Mapper(config); var productProvider = new ProductsProvider(dbContext, null, mapper); //Act var result = await productProvider.GetProductsAsync(); //Assert Assert.True(result.IsSuccess); Assert.True(result.products.Any()); Assert.Null(result.ErrorMessage); }
public async Task GetProductsReturnsAllProducts() { var options = new DbContextOptionsBuilder <ProductsDbContext>() .UseInMemoryDatabase(nameof(GetProductsReturnsAllProducts)) .Options; var dbContext = new ProductsDbContext(options); CreateProducts(dbContext); var productprofile = new ProductProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(productprofile)); var mapper = new Mapper(configuration); var productsProvider = new ProductsProvider(dbContext, null, mapper); var product = await productsProvider.GetProductsAsync(); Assert.True(product.IsSuccess); Assert.True(product.Products.Any()); Assert.Null(product.ErrorMessage); }
public async Task GetProductsReturnsAllProducts() { //var context = new ProductsDbContext(); //var productsProvider = new ProductsProvider(); var options = new DbContextOptionsBuilder <ProductsDbContext>() .EnableSensitiveDataLogging() .UseInMemoryDatabase(nameof(GetProductsReturnsAllProducts)) .Options; var context = new ProductsDbContext(options); CreateProducts(context); var productProfile = new ProductProfile(); var configuration = new MapperConfiguration(config => config.AddProfile(productProfile)); var mapper = new Mapper(configuration); var provider = new ProductsProvider(context, null, mapper); var(isSuccess, products, errorMessage) = await provider.GetProductsAsync(); Assert.True(isSuccess); Assert.True(products.Any()); Assert.Null(errorMessage); }
public async Task GetProductsReturnsAllProducts() { var productProfile = new ProductProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(productProfile)); var mapper = new Mapper(configuration); var productsProvider = new ProductsProvider(fixture.dbContext, null, mapper); var product = await productsProvider.GetProductsAsync(); Assert.True(product.IsSuccess); Assert.True(product.Products.Any()); Assert.Null(product.ErrorMessage); }
public async Task GetProductsReturnAllProductsAsync() { //Arrange var profile = new ProductProfile(); var mapperConfig = new MapperConfiguration(a => a.AddProfile(profile)); var mapper = new Mapper(mapperConfig); var productsProvider = new ProductsProvider(dbContext, null, mapper); //act var produsts = await productsProvider.GetProductsAsync(); //Assert Assert.True(produsts.IsSuccess); Assert.True(produsts.Products.Any()); Assert.Null(produsts.ErrorMessage); }
public async Task GetAllProducts_ReturnAllProducts() { var dbContextOptions = new DbContextOptionsBuilder <ProductsDbContext>() .UseInMemoryDatabase(nameof(GetAllProducts_ReturnAllProducts)).Options; var dbContext = new ProductsDbContext(dbContextOptions); CreateProducts(dbContext); var profile = new ProductProfile(); var config = new MapperConfiguration(cfg => cfg.AddProfile(profile)); var mapper = new Mapper(config); var provider = new ProductsProvider(dbContext, null, mapper); var products = await provider.GetProductsAsync(); Assert.AreEqual(true, products.IsSuccess); Assert.IsNotNull(products.Products); Assert.IsTrue(products.Products.Count() == 10); Assert.IsTrue(products.Products.First().Name == "Product 0"); }
public async Task GetProductsReturnsAllProducts() { var options = new DbContextOptionsBuilder<ProductsDbContext>() .UseSqlServer("Data Source=LAPTOP-U3V1724K;Initial Catalog=Microservices.Products.Database;Integrated Security=True") .Options; var dbContext = new ProductsDbContext(options); var productProfile = new ProductProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(productProfile)); var mapper = new Mapper(configuration); var productsProvider = new ProductsProvider(dbContext, null, mapper, configuration, null); var product = await productsProvider.GetProductsAsync(); Assert.True(product.IsSuccess); Assert.True(product.Products.Any()); Assert.Null(product.ErrorMessage); }
public async void GetProductsReturnAllProducts() { var options = new DbContextOptionsBuilder <ProductsDbContext>() .UseInMemoryDatabase(nameof(GetProductsReturnAllProducts)) .Options; var productDbContext = new ProductsDbContext(options); var profile = new ProductProfile(); var configuration = new MapperConfiguration(config => config.AddProfile(profile)); var mapper = new Mapper(configuration); var dbprovider = new ProductsProvider(productDbContext, null, mapper); var products = await dbprovider.GetProductsAsync(); Assert.True(products.Success); Assert.NotNull(products.Products); // Assert.True(products.Products.Any()); Assert.Contains("All", products.ErrorMessage); }
public async Task GetProducts_ReturnsAllProduts() { var dbContextOptionsBuilder = new DbContextOptionsBuilder(); dbContextOptionsBuilder.UseInMemoryDatabase("GetProducts_ReturnsAllProduts"); var dbContext = new Db.ProductsDbContext(dbContextOptionsBuilder.Options); CreateData(dbContext); var mapper = new MapperConfiguration(config => { config.CreateMap <Db.Product, Models.Product>(); }).CreateMapper(); var productsProvider = new ProductsProvider(dbContext, null, mapper); var productsResult = await productsProvider.GetProductsAsync(); Assert.True(productsResult.IsSuccess); Assert.Equal(10, productsResult.Products.Count()); Assert.Null(productsResult.ErrorMessage); }