public void GetExtendedMacro_returns_null_for_evaluation_failure() { // Arrange var attribute = Mock.Of<global::CSF.Zpt.Rendering.ZptAttribute>(); ZptElement originalElement = Mock.Of<ZptElement>(x => x.GetAttribute(ZptConstants.Metal.Namespace, ZptConstants.Metal.ExtendMacroAttribute) == attribute); _fixture.Inject(originalElement); var model = _fixture.Create<DummyModel>(); _fixture.Inject(model); var context = _fixture.Create<RenderingContext>(); Mock.Get(model) .Setup(x => x.Evaluate(It.IsAny<string>(), context)) .Throws<IntendedTestingException>(); var sut = new MacroFinder(); // Act var result = sut.GetExtendedMacro(context); // Assert Assert.IsNull(result); }
public void GetExtendedMacro_returns_correct_referenced_element() { // Arrange var attribute = Mock.Of<global::CSF.Zpt.Rendering.ZptAttribute>(); var referencedElement = Mock.Of<ZptElement>(x => x.Clone() == x); var model = _fixture.Create<DummyModel>(); _fixture.Inject(model); var context = _fixture.Create<RenderingContext>(); Mock.Get(context) .Setup(x => x.GetAttribute(ZptConstants.Metal.Namespace, ZptConstants.Metal.ExtendMacroAttribute)) .Returns(attribute); Mock.Get(model) .Setup(x => x.Evaluate(It.IsAny<string>(), context)) .Returns(new ExpressionResult(referencedElement)); var sut = new MacroFinder(); // Act var result = sut.GetExtendedMacro(context); // Assert Assert.AreSame(referencedElement, result); }
public void GetExtendedMacro_returns_null_when_attribute_not_present() { // Arrange var mockOriginalElement = new Mock<ZptElement>(); mockOriginalElement .Setup(x => x.GetAttribute(ZptConstants.Metal.Namespace, ZptConstants.Metal.ExtendMacroAttribute)) .Returns((global::CSF.Zpt.Rendering.ZptAttribute) null); ZptElement originalElement = mockOriginalElement.Object; _fixture.Inject(originalElement); var context = _fixture.Create<RenderingContext>(); var sut = new MacroFinder(); // Act var result = sut.GetExtendedMacro(context); // Assert Assert.IsNull(result); }