public void Run() { MathematicModel model = this.userInterface.ReadModel(); int result = Calculate(model); this.userInterface.WriteResult(result); }
private static int Calculate(MathematicModel model) { switch (model.Operation) { default: return(Mathematics.Add(model.First, model.Second)); } }
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); }
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); }
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()); }
public Calculator(IMathematics mathematics, MathematicModel model) { _mathematics = mathematics; _model = model; }
public Calculator(MathematicModel model) { this.model = model; }
public ActionResult Calculate(MathematicModel input) { var ui = new Calculator(input); return(View(ui.Calculate())); }