public XPathBuilder_GetAttributePart_Tests() { _xPathValidator = new XPathValidator(); _xPathValidatorMock = Substitute.For <IXPathValidator>(); _xPathValidatorMock.IsReservedFunctionName(Arg.Any <string>()) .Returns(x => _xPathValidator.IsReservedFunctionName(x.Arg <string>())); _xPathValidatorMock.When(x => x.ValidateQName(Arg.Any <string>(), Arg.Any <string>())) .Do(x => _xPathValidator.ValidateQName(x.ArgAt <string>(0), x.ArgAt <string>(1))); _xPathValidatorMock.When(x => x.ValidateNCName(Arg.Any <string>(), Arg.Any <string>())) .Do(x => _xPathValidator.ValidateNCName(x.ArgAt <string>(0), x.ArgAt <string>(1))); _cssValidatorMock = Substitute.For <ICssValidator>(); _builder = new XPathBuilder(_xPathValidatorMock, _cssValidatorMock); }
public void when_creating_xpath_tag_with_invalid_tag_name() { _xPathValidator.When(x => x.ValidateQName(" invalid:Tag", "Tag Name")) .Do(x => throw new ArgumentException("Tag Name contains invalid character “ ” at position 0.")); var exception = Should.Throw <ArgumentException>(() => _builder.GetTagNamePart(" invalid:Tag")); exception.ShouldNotBeNull(); exception.Message.ShouldBe("Tag Name contains invalid character “ ” at position 0."); _xPathValidator.DidNotReceiveWithAnyArgs().IsReservedFunctionName(Arg.Any <string>()); _xPathValidator.Received(1).ValidateQName(" invalid:Tag", "Tag Name"); _xPathValidator.DidNotReceiveWithAnyArgs().ValidateNCName(Arg.Any <string>(), Arg.Any <string>()); _cssValidator.DidNotReceiveWithAnyArgs().ValidateClassName(Arg.Any <string>()); }
public void when_creating_xpath_attribute_with_invalid_attibute_name(string attributeValue) { _xPathValidatorMock.When(x => x.ValidateQName("invalid-tag", Arg.Any <string>())) .Do(x => throw new ArgumentException("Exception message.")); var exception = Should.Throw <ArgumentException>(() => _builder.GetAttributePart("invalid-tag", attributeValue)); exception.ShouldNotBeNull(); exception.Message.ShouldBe("Exception message."); _cssValidatorMock.DidNotReceiveWithAnyArgs().ValidateClassName(Arg.Any <string>()); _xPathValidatorMock.DidNotReceiveWithAnyArgs().IsReservedFunctionName(Arg.Any <string>()); _xPathValidatorMock.Received(1).ValidateQName("invalid-tag", "Attribute Name"); _xPathValidatorMock.DidNotReceiveWithAnyArgs().ValidateNCName(Arg.Any <string>(), Arg.Any <string>()); }