public ProductService(IProductSorterFactory factory, HttpClient client) { _wooliesApiEndpoint = Environment.GetEnvironmentVariable("WooliesApiEndpoint"); _appToken = Environment.GetEnvironmentVariable("AppToken"); _factory = factory; _httpClient = client; }
public ProductServiceTests() { Environment.SetEnvironmentVariable("AppToken", "token"); Environment.SetEnvironmentVariable("WooliesApiEndpoint", "http://endpoint/"); var rand = new Random(); _fixture = new Fixture(); _products = _fixture.CreateMany <Product>(5); _customers = _fixture.Build <Customer>() .Without(c => c.Products) .CreateMany(5); foreach (var customer in _customers) { // generates a product array of random size from products generated by autofixture customer.Products = _products.OrderBy(p => Guid.NewGuid()) .Take(rand.Next(1, 3)) .ToArray(); } _factory = new ProductSorterFactory(); _handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); _httpClient = new HttpClient(_handlerMock.Object); _productService = new ProductService(_factory, _httpClient); }
public ProductService(ILogger <ProductService> logger, IOptions <WooliesXOptions> options, IWooliesXClient wooliesXClient, IProductSorterFactory productSorterFactory, IMapper mapper) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _wooliesXOptions = options?.Value ?? throw new ArgumentNullException(nameof(options)); _wooliesXClient = wooliesXClient ?? throw new ArgumentNullException(nameof(wooliesXClient)); _productSorterFactory = productSorterFactory ?? throw new ArgumentNullException(nameof(productSorterFactory)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log, [Inject] IProductsService productsService, [Inject] IProductSorterFactory productSorterFactory ) { string sortOption = req.Query["sortOption"]; if (!Enum.TryParse(sortOption, true, out SortOptionType sortOptionType)) { return(new BadRequestResult()); } var productSorter = productSorterFactory.Create(sortOptionType); var products = await productsService.GetProductsAsync(); return((ActionResult) new OkObjectResult(await productSorter.Sort(products))); }
public ProductsService(IApiResourceProxy apiResourceProxy, IProductSorterFactory productSorterFactory) { _apiResourceProxy = apiResourceProxy; _productSorterFactory = productSorterFactory; }
public ProductServiceTests() { _apiResourceProxy = Substitute.For <IApiResourceProxy>(); _productSorterFactory = new ProductSorterFactory(_apiResourceProxy); _sut = new ProductsService(_apiResourceProxy, _productSorterFactory); }