Example #1
0
        internal string Sqrt(int number)
        {
            var requestSqrt = new RequestSqrt {
                Number = number
            };
            var result = _client.Post <ResponseSqrt>("/sqrt", requestSqrt);

            return((string)result.RawData);
        }
        public async Task Task_Sqrt_Numbers()
        {
            RequestSqrt requestSqrt = new RequestSqrt()
            {
                Number = 16
            };

            string      strPayload = JsonConvert.SerializeObject(requestSqrt);
            HttpContent content    = new StringContent(strPayload, Encoding.UTF8, "application/json");
            var         response   = await _client.PostAsync("api/v1/calculator/sqrt", content);

            response.EnsureSuccessStatusCode();
            var responseString = await response.Content.ReadAsStringAsync();

            Assert.Equal("{\"square\":4.0}", responseString);
        }
Example #3
0
        public async Task <IActionResult> Sqrt([FromBody] RequestSqrt requestSqrt, CancellationToken ct = default(CancellationToken))
        {
            try {
                bool save     = Request.Headers.ContainsKey("X-Evl-Tracking-Id");
                var  id       = save ? Request.Headers["X-Evl-Tracking-Id"].ToString() : null;
                var  response = await _calculatorSupervisor.SqrtAsync(requestSqrt, save, id, ct);

                return(Ok(response));
            } catch (Exception ex) {
                var response = new ResponseCanonic()
                {
                    ErrorCode    = Enum.GetName(typeof(HttpStatusCode), HttpStatusCode.InternalServerError),
                    ErrorStatus  = (int)HttpStatusCode.InternalServerError,
                    ErrorMessage = ex.Message
                };
                return(StatusCode((int)HttpStatusCode.InternalServerError, response));
            }
        }
        public async Task <ResponseSqrt> SqrtAsync(RequestSqrt requestSqrt, bool save, string id, CancellationToken ct = default(CancellationToken))
        {
            var resSqrt = Math.Sqrt(requestSqrt.Number);

            if (save)
            {
                await _operationRepository.AddAsync(new Model.Entities.Operation()
                {
                    IdHeader      = id,
                    OperationType = "Sqrt",
                    Date          = DateTime.Now.ToString(),
                    Calculation   = $"SQRT({requestSqrt.Number}) = {resSqrt}"
                });
            }
            return(new ResponseSqrt()
            {
                Square = resSqrt
            });
        }