Exemplo n.º 1
0
 /// <summary>
 /// Instantiates a new <see cref="TagHelperContext"/>.
 /// </summary>
 /// <param name="allAttributes">Every attribute associated with the current HTML element.</param>
 /// <param name="items">Collection of items used to communicate with other <see cref="ITagHelper"/>s.</param>
 /// <param name="uniqueId">The unique identifier for the source element this <see cref="TagHelperContext" />
 /// applies to.</param>
 /// <param name="getChildContentAsync">A delegate used to execute and retrieve the rendered child content
 /// asynchronously.</param>
 public TagHelperContext(
     [NotNull] IEnumerable <IReadOnlyTagHelperAttribute> allAttributes,
     [NotNull] IDictionary <object, object> items,
     [NotNull] string uniqueId,
     [NotNull] Func <Task <TagHelperContent> > getChildContentAsync)
 {
     AllAttributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(
         allAttributes.Select(attribute => new TagHelperAttribute(attribute.Name, attribute.Value)));
     Items    = items;
     UniqueId = uniqueId;
     _getChildContentAsync = getChildContentAsync;
 }
Exemplo n.º 2
0
        public void IntIndexer_ThrowsIfInvalidIndex(int index)
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(
                new[]
            {
                new TagHelperAttribute("a", "av"),
                new TagHelperAttribute("b", "bv")
            });

            // Act & Assert
            var exception = Assert.Throws <ArgumentOutOfRangeException>("index", () => attributes[index]);
        }
Exemplo n.º 3
0
        public void IndexOf_ReturnsExpectedResult(
            IEnumerable <IReadOnlyTagHelperAttribute> initialAttributes,
            IReadOnlyTagHelperAttribute attributeToLookup,
            int expected)
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(initialAttributes);

            // Act
            var index = attributes.IndexOf(attributeToLookup);

            // Assert
            Assert.Equal(expected, index);
        }
Exemplo n.º 4
0
        public void IntIndexer_ReturnsExpectedAttribute(
            IEnumerable <IReadOnlyTagHelperAttribute> initialAttributes,
            int indexToLookup,
            IReadOnlyTagHelperAttribute expectedAttribute)
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(initialAttributes);

            // Act
            var attribute = attributes[indexToLookup];

            // Assert
            Assert.Equal(expectedAttribute, attribute, CaseSensitiveTagHelperAttributeComparer.Default);
        }
Exemplo n.º 5
0
        public void ContainsName_ReturnsExpectedResult(
            IEnumerable <IReadOnlyTagHelperAttribute> initialAttributes,
            string nameToLookup,
            bool expected)
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(initialAttributes);

            // Act
            var contains = attributes.ContainsName(nameToLookup);

            // Assert
            Assert.Equal(expected, contains);
        }
Exemplo n.º 6
0
        public void TryGetAttributes_ReturnsExpectedValueAndAttribute(
            IEnumerable <IReadOnlyTagHelperAttribute> initialAttributes,
            string nameToLookup,
            IEnumerable <IReadOnlyTagHelperAttribute> expectedAttributes,
            bool expectedResult)
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(initialAttributes);
            IEnumerable <IReadOnlyTagHelperAttribute> resolvedAttributes;

            // Act
            var result = attributes.TryGetAttributes(nameToLookup, out resolvedAttributes);

            // Assert
            Assert.Equal(expectedResult, result);
            Assert.Equal(expectedAttributes, resolvedAttributes, CaseSensitiveTagHelperAttributeComparer.Default);
        }
Exemplo n.º 7
0
        public void Count_ReturnsNumberOfAttributes()
        {
            // Arrange
            var attributes = new ReadOnlyTagHelperAttributeList <IReadOnlyTagHelperAttribute>(
                new[]
            {
                new TagHelperAttribute(),
                new TagHelperAttribute(),
                new TagHelperAttribute()
            });

            // Act
            var count = attributes.Count;

            // Assert
            Assert.Equal(3, count);
        }