Beispiel #1
0
        public void Run()
        {
            MathematicModel model  = this.userInterface.ReadModel();
            int             result = Calculate(model);

            this.userInterface.WriteResult(result);
        }
Beispiel #2
0
 private static int Calculate(MathematicModel model)
 {
     switch (model.Operation)
     {
     default:
         return(Mathematics.Add(model.First, model.Second));
     }
 }
Beispiel #3
0
        public void PostedValidModel_Calculate_RendersResult()
        {
            var input = new MathematicModel()
            {
                First  = 5,
                Second = 2
            };
            var          viewResult = this.controller.Calculate(input) as ViewResult;
            const string message    = "The calculated result should be delivered as model to the view";

            Assert.IsInstanceOf(typeof(int), viewResult.Model, message);
        }
Beispiel #4
0
        public void Calculate()
        {
            // Arrange
            HomeController controller = new HomeController();
            var            input      = new MathematicModel
            {
                First  = 5,
                Second = 2
            };

            // Act
            ViewResult result = controller.Calculate(input) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(int), result.Model);
        }
Beispiel #5
0
        public void FiveTwo_Calculate_WritesSevenToUi()
        {
            var model = new MathematicModel()
            {
                First  = 5,
                Second = 2
            };

            var userInterfaceMock = new Mock <IUserInterface>();

            userInterfaceMock.Setup(c => c.ReadModel())
            .Returns(model);
            userInterfaceMock.Setup(c => c.WriteResult(7))
            .Verifiable("output of add operation should be written to the ui");

            var calculator = new CalculatorService(userInterfaceMock.Object);

            calculator.Run();
            userInterfaceMock.VerifyAll();
        }
        // GET api/values
        public int Get([FromUri] MathematicModel input)
        {
            var ui = new Models.Calculator(_mathematics, input);

            return(ui.Calculate());
        }
Beispiel #7
0
 public Calculator(IMathematics mathematics, MathematicModel model)
 {
     _mathematics = mathematics;
     _model       = model;
 }
Beispiel #8
0
 public Calculator(MathematicModel model)
 {
     this.model = model;
 }
Beispiel #9
0
        public ActionResult Calculate(MathematicModel input)
        {
            var ui = new Calculator(input);

            return(View(ui.Calculate()));
        }