Ejemplo n.º 1
0
        public void Test()
        {
            _calculator.Add(1, 3).Returns(4);

            _calculatorService.Add(1, 3).Should().Be(4);
            _calculator.Received(1).Add(1, 3);
        }
Ejemplo n.º 2
0
        public void Twice()
        {
            var calculator = MockRepository.GenerateMock <ICalculator>();

            calculator.Expect(cal => cal.Add(1, 2)).Return(3).Repeat.Twice();

            var calculatorService = new CalculatorService(calculator);
            var sum  = calculatorService.Add(1, 2);
            var sum2 = calculatorService.Add(1, 2);

            Assert.Equal(3, sum);
            Assert.Equal(3, sum2);
            calculator.VerifyAllExpectations();
        }
Ejemplo n.º 3
0
        static void Main()
        {
            using (var activator = new BuiltinHandlerActivator())
            {
                activator.Register(() => new ResultReceivedEventHandler());

                Configure.With(activator)
                .Logging(l => l.ColoredConsole(LogLevel.Info))
                .Routing(s => s.TypeBased().MapAssemblyOf <ResultReceivedEvent>("calculator-subscriber"))
                .Transport(t => t.UseMsmq("calculator-publisher"))
                .Subscriptions(s => s.UseJsonFile(JsonFilePath))
                .Start();

                activator.Bus.Subscribe <ResultReceivedEvent>();

                _calculatorService = new CalculatorService(activator.Bus);

                while (true)
                {
                    Console.WriteLine(@"1) Add 1 + 2
2) Add 2 + 3
q) Quit");

                    var keyChar = char.ToLower(Console.ReadKey(true).KeyChar);

                    switch (keyChar)
                    {
                    case '1':
                        _calculatorService.Add(1, 2);
                        break;

                    case '2':
                        _calculatorService.Add(2, 3);
                        break;

                    case 'q':
                        goto consideredHarmful;

                    default:
                        Console.WriteLine("Invalid key ({0})", keyChar);
                        break;
                    }
                }

consideredHarmful:
                Console.WriteLine("Quitting!");
            }
        }
Ejemplo n.º 4
0
        private int CalculatorServiceAdd(int num1, int num2)
        {
            var calculatorService = new CalculatorService();
            var actual            = calculatorService.Add(num1, num2);

            return(actual);
        }
Ejemplo n.º 5
0
        public void TesVariousDelimetrs()
        {
            string pattern = @"-?\d+";
            string input   = "//***\ndsada1fds***2***10”,3,4,2000,";
            var    matches = Regex.Matches(input, pattern);

            StringBuilder positiveNumberList = new StringBuilder();

            for (int i = 0; i < matches.Count; i++)
            {
                int result = 0;

                if (!string.IsNullOrEmpty(matches[i].ToString()) && int.TryParse(matches[i].ToString(), out result) && result > 0 && result <= 1000)
                {
                    positiveNumberList.Append(result + ",");
                }
            }

            int expected = 20;


            CalculatorService calculatorService = new CalculatorService();
            int actual = calculatorService.Add(positiveNumberList.ToString().TrimEnd(','));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     a = Convert.ToDecimal(txtFno.Text);
     b = Convert.ToDecimal(txtSno.Text);
     c = oCalc.Add(a, b);
     lblResult.Text = c.ToString();
 }
        public void Add_Given5PlusMinus2_ResultsIn3()
        {
            var calculator = new CalculatorService();

            var result = calculator.Add(5, -2);

            result.Should().Be(3);
        }
Ejemplo n.º 8
0
        public void Adding_Two_And_Two_Should_Equal_Four()
        {
            var m      = 2;
            var n      = 2;
            var result = _calculatorService.Add(m, n);

            Assert.Equal(4.0, result, 0);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            CalculatorService calculatorService = new CalculatorService();

            Console.WriteLine("Addition:{0}", calculatorService.Add(7, 8));
            Console.WriteLine("Subtraction:{0}", calculatorService.Sub(20, 8));
            Console.Read();
        }
        public void Add_Given2Plus2_ResultsIn4()
        {
            var calculator = new CalculatorService();

            var result = calculator.Add(2, 2);

            result.Should().Be(4);
        }
