예제 #1
0
        public async Task <IActionResult> GetFizzBuzz()
        {
            try
            {
                var results = await _service.FizzBuzz();

                var response = new FizzBuzzResponse {
                    Results = results
                };

                return(Ok(response));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);

                if (e is ArgumentOutOfRangeException || e is ArgumentNullException)
                {
                    return(BadRequest(e.Message));
                }

                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #2
0
        /// <summary>
        /// Expose FizzBuzz service to outside
        /// </summary>
        /// <param name="n">The n.</param>
        /// <returns></returns>
        public IEnumerable <string> Get(int n)
        {
            //TODO: return 400 back to user
            if (n <= 0)
            {
                return new List <string> {
                           "n must be greater then 0"
                }
            }
            ;

            return(n > 100 ? new List <string> {
                "n must be less then 101"
            } : _service.FizzBuzz(n));
        }
    }
예제 #3
0
        public async Task <string> Handle(GetFizzBuzzQuery request, CancellationToken cancellationToken)
        {
            var result = await Task.Run(() => _fizzBuzzService.FizzBuzz(request.Value));

            return(result);
        }