public void WhenProductsAreRetrievedExpectCorrectlyMappedProducts() { //Arrange List <Product> products = new List <Product>() { new Product { ID = 1, Name = "Name1", Description = "desc1", Price = 1.1M }, new Product { ID = 2, Name = "Name2", Description = "desc2", Price = 2.2M } }; Mock <IProductsRepository> mock = new Mock <IProductsRepository>(); mock.Setup(m => m.GetProducts()).Returns(products); ProductsApiService productsService = new ProductsApiService(mock.Object); //Act List <ProductDto> productDtos = productsService.GetProducts(); //Assert Assert.IsNotNull(productDtos); Assert.IsNotEmpty(productDtos); Assert.IsTrue(productDtos.Count == products.Count); Assert.IsTrue(productDtos.First().ID == products.First().ID); }
private void SearchProductRemainings(object sender, RoutedEventArgs e) { var productsService = new ProductsApiService(ConfigurationManager.AppSettings["ApiUrl"]); if (ProductToSearchTerm.Text?.Length > 2) { var availableProducts = productsService.GetProductAvailability(ProductToSearchTerm.Text); RemainingProductsList.ItemsSource = availableProducts; } }
public void InitializeDb() { var connectionString = ConfigurationManager.AppSettings["DbConnectionString"]; var apiUrl = ConfigurationManager.AppSettings["ApiUrl"]; var productsRepository = new ProductsRepository(connectionString); var barcodesRepository = new BarcodesRepository(connectionString); var productsApiService = new ProductsApiService(apiUrl); var allProducts = productsApiService.GetAllProducts(); var context = new RegisterDbContext(connectionString); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var barcodes = allProducts.Data.SelectMany(s => s.BarCodes); productsRepository.Add(allProducts.Data); barcodesRepository.Add(barcodes); }