Ejemplo n.º 11
0
        public void BinaryInputAddTest(string commaSeparatedOperands, int expectedResult)
        {
            var delimterService = new DelimiterService();

            var validationService = new ValidationService(delimterService);
            var calService        = new CalculatorService(validationService);
            var sum = calService.Add(commaSeparatedOperands);

            Assert.Equal(expectedResult, sum);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            CalculatorService cal = new CalculatorService();

            Console.Write("Enter input string: ");

            string input = Console.ReadLine();

            cal.Add(input);
        }
Ejemplo n.º 13
0
        public void ShowOptionMenu()
        {
            int option;

            do
            {
                Console.ForegroundColor = ConsoleColor.Gray;

                Console.WriteLine("\nEnter an option: 1.Add | 2.Subtract | 3.Multiply | 4.Divide | 5.Square Root | 6.Query | 7.Exit");

                option = CalculatorService.ReadInt("option");

                switch (option)
                {
                case 1:
                    Console.WriteLine("\nYou have selected add");
                    CalculatorService.Add();
                    break;

                case 2:
                    Console.WriteLine("\nYou have selected subtract");
                    CalculatorService.Subtract();
                    break;

                case 3:
                    Console.WriteLine("\nYou have selected multiply");
                    CalculatorService.Multiply();
                    break;

                case 4:
                    Console.WriteLine("\nYou have selected divide");
                    CalculatorService.Divide();
                    break;

                case 5:
                    Console.WriteLine("\nYou have selected square root");
                    CalculatorService.SquareRoot();
                    break;

                case 6:
                    Console.WriteLine("\nRequest all operations for a Tracking-Id since the last application restart");
                    CalculatorService.Query();
                    break;

                case 7:
                    Console.WriteLine("\nYou have left the application\n");
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("\nPlease enter a valid option");
                    break;
                }
            } while (option != 7);
        }
        public void CanIntegrate_AdditionService_AndAdd_1_2()
        {
            // Arrange
            CalculatorService subject  = new CalculatorService(new AdditionService(), new SubtractionService());
            float             expected = 3f;

            // Act
            float actual = subject.Add(1, 2);

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.Write("Enter input string: ");

            string input = Console.ReadLine();

            if (input.Length == 0)
            {
                Console.WriteLine("Sum : " + input.Length.ToString());
                Console.Read();
            }

            List <int> negativeInt = new List <int>();
            string     pattern     = @"-?\d+";
            var        matches     = Regex.Matches(input, pattern);

            StringBuilder negativeNumberList = new StringBuilder("Negative numbers in the string:");
            StringBuilder positiveNumberList = new StringBuilder();

            for (int i = 0; i < matches.Count; i++)
            {
                int result = 0;

                if (!string.IsNullOrEmpty(matches[i].ToString()) && int.TryParse(matches[i].ToString(), out result) && result > 0 && result <= 1000)
                {
                    positiveNumberList.Append(result + ",");
                }
                if (result < 0)
                {
                    negativeNumberList.Append(result.ToString() + ",");
                    negativeInt.Add(result);
                }
            }

            if (negativeInt.Count > 0)
            {
                Console.WriteLine(new Exception("Negatives not allowed."));
                Console.WriteLine(negativeNumberList.ToString().TrimEnd(','));
                Console.Read();
            }
            else if (positiveNumberList.Length > 0)
            {
                CalculatorService calculatorService = new CalculatorService();
                Console.WriteLine("Sum: " + calculatorService.Add(positiveNumberList.ToString().TrimEnd(',')));
                Console.Read();
            }
            else
            {
                Console.WriteLine("Not found any number");
                Console.Read();
            }
        }
Ejemplo n.º 16
0
        public void Calculator_should_be_able_to_add_2_by_2()
        {
            // ARRANGE
            CalculatorService service = new CalculatorService();
            int x = 2, y = 2;
            int result;

            // ACT
            result = service.Add(x, y);

            //ASSERT
            Assert.Equal(4, result);
        }
