Example #1
0
        private void InitializeFakedirectiveMethod(Parser parser)
        {
            ShimParser.AllInstances.directiveDirectiveOut = (Parser instance, out Directive directive) =>
            {
                var testInputItemsList = new List <TestInputItems>();
                var testInputItems     = new TestInputItems();
                var className          = "h1Class";
                var elementName        = "h1";
                var name = new StringBuilder();
                testInputItems.ClassName = name.Append(className)
                                           .Append(" ")
                                           .Append(elementName).ToString();
                testInputItems.PseudoName = "hover";
                testInputItemsList.Add(testInputItems);

                directive = new Directive
                {
                    Type = DirectiveType.Charset,
                    Name = "DIRECTIVE-TEST"
                };
                var mediums = new List <Medium>
                {
                    Medium.print
                };
                directive.Mediums      = mediums;
                directive.Directives   = null;
                directive.RuleSets     = GetRuleSets(testInputItemsList);
                directive.Declarations = GetDeclarations();;
                directive.Expression   = GetExpression();
            };
        }
        public void BuildCssTest_Has_Id_Only()
        {
            // Arrange
            var cssDocument = new CSSDocument();

            var testInputItemsList = new List <TestInputItems>();
            var testInputItems     = new TestInputItems();

            var listStyle = "Declaration: url('http://localhost')";
            var idName    = "h1";

            testInputItems.IdName = idName;
            testInputItemsList.Add(testInputItems);

            cssDocument.RuleSets   = GetRuleSets(testInputItemsList);
            cssDocument.Directives = null;

            InitializeFakeConstructors();

            // Act
            var result = _cssListBuilder.Invoke("BuildCssList", cssDocument) as CssItem;

            // Assert
            result.ShouldNotBeNull();
            result.HasClass.ShouldBeFalse();
            result.HasElement.ShouldBeFalse();
            result.HasId.ShouldBeTrue();
            result.ListId[0].Name.ShouldBe(idName);
            result.ListId[0].ListElement.Count.ShouldBe(0);
            result.ListId[0].ListIdStyle[0].Format.ShouldBe(listStyle);
            result.ListClass.Count.ShouldBe(0);
            result.ListElement.Count.ShouldBe(0);
        }
        private void SetDirectiveDeclarations_RuleSets_Directives(Directive directive)
        {
            var testInputItemsList = new List <TestInputItems>();
            var testInputItems     = new TestInputItems();
            var className          = "h1Class";
            var elementName        = "h1";
            var name = new StringBuilder();

            testInputItems.ClassName = name.Append(className)
                                       .Append(" ")
                                       .Append(elementName)
                                       .ToString();
            testInputItems.PseudoName = "hover";
            testInputItemsList.Add(testInputItems);

            directive.Declarations = GetDeclarations();
            directive.RuleSets     = GetRuleSets(testInputItemsList);
            directive.Directives   = GetDirectives(testInputItemsList);
        }
        public void BuildCssTest_Has_Class_And_Nested_Element()
        {
            // Arrange
            var cssDocument = new CSSDocument();

            var testInputItemsList = new List <TestInputItems>();
            var testInputItems     = new TestInputItems();

            var listStyle   = "Declaration: url('http://localhost')";
            var className   = "h1Class";
            var elementName = "h1";
            var name        = new StringBuilder();

            testInputItems.ClassName = name.Append(className)
                                       .Append(" ")
                                       .Append(elementName).ToString();
            testInputItemsList.Add(testInputItems);

            testInputItems           = new TestInputItems();
            name                     = new StringBuilder();
            testInputItems.ClassName = name.Append(className).Append(" ").Append(elementName).ToString();
            testInputItemsList.Add(testInputItems);

            cssDocument.RuleSets   = GetRuleSets(testInputItemsList);
            cssDocument.Directives = null;

            InitializeFakeConstructors();

            // Act
            var result = _cssListBuilder.Invoke("BuildCssList", cssDocument) as CssItem;

            // Assert
            result.ShouldNotBeNull();
            result.HasClass.ShouldBeTrue();
            result.HasElement.ShouldBeFalse();
            result.HasId.ShouldBeFalse();
            result.ListClass[0].Name.ShouldBe(className);
            result.ListClass[0].ListClassStyle.ShouldBeNull();
            result.ListClass[0].ListElement[0].ListElementStyle[0].Format.ShouldBe(listStyle);
            result.ListClass[0].ListElement[0].Name.ShouldBe(elementName);
            result.ListClass[0].ListElement[0].Parent.ShouldBeNull();
        }
        public void BuildCssTest_Has_Elements_With_Pseudo_Then_Class()
        {
            // Arrange
            var cssDocument = new CSSDocument();

            var testInputItemsList = new List <TestInputItems>();
            var testInputItems     = new TestInputItems();
            var listStyle          = "Declaration: url('http://localhost')";

            var elementName = "li";
            var pseudo      = "hover";
            var className   = "links";

            var syntax = new StringBuilder();

            testInputItems.ElementName = syntax.Append(elementName).Append(":").Append(pseudo).Append(".").Append(className).ToString();
            testInputItemsList.Add(testInputItems);

            cssDocument.RuleSets   = GetRuleSets(testInputItemsList);
            cssDocument.Directives = null;

            InitializeFakeConstructors();

            // Act
            var result = _cssListBuilder.Invoke("BuildCssList", cssDocument) as CssItem;

            // Assert
            result.ShouldNotBeNull();
            result.HasClass.ShouldBeTrue();
            result.HasElement.ShouldBeFalse();
            result.HasId.ShouldBeFalse();
            result.ListElement.Count.ShouldBe(0);
            result.ListId.Count.ShouldBe(0);
            result.ListClass[0].Name.ShouldBe(className);
            result.ListClass[0].ListClassStyle.ShouldBeNull();
            result.ListClass[0].ListElement[0].Parent.ShouldBeNull();
            result.ListClass[0].ListElement[0].Name.ShouldBe(elementName);
            result.ListClass[0].ListElement[0].ListElementStyle.ShouldBeNull();
            result.ListClass[0].ListElement[0].ListPsuedo[0].Name.ShouldBe(pseudo);
            result.ListClass[0].ListElement[0].ListPsuedo[0].ListStyle[0].Format.ShouldBe(listStyle);
        }
