Exemplo n.º 1
0
        public void SimpleAttributecontributionTest()
        {
            context.SetInitialValue(context.Race("gnome"), 0);
            context.SetInitialValue(context.Ability("int"), 8);
            var result = service.Calculate(context);

            result.AssertAttribValue(context.Ability("int"), 10);
        }
Exemplo n.º 2
0
        public ActionResult Calculate(CalculationLogModel model)
        {
            var threadId = Thread.CurrentThread.ManagedThreadId;
            var x        = model.Number;

            var log = _service.Calculate(x);

            return(View("Index", new CalculationLogModel(log, model.Number, "Synchronous calculation", threadId)));
        }
Exemplo n.º 3
0
        public void CalculationWithNotANumber()
        {
            ICalculationService calculationService = new CalculationService();

            string input = "12ABC";

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(ResultType.NotANumber, result.Type);
        }
Exemplo n.º 4
0
        public void CalculationWithValueTooLarge()
        {
            ICalculationService calculationService = new CalculationService();

            string input = "2147483649"; // Int32.MaxValue + 1

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(ResultType.NumberTooLarge, result.Type);
        }
Exemplo n.º 5
0
        private void SyncButton_Click(object sender, EventArgs e)
        {
            var n = ++_count;

            LogStart(SyncButton.Text, n);

            var log = _service.Calculate(Convert.ToInt32(NumberTextBox.Text));

            LogEnd(SyncButton.Text, log, n);
        }
Exemplo n.º 6
0
        public void ConversionOfStringToInt()
        {
            ICalculationService calculationService = new CalculationService();

            string input = "3";

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(3, result.Input);
        }
Exemplo n.º 7
0
        public void CalculationWithValueEqualToUpperLimt()
        {
            ICalculationService calculationService = new CalculationService();

            string input = upperLimit.ToString();

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(ResultType.Valid, result.Type);
            Assert.AreEqual(0, result.Difference);
        }
Exemplo n.º 8
0
        public void CalculationWithValueSmallerThanUpperLimt()
        {
            ICalculationService calculationService = new CalculationService();

            string input = "2";

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(ResultType.Valid, result.Type);
            Assert.AreEqual(upperLimit - 2, result.Difference);
        }
Exemplo n.º 9
0
        public void CalculationWithNegativeValue()
        {
            ICalculationService calculationService = new CalculationService();

            string input = "-7";

            Result result = calculationService.Calculate(input);

            Assert.AreEqual(ResultType.ValidButNegativeNumber, result.Type);
            Assert.AreEqual(upperLimit - (-7), result.Difference);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var inputService  = new InputService();
            var calculator    = new CalculationService();
            var outputService = new OutputService();


            string inputLine = inputService.GetInput();
            double answer    = calculator.Calculate(inputLine);

            outputService.ShowResult(answer);
        }
Exemplo n.º 11
0
        public string Get(string leftOperand, string rightOperand, string operation)
        {
            var ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            _loggingService.Log(leftOperand, rightOperand, operation, ipAddress);

            try
            {
                var result = _calculationService.Calculate(leftOperand, rightOperand, operation);
                return(result);
            }
            catch (Exception)
            {
                return("ERROR");
            }
        }
        public async Task <IActionResult> CreateCalculation([FromBody] Calculation calculation)
        {
            try
            {
                calculation.Agent     = Agent + "/ ip = " + calculation.Agent;
                calculation.CreatedAt = DateTime.UtcNow;
                calculation           = await calculationService.Calculate(calculation);

                await calculationService.CreateCalculationAsync(calculation);

                return(new OkObjectResult(calculation));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(new { Message = ex.Message }));
            }
        }
 public ActionResult Calculate(string expression)
 {
     try
     {
         var res = calculationService.Calculate(expression);
         SaveToBd(expression, res);
         return(Json(new CalculationResult {
             Result = res
         }, JsonRequestBehavior.AllowGet));
     }
     catch (InvalidExpressionException ex)
     {
         return(Json(new CalculationResult {
             Result = null
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            ConnectionFactory factory = new ConnectionFactory();

            factory.HostName    = "localhost";
            factory.VirtualHost = "/";
            factory.Port        = 5672;
            factory.UserName    = "******";
            factory.Password    = "******";

            conn    = factory.CreateConnection();
            channel = conn.CreateModel();

            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += (sender, e) =>
            {
                Console.WriteLine("Request received");
                string             message = Encoding.UTF8.GetString(e.Body);
                CalculationRequest request = JsonConvert.DeserializeObject <CalculationRequest>(message);

                CalculationService calcService = new CalculationService();
                var response     = calcService.Calculate(request);
                var responseData = JsonConvert.SerializeObject(response);

                var basicProperties = channel.CreateBasicProperties();
                basicProperties.Headers = new Dictionary <string, object>();
                basicProperties.Headers.Add(Constants.RequestIdHeaderKey, e.BasicProperties.Headers[Constants.RequestIdHeaderKey]);
                Console.WriteLine("Request received " + message);
                channel.BasicAck(e.DeliveryTag, false);

                channel.BasicPublish("", "responses", basicProperties, Encoding.UTF8.GetBytes(responseData));
            };

            string consumerTag = channel.BasicConsume("requests", false, consumer);

            Console.WriteLine("Please any key to exit");
            Console.ReadKey();

            channel.Close();
            conn.Close();
        }
Exemplo n.º 15
0
        public void Caclulate_TaxRatePassed_ProductWithAppliedTax(decimal taxRate, float expectedPriceInt)
        {
            // Arrange
            CalculationService calculationService = new CalculationService(taxRate);

            decimal expectedPrice = (decimal)expectedPriceInt;
            Product testProduct   = new Product
                                    (
                PRODUCT_NAME,
                UPC,
                new Money(PRICE)
                                    );

            // Act
            Receipt result = calculationService.Calculate(testProduct);

            // Assert
            Assert.Equal(PRODUCT_NAME, result.Product.Name);
            Assert.Equal(UPC, result.Product.UPC);
            Assert.Equal(expectedPrice, result.Product.Price.Amount);
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            ICalculationService calculationService = new CalculationService();

            bool repeat = true;

            while (repeat)
            {
                Console.Write("Enter a number equal or smaller than {0} (Enter 'q' to quit): ", ConfigurationManager.AppSettings["UpperLimit"]);

                string input = Console.ReadLine().ToLower();
                if (input.Equals("q"))
                {
                    Environment.Exit(0);
                }

                Result result = calculationService.Calculate(input);

                Console.WriteLine(result.ToString());
            }
        }
        public void CalculationService_ShouldPerformCalculation()
        {
            var sut = new CalculationService();

            sut.Calculate(1, 2).Should().Be(17);
        }