Example #1
0
        public void TestDivisors_ResultAreEqual()
        {
            const long number = 100000;

            #region Expected object
            var expectedDivisors = new List <long> {
                1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 80, 100,
                125, 160, 200, 250, 400, 500, 625, 800, 1000, 1250,
                2000, 2500, 3125, 4000, 5000, 6250, 10000, 12500, 20000,
                25000, 50000, 100000
            };
            #endregion

            Guid numberProcessingId = _numberProcessingService.RequestProcess(number);

            bool      isReady;
            const int defaultWaitTime = 500;

            do
            {
                Thread.Sleep(defaultWaitTime);
                isReady = _numberProcessingService.CheckIsReady(numberProcessingId);
            } while (!isReady);

            NumberProcessingResult result = _numberProcessingService.GetResult(numberProcessingId);

            result.Divisors.Sort();
            expectedDivisors.Sort();

            CollectionAssert.AreEqual(expectedDivisors, result.Divisors);
        }
Example #2
0
        public async Task <IActionResult> GetAsync(Guid id)
        {
            try
            {
                NumberProcessingResult result =
                    await Task.Run(() => _numberProcessingService.GetResult(id));


                return(new ObjectResult(result.ToModel()));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Example #3
0
 private static NumberProcessingResult GetResult(Guid numberProcessingId)
 {
     ConsoleHelper.WriteLineWithTime($"Obtendo resultado da solicitação de ID {numberProcessingId}");
     return(_numberProcessingService.GetResult(numberProcessingId));
 }