Ejemplo n.º 1
0
        private static void EnsureDeclarationNode(DeclarationNode declarationNode, RulesetNode ruleSetNode, MediaNode mediaQueryNode, StyleSheetNode actualCss)
        {
            var rules = actualCss.StyleSheetRules.ToArray();
            var expectedMediaQuery = string.Empty;

            if (mediaQueryNode != null)
            {
                expectedMediaQuery = mediaQueryNode.PrintSelector();
                rules = rules.OfType <MediaNode>().Where(r => r.PrintSelector().Equals(expectedMediaQuery)).SelectMany(mq => mq.Rulesets).ToArray();
            }

            var expectedRule = ruleSetNode.PrintSelector();
            var declarations = rules
                               .OfType <RulesetNode>()
                               .Where(rsn => rsn.PrintSelector().Equals(expectedRule))
                               .SelectMany(r => r.Declarations).ToArray();

            var expectedproperty  = declarationNode.Property;
            var declarationValues = declarations.Where(d => d.Property.Equals(expectedproperty)).ToArray();

            var expectedValue = declarationNode.ExprNode.TermNode.MinifyPrint();

            if (!declarationValues.Any(d => d.ExprNode.TermNode.MinifyPrint().Equals(expectedValue)))
            {
                Assert.Fail("Could not find [{0}] --> [{1}] --> {2}: {3}; ".InvariantFormat(expectedMediaQuery, expectedRule, expectedproperty, expectedValue));
            }
        }
        /// <summary>The optimize media query.</summary>
        /// <param name="mediaNode">The media node.</param>
        /// <param name="ruleSetMediaPageDictionary">The rule set media page dictionary.</param>
        private void OptimizeMediaQuery(MediaNode mediaNode, OrderedDictionary ruleSetMediaPageDictionary)
        {
            var mediaNodeHashKey = mediaNode.PrintSelector();
            var pageNodes        = mediaNode.PageNodes.ToList();
            var rulesetNodes     = mediaNode.Rulesets.ToList();

            if (ruleSetMediaPageDictionary.Contains(mediaNodeHashKey))
            {
                var previousNode = ruleSetMediaPageDictionary[mediaNodeHashKey] as MediaNode;
                if (previousNode != null)
                {
                    pageNodes    = previousNode.PageNodes.Concat(pageNodes).ToList();
                    rulesetNodes = previousNode.Rulesets.Concat(rulesetNodes).ToList();
                }

                ruleSetMediaPageDictionary.Remove(mediaNodeHashKey);
            }

            ruleSetMediaPageDictionary.Add(
                mediaNodeHashKey,
                new MediaNode(
                    mediaNode.MediaQueries,
                    this.GetMergedNodeDictionary(rulesetNodes).Values.Cast <RulesetNode>().ToList().AsSafeReadOnly(),
                    pageNodes.ToSafeReadOnlyCollection()));
        }