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 TestCreateChildModel() { // Arrange var sut = new TalesModel(Mock.Of<IEvaluatorSelector>()); // Act var child = sut.CreateChildModel(); // Assert Assert.NotNull(child, "Result nullability"); Assert.AreSame(sut, child.Parent, "Parent model"); }
public void Setup() { _autofixture = new Fixture(); new TalesModelCustomisation().Customize(_autofixture); _pathEvaluator = new Mock<IExpressionEvaluator>(); var registry = new Mock<IEvaluatorSelector>(); _autofixture.Inject(registry.Object); _model = _autofixture.Create<TalesModel>(); registry.Setup(x => x.GetEvaluator<PathExpressionEvaluator>()).Returns(_pathEvaluator.Object); _sut = new StringExpressionEvaluator(registry.Object); }
/// <summary> /// Attempts to get a root object, from which to begin traversal of the path. /// </summary> /// <returns><c>true</c>, if the root object was retrieved, <c>false</c> otherwise.</returns> /// <param name="walker">A TALES path walker.</param> /// <param name="element">A ZPT element.</param> /// <param name="model">The TALES model.</param> /// <param name="result">Exposes the result of this operation.</param> protected virtual bool TryGetTraversalRoot(PathWalker walker, ZptElement element, TalesModel model, out object result) { bool output; if(walker.NextPart() && model.TryGetLocalRootObject(walker.CurrentPart.Value, element, out result)) { output = true; } else { output = false; result = null; } return output; }
public void TestEvaluate() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var evaluator = new Mock<IExpressionEvaluator>(); var sut = new TalesModel(registry.Object); var expressionResult = _autofixture.Create<ExpressionResult>(); registry .Setup(x => x.GetEvaluator(It.IsAny<Expression>())) .Returns(evaluator.Object); evaluator .Setup(x => x.Evaluate(It.IsAny<Expression>(), It.IsAny<RenderingContext>(), sut)) .Returns(expressionResult); // Act var result = sut.Evaluate(_autofixture.Create<Expression>(), Mock.Of<RenderingContext>()); // Assert Assert.AreSame(expressionResult, 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"); }
/// <summary> /// Create a context instance. /// </summary> public virtual IRenderingContext Create(IZptElement element, IRenderingSettings options, object model) { if(element == null) { throw new ArgumentNullException(nameof(element)); } if(options == null) { throw new ArgumentNullException(nameof(options)); } NamedObjectWrapper metalKeywordOptions = new NamedObjectWrapper(MetalKeywordOptions), talKeywordOptions = new NamedObjectWrapper(TalKeywordOptions); IModel metalModel = new TalesModel(this.EvaluatorRegistry, metalKeywordOptions, modelObject: model), talModel = new TalesModel(this.EvaluatorRegistry, talKeywordOptions, modelObject: model); PopulateMetalModel(metalModel); PopulateTalModel(talModel); return new RenderingContext(metalModel, talModel, element, options, this.RootDocumentPath); }
public void TestTryGetRootObject_Repeat() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var sut = new TalesModel(registry.Object); // Act object output; var result = sut.TryGetRootObject("repeat", _context, out output); // Assert Assert.IsTrue(result, "Overall success"); Assert.NotNull(output, "Output nullability"); Assert.IsInstanceOf<RepetitionMetadataCollectionWrapper>(output, "Expected output type"); }
public void TestTryGetRootObject_Nothing() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var sut = new TalesModel(registry.Object); // Act object output; var result = sut.TryGetRootObject("nothing", _context, out output); // Assert Assert.IsTrue(result, "Overall success"); Assert.IsNull(output, "Output nullability"); }
public void TestTryGetRootObject_Default() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var sut = new TalesModel(registry.Object); // Act object output; var result = sut.TryGetRootObject("default", _context, out output); // Assert Assert.IsTrue(result, "Overall success"); Assert.NotNull(output, "Output nullability"); Assert.AreSame(ZptConstants.CancellationToken, output, "Expected output"); }
public void TestTryGetRootObject_Contexts() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var sut = new TalesModel(registry.Object); // Act object output; var result = sut.TryGetRootObject("CONTEXTS", _context, out output); // Assert Assert.IsTrue(result, "Overall success"); Assert.NotNull(output, "Output nullability"); Assert.IsInstanceOf<BuiltinContextsContainer>(output, "Expected output type"); }
public void TestTryGetRootObject_Attrs() { // Arrange var registry = new Mock<IEvaluatorSelector>(); var sut = new TalesModel(registry.Object); // Act object output; var result = sut.TryGetRootObject("attrs", _context, out output); // Assert Assert.IsTrue(result, "Overall success"); Assert.NotNull(output, "Output nullability"); Assert.IsInstanceOf<OriginalAttributeValuesCollection>(output, "Expected output type"); }
/// <summary> /// Creates and returns a child <see cref="TalesModel"/> instance. /// </summary> /// <returns>The child model.</returns> public override IModel CreateChildModel() { var output = new TalesModel(this, this.Root, EvaluatorRegistry, modelObject: this.ModelObject); return output; }