public void DivideReturnOk()
        {
            // Arrange
            DivideRequest testDivideRequest = new DivideRequest();

            testDivideRequest.Dividend = 11;

            testDivideRequest.Divisor = 2;

            // Act
            var client = new RestClient("http://localhost:54405/api/calculator/");

            var request = new RestRequest("div", Method.POST);

            string json = JsonConvert.SerializeObject(testDivideRequest);

            request.AddJsonBody(json);

            var response = client.Execute(request);

            var proccessResponse = JsonConvert.DeserializeObject <DivideResponse>(response.Content);

            DivideResponse compare = new DivideResponse {
                Quotient = 5, Remainder = 1
            };

            // Assert
            Assert.AreEqual(5, proccessResponse.Quotient);

            Assert.AreEqual(1, proccessResponse.Remainder);
        }
        public void DivideReturnBadRequest()
        {
            try
            {
                // Arrange
                DivideRequest testDivideRequest = null;

                // Act
                var client = new RestClient("http://localhost:54405/api/calculator/");

                var request = new RestRequest("div", Method.POST);

                string json = JsonConvert.SerializeObject(testDivideRequest);

                request.AddJsonBody(json);

                var response = client.Execute(request);

                var proccessResponse = JsonConvert.DeserializeObject <DivideResponse>(response.Content);

                DivideResponse compare = new DivideResponse {
                    Quotient = 5, Remainder = 1
                };
            }
            catch (HttpResponseException ex)
            {
                // Assert
                Assert.AreEqual(ex.Response.StatusCode, HttpStatusCode.BadRequest);
            }
        }
        public IHttpActionResult Divide(DivideRequest request)
        {
            logger.Trace("Service called: divide");

            // An invalid request has been received
            // This may mean the HTTP requests and/or the HTTP body may contains some errors which should be fixed

            if (request == null)
            {
                logger.Error(HttpStatusCode.BadRequest);

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            try
            {
                DivideResponse result = new DivideResponse();

                // Execute operation: Divison
                string dataJournal = "";

                result.Quotient  = request.Dividend / request.Divisor;
                result.Remainder = request.Dividend % request.Divisor;

                dataJournal += request.Dividend + " / " + request.Divisor + " = " + "quotient: " + result.Quotient + " remainder: " + result.Remainder;

                logger.Trace("Divide success!!");

                IEnumerable <string> headerValues;

                // If tracking ID exists create operation instance and store in journal
                if (Request.Headers.TryGetValues("X-Evi-Tracking-Id", out headerValues))
                {
                    string id;

                    id = headerValues.FirstOrDefault();

                    var operation = new Operation()
                    {
                        Name        = "division",
                        Calculation = dataJournal,
                        Date        = DateTime.Now
                    };

                    Journal.Store(id, operation);
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                // An unexpected error condition was triggered which made impossible to fulfill the request
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
        public static void Divide()
        {
            int dividend, divisor;

            try
            {
                DivideRequest div = new DivideRequest();

                string id = AskTrackingId();

                Console.WriteLine("\nEnter dividend and divisor");

                Console.WriteLine("\nEnter dividend:");

                dividend = ReadInt("dividend");

                div.Dividend = dividend;

                Console.WriteLine("\nEnter divisor: ");

                divisor = ReadInt("divisor");

                div.Divisor = divisor;

                var client = new RestClient(ENDPOINT);

                var request = new RestRequest("div", Method.POST);

                string json = JsonConvert.SerializeObject(div);

                request.AddJsonBody(json);

                // Add to headers 'X-Evi-Tracking-Id'
                if (id != "")
                {
                    request.AddHeader("X-Evi-Tracking-Id", id);
                }

                var response = client.Execute(request);

                var proccessResponse = JsonConvert.DeserializeObject <DivideResponse>(response.Content);

                Console.ForegroundColor = ConsoleColor.Green;

                Console.WriteLine("\nQuotient: " + proccessResponse.Quotient);

                Console.WriteLine("\nRemainder: " + proccessResponse.Remainder);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public async void ExecuteCalculatorDivideRequest()
        {
            DivideRequest request = new DivideRequest()
            {
                intA = UnityEngine.Random.Range(-byte.MaxValue, byte.MaxValue),
                intB = UnityEngine.Random.Range(1, byte.MaxValue / 16)
            };
            DivideResponse response = await Divide.Execute(_calculatorClient, request);

            if (response != null)
            {
                _results.text = string.Format("{0} / {1} = {2}", request.intA, request.intB, response.Value) + Environment.NewLine;
            }
        }
        public async Task <double> Divide(DivideRequest req)
        {
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            var channel = GrpcChannel.ForAddress("http://localhost:8081");
            var client  = new Protomath.mathService.mathServiceClient(channel);

            var divideReq = new Protomath.divideRequest();

            foreach (var num in req.numbers)
            {
                divideReq.Numbers.Add(num);
            }
            var reply = await client.divideAsync(divideReq);

            return(reply.Result);
        }
        public static void TestDivide()
        {
            DivideRequest div = new DivideRequest();

            div.Dividend = 11;

            div.Divisor = 2;

            var client = new RestClient(ENDPOINT);

            var request = new RestRequest("div", Method.POST);

            string json = JsonConvert.SerializeObject(div);

            request.AddJsonBody(json);

            var response = client.Execute(request);

            var proccessResponse = JsonConvert.DeserializeObject <DivideResponse>(response.Content);

            Console.WriteLine("\nResult: " + proccessResponse.Quotient);

            Console.WriteLine("\nRemainder: " + proccessResponse.Remainder);
        }
 public async Task<DivideResponse> DivideAsync(DivideRequest request)
 {
     using (var client = new WebClient())
     {
         await client.DownloadDataTaskAsync(new Uri(this.url + "divide?id=" + request.CalculatorId + "&value=" + request.Value));
     }
     return new DivideResponse();
 }
 public DivideResponse Divide(DivideRequest request)
 {
     using (var client = new WebClient())
     {
         client.DownloadData(new Uri(this.url + "divide?id=" + request.CalculatorId + "&value=" + request.Value));
     }
     return new DivideResponse();
 }