Example #6
0
        private void InitializeFakerulesetMethod(Parser parser)
        {
            ShimParser.AllInstances.rulesetRuleSetOut = (Parser instance, out RuleSet ruleSet) =>
            {
                var testInputItemsList = new List <TestInputItems>();
                var testInputItems     = new TestInputItems();
                var className          = "h1Class";
                var elementName        = "h1";
                var name = new StringBuilder();
                testInputItems.ClassName = name.Append(className)
                                           .Append(" ")
                                           .Append(elementName)
                                           .ToString();
                testInputItems.PseudoName = "hover";
                testInputItemsList.Add(testInputItems);

                ruleSet = new RuleSet
                {
                    Selectors    = GetSelectors(testInputItemsList),
                    Declarations = GetDeclarations()
                };
            };
        }
Example #7
0
        public void NodeHasAncestors_Test()
        {
            // Arrange
            var document = new HtmlDocument();

            document.DocumentNode.Name = "document";
            var node = new HtmlNode(HtmlNodeType.Element, document, 1);

            node.Name = "ul";

            var cssDocument        = new CSSDocument();
            var testInputItemsList = new List <TestInputItems>();
            var testInputItems     = new TestInputItems();

            var className   = "h1Class";
            var elementName = "h1";
            var name        = new StringBuilder();

            testInputItems.ClassName = name.Append(className)
                                       .Append(" ")
                                       .Append(elementName)
                                       .ToString();
            testInputItems.PseudoName = "hover";
            testInputItemsList.Add(testInputItems);

            cssDocument.RuleSets   = GetRuleSets(testInputItemsList);
            cssDocument.Directives = null; // Option of GetDirectives();

            var methodCaller = new PrivateObject(new CssConvert_2_0.Convert());

            _parameters = new object[] { node, cssDocument };

            // Act
            var result = methodCaller.Invoke("NodeHasAncestors", _parameters) as bool?;

            // Assert
            Assert.IsFalse(result);

            // Arrange

            node = new HtmlNode(HtmlNodeType.Element, document, 1)
            {
                Name = "ul"
            };
            var node_ancestor = new HtmlNode(HtmlNodeType.Element, document, 1)
            {
                Name = "div"
            };

            node_ancestor.AppendChild(node);

            _parameters = new object[] { node, cssDocument };

            // Act
            result = methodCaller.Invoke("NodeHasAncestors", _parameters) as bool?;

            // Assert
            Assert.IsFalse(result);

            // Arrange
            node          = new HtmlNode(HtmlNodeType.Element, document, 1);
            node.Name     = "ul";
            node_ancestor = new HtmlNode(HtmlNodeType.Element, document, 1)
            {
                Name = "div"
            };
            node_ancestor.AppendChild(node);

            var ancestor = new HtmlNode(HtmlNodeType.Element, document, 1)
            {
                Name = "body"
            };

            ancestor.AppendChild(node_ancestor);

            _parameters = new object[] { node, cssDocument };

            // Act
            result = methodCaller.Invoke("NodeHasAncestors", _parameters) as bool?;

            // Assert
            Assert.IsFalse(result);
        }