Ejemplo n.º 1
0
        public void Interpret_ThrowError_WhenCalledNullOrEmpty(string input)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            Assert.ThrowsException <ArgumentNullException>(() => engine.Interpret(input, CultureInfo.CurrentCulture, out _));
        }
        public void Interpret_ThrowError_WhenCalledNullOrEmpty(string input)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            Assert.Catch <ArgumentNullException>(() => engine.Interpret(input));
        }
        [TestCase("pi(2)")] // Incorrect input, constant is being treated as a function.
        public void Interpret_NoResult_WhenCalled(string input)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            var result = engine.Interpret(input);

            // Assert
            Assert.AreEqual(default(CalculateResult), result);
        }
Ejemplo n.º 4
0
        [TestCase("123 456", 56088D)]                                      // BUG: Framework accepts ' ' as multiplication
        public void Interpret_QuirkOutput_WhenCalled(string input, decimal expectedResult)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            var result = engine.Interpret(input, CultureInfo.InvariantCulture);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result.Result);
        }
Ejemplo n.º 5
0
        public void Interpret_NoErrors_WhenCalledWithRounding(string input, decimal expectedResult)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            var result = engine.Interpret(input, CultureInfo.InvariantCulture);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(CalculateEngine.Round(expectedResult), result.RoundedResult);
        }
Ejemplo n.º 6
0
        public void Interpret_MustReturnResult_WhenResultIsZero(string input)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            var result = engine.Interpret(input, CultureInfo.InvariantCulture);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0.0, result.Result);
        }
        public void Interpret_DifferentCulture_WhenCalled(string input, decimal expectedResult, string cultureName)
        {
            // Arrange
            var cultureInfo = CultureInfo.GetCultureInfo(cultureName);
            var engine      = new CalculateEngine();

            // Act
            var result = engine.Interpret(input, cultureInfo);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(CalculateEngine.Round(expectedResult), result.RoundedResult);
        }
        public void Interpret_MustReturnExpectedResult_WhenCalled(string input, decimal expectedResult)
        {
            // Arrange
            var engine = new CalculateEngine();

            // Act
            // Using InvariantCulture since this is internal
            var result = engine.Interpret(input, CultureInfo.InvariantCulture);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result.Result);
        }
Ejemplo n.º 9
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            _state = new CurrentStateModel();
            Running.DataContext     = _state;
            Count.DataContext       = _state;
            CountPerSec.DataContext = _state;

            _backgroundWorker = new CalculateEngine();
            _backgroundWorker.Run();

            _timer          = new Timer(100);
            _timer.Elapsed += TimerTick;
            _timer.Start();
        }
Ejemplo n.º 10
0
            public void DoWork()
            {
                var calculator = new CalculateEngine();

                calculator.DoJob(id);
            }
Ejemplo n.º 11
0
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage([ServiceBusTrigger("bus2")] BrokeredMessage message, TextWriter log)
        {
            var calculatejob = new CalculateEngine();

            calculatejob.DoJob(message.MessageId);
        }