public void TestEvaluateCancel() { // Arrange var aFixture = new Fixture(); var expressionContent = aFixture.Create<string>(); var expression = new Expression("not", expressionContent); var evaluator = new Mock<IExpressionEvaluator>(); var registry = Mock.Of<IEvaluatorSelector>(x => x.GetEvaluator(It.IsAny<Expression>()) == evaluator.Object); evaluator .Setup(x => x.Evaluate(It.Is<Expression>(e => e.ToString() == expressionContent), It.IsAny<RenderingContext>(), It.IsAny<TalesModel>())) .Returns(new ExpressionResult(ZptConstants.CancellationToken)); var model = new TalesModel(registry); var sut = new NotExpressionEvaluator(); // Act var result = sut.Evaluate(expression, Mock.Of<RenderingContext>(), model); // Assert Assert.NotNull(result, "Result nullability"); Assert.AreEqual(true, result.Value, "Correct result"); }
public void TestEvaluateTalesConvertible(bool conversionValue, bool expectedResult) { // Arrange var aFixture = new Fixture(); var expressionContent = aFixture.Create<string>(); var expression = new Expression("not", expressionContent); var evaluator = new Mock<IExpressionEvaluator>(); var registry = Mock.Of<IEvaluatorSelector>(x => x.GetEvaluator(It.IsAny<Expression>()) == evaluator.Object); var convertible = Mock.Of<ITalesConvertible>(x => x.AsBoolean() == conversionValue); evaluator .Setup(x => x.Evaluate(It.Is<Expression>(e => e.ToString() == expressionContent), It.IsAny<RenderingContext>(), It.IsAny<TalesModel>())) .Returns(new ExpressionResult(convertible)); var model = new TalesModel(registry); var sut = new NotExpressionEvaluator(); // Act var result = sut.Evaluate(expression, Mock.Of<RenderingContext>(), model); // Assert Assert.NotNull(result, "Result nullability"); Assert.AreEqual(expectedResult, result.Value, "Correct result"); }