public static CssSelectorConstraint FindByCss(DomContainer domContainer, string cssSelector)
        {
            string cssMarker = "findByCssMarker" + ++_cssMarkerIndex;

            var constraint = new CssSelectorConstraint(new ScriptLoader(), domContainer);
            constraint.Initialize(cssSelector, cssMarker);
            return constraint;
        }
        public static CssSelectorConstraint FindByCss(DomContainer domContainer, string cssSelector)
        {
            string cssMarker = "findByCssMarker" + ++_cssMarkerIndex;

            var constraint = new CssSelectorConstraint(new ScriptLoader(), domContainer);

            constraint.Initialize(cssSelector, cssMarker);
            return(constraint);
        }
        public bool doesRegex_usedByClassConstraint_match(string markerClass, string classValue)
        {
            var sut = new CssSelectorConstraint(null,null);

            sut.Initialize(null, markerClass);

            AttributeConstraint constraint = sut.ActualConstraint as AttributeConstraint;
            return constraint.Comparer.Compare(classValue);
        }
        public void TestInitialize_createsAClassConstraint()
        {
            string markerClass = Some.String();

            var sut = new CssSelectorConstraint(null,null);

            sut.Initialize(null, markerClass);

            AttributeConstraint constraint = sut.ActualConstraint as AttributeConstraint;
            Assert.That(constraint.AttributeName.Equals("class"));
        }
        public void TestEnterMatch_ensuresJQueryIsAvailable()
        {
            string jQueryInstallScript = Some.String();

            Mock<IScriptLoader> scriptLoader = new Mock<IScriptLoader>();
            Mock<WatiN.Core.DomContainer> domContainer = new Mock<DomContainer>();
            
            scriptLoader.Setup(s => s.GetJQueryInstallScript()).Returns(jQueryInstallScript);
            domContainer.Setup(s => s.Eval(jQueryInstallScript)).Verifiable();

            var sut = new CssSelectorConstraint(scriptLoader.Object, domContainer.Object);

            sut.EnterMatch();

            domContainer.Verify();
        }
        public static Element ElementByCss(this DomContainer domContainer, string cssSelector)
        {
            CssSelectorConstraint constraint = FindByCss(domContainer, cssSelector);

            return(domContainer.Element(constraint));
        }
        public void TestEnterMatch_usesCssSelectorToAddCssClass()
        {
            string cssSelector = Some.String();
            string markerClass = Some.String();

            string markingScript = Some.String();

            Mock<IScriptLoader> scriptLoader = new Mock<IScriptLoader>();
            Mock<WatiN.Core.DomContainer> domContainer = new Mock<DomContainer>();

            scriptLoader.Setup(s => s.GetCssMarkingScript(cssSelector, markerClass)).Returns(markingScript);
            domContainer.Setup(d => d.Eval(markingScript)).Verifiable();

            var sut = new CssSelectorConstraint(scriptLoader.Object, domContainer.Object);

            sut.Initialize(cssSelector, markerClass);

            sut.EnterMatch();

            domContainer.Verify(); 
        }
        public void TestCanBeCreated()
        {
            var sut = new CssSelectorConstraint(null,null);

            Assert.IsInstanceOf(typeof(WatiN.Core.Constraints.Constraint), sut);
        }
        public void TestWriteDescriptionTo_uninitialized()
        {
            Mock<System.IO.TextWriter> textWriter = new Mock<TextWriter>();
            textWriter.Setup(tw => tw.Write(It.IsAny<string>())).Callback(
                delegate(string writtenText)
                {
                    Assert.That(writtenText.Contains("CssSelectorConstraint"));
                }
                ).Verifiable();

            var sut = new CssSelectorConstraint(null, null);

            sut.WriteDescriptionTo(textWriter.Object);

            textWriter.Verify();
        }