public void QueryConsumable_BadInputs()
        {
            var consumable = _captainHookGenerator.GenerateQueryConsumable();

            consumable.category = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForStockQuery(consumable));

            consumable = _captainHookGenerator.GenerateQueryConsumable();
            consumable.address.Country = "";
            Assert.Throws <ArgumentException>(() => _service.ValidateForStockQuery(consumable));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetAsync([FromQuery][Required] string region,
                                                   [FromQuery] Consumable consumable, [FromQuery] Address address)
        {
            NullCheck.ThrowIfNull <Consumable>(consumable);
            NullCheck.ThrowIfNull <Address>(address);

            try
            {
                _configurationService.ThrowIfUnknownRegion(region);
                consumable.address = address;
                _resourceStockInputValidatorService.ValidateForStockQuery(consumable);
                return(Ok(await _resourceStockQueryService.QueryOffersAsync(consumable, region).ToListAsync()));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
            catch (UnknownAdressException e)
            {
                return(BadRequest(e.Message));
            }
        }