Ejemplo n.º 17
0
        public void Calculator_should_be_able_to_add(int x, int y)
        {
            // ARRANGE
            CalculatorService service = new CalculatorService();
            //int x = 2, y = 2;
            int result;
            int assertion = x + y;

            // ACT
            result = service.Add(x, y);

            //ASSERT
            Assert.Equal(assertion, result);
        }
Ejemplo n.º 18
0
        public void BinaryInputAddExcpetionTest()
        {
            var delimterService   = new DelimiterService();
            var validationService = new ValidationService(delimterService);
            var calService        = new CalculatorService(validationService);

            try
            {
                var sum = calService.Add("2,3,4");
            } catch (Exception ex)
            {
                Assert.IsType(typeof(NotBinaryOperandException), ex);
            }
        }
Ejemplo n.º 19
0
        public void Any(int times)
        {
            var calculator = MockRepository.GenerateMock <ICalculator>();

            calculator.Expect(cal => cal.Add(1, 2)).Return(3).Repeat.Any();

            var calculatorService = new CalculatorService(calculator);

            for (var i = 0; i < times; i++)
            {
                var sum = calculatorService.Add(1, 2);
                Assert.Equal(3, sum);
            }
            calculator.VerifyAllExpectations();
        }
Ejemplo n.º 20
0
        public async Task DivideStrategy_Success_Handled()
        {
            List <double> inputs = new List <double> {
                1, 2, 3
            };
            CalculatorResponse expectedResponse = new CalculatorResponse();

            expectedResponse.SetResult(0.16666, true, 200, new List <string>());
            var computeResolver = new Mock <IComputeResolver>();

            computeResolver.Setup(cr => cr.Compute(inputs)).ReturnsAsync(0.16666);
            ICalculatorService calculator = new CalculatorService(computeResolver.Object);
            var result = await calculator.Add(inputs);

            expectedResponse.Should().BeEquivalentTo(result);
        }
Ejemplo n.º 21
0
        public async Task MultiplyStrategy_Failure_Handled()
        {
            List <double> inputs = new List <double> {
                1, 2, 3
            };
            CalculatorResponse expectedResponse = new CalculatorResponse();

            expectedResponse.SetResult(double.NaN, false, 500, new List <string>()
            {
                Resources.GenericException
            });
            var computeResolver = new Mock <IComputeResolver>();

            computeResolver.Setup(cr => cr.Compute(inputs)).ThrowsAsync(new Exception(Resources.GenericException));
            ICalculatorService calculator = new CalculatorService(computeResolver.Object);
            var result = await calculator.Add(inputs);

            expectedResponse.Should().BeEquivalentTo(result);
        }
Ejemplo n.º 22
0
        public void AtLeastOnce(int times)
        {
            var calculator = MockRepository.GenerateMock <ICalculator>();

            calculator.Expect(cal => cal.Add(1, 2)).Return(3).Repeat.AtLeastOnce();

            var calculatorService = new CalculatorService(calculator);

            for (var i = 0; i < times; i++)
            {
                var sum = calculatorService.Add(1, 2);
                Assert.Equal(3, sum);
            }

            if (times == 0)
            {
                Assert.Throws <Moq.MockException>(() => calculator.VerifyAllExpectations());
            }
            else
            {
                calculator.VerifyAllExpectations();
            }
        }
Ejemplo n.º 23
0
 public void WhenIPressAdd()
 {
     _calculatorService.Add(ScenarioContext.Current.Get <int>("first"), ScenarioContext.Current.Get <int>("second"));
 }
Ejemplo n.º 24
0
 public async Task Execute(BehaviorContext <ClaimAdjustmentInstance, CreateClaim> context,
                           Behavior <ClaimAdjustmentInstance, CreateClaim> next)
 {
     context.Instance.Value = _calculator.Add(context.Data.X, context.Data.Y);
 }
Ejemplo n.º 25
0
 public void Execute(Composer composer, ClaimAdjustment instance, CreateClaim value)
 {
     composer.Execute(() => { instance.Value = _calculator.Add(value.X, value.Y); });
 }
 public ActionResult <float> Add(float num1, float num2)
 {
     return(calcService.Add(num1, num2));
 }
Ejemplo n.º 27
0
 public void TestAdd1(int value)
 {
     Assert.AreEqual(value, calculator.Add(0, value));
 }