public Calculator(IPostfixBuilder postfixBuilder, IPostfixCalculator postfixCalculator, IEquationParser equationParser) { _postfixBuilder = postfixBuilder; _postfixCalculator = postfixCalculator; _equationParser = equationParser; }
public void EvaluateExpression_Should_ThrowArgumentNullException_When_PassedNull() { this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object); Assert.ThrowsException <ArgumentNullException>(() => this.postfixCalculator.EvaluateExpression(null)); }
public void EvaluateExpression_Should_ThrowInvalidMathematicalExpressionException_When_PassedEmptyCollection() { this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object); Assert.ThrowsException <InvalidMathematicalExpressionException>( () => this.postfixCalculator.EvaluateExpression(new List <string>())); }
public void EvaluateExpression_Should_ThrowInvalidMathematicaExpressionException_When_Passed_StringEnumerableWhitInvalidElement() { const string token = "Pesho"; var args = new List <string> { token }; this.operationTableMock.Setup(x => x.Contains(token)).Returns(false); this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object); Assert.ThrowsException <InvalidMathematicalExpressionException>(() => this.postfixCalculator .EvaluateExpression(args)); }
public void EvaluateExpression_Should_ThrowInvalidOperationException_When_OperationCannotBeExecuted() { const string operation = "+"; var args = new List <string> { operation }; var operationStub = new Mock <IOperation>(); this.operationTableMock.Setup(x => x.Contains(operation)).Returns(true); this.opeartionFacotryMock.Setup(x => x.CreateOperation(operation)).Returns(operationStub.Object); this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object); Assert.ThrowsException <InvalidOperationException>(() => this.postfixCalculator .EvaluateExpression(args)); }
public void EvaluateExpression_Should_InvokeCreateOperation_When_Passed_StringEnumerableContainigOperation() { const string operation = "+"; this.operationTableMock.Setup(x => x.Contains(operation)).Returns(true); this.opeartionFacotryMock.Setup(x => x.CreateOperation(operation)).Throws <NotImplementedException>(); this.postfixCalculator = new PostfixCalculator(this.operationTableMock.Object, this.opeartionFacotryMock.Object); try { this.postfixCalculator.EvaluateExpression(new List <string> { "2", "2", operation }); } catch (NotImplementedException) { } this.opeartionFacotryMock.Verify(x => x.CreateOperation(operation), Times.Once); }
public Expression(IExpressionParser parser, IInfixToPostfixConverter postfixConverter, IPostfixCalculator postfixCalculator) { this.parser = parser; this.postfixConverter = postfixConverter; this.postfixCalculator = postfixCalculator; }