Пример #1
0
        public void DetermineMode_FindsFullModeMatchWithMultipleAttributes()
        {
            // Arrange
            var modeInfo = new[]
            {
                ModeAttributes.Create("mode0", new [] { "first-attr", "second-attr" })
            };
            var attributes = new TagHelperAttributeList
            {
                ["first-attr"]      = "value",
                ["second-attr"]     = "value",
                ["not-in-any-mode"] = "value"
            };
            var context = MakeTagHelperContext(attributes);

            // Act
            var modeMatch = AttributeMatcher.DetermineMode(context, modeInfo);

            // Assert
            Assert.Collection(modeMatch.FullMatches, match =>
            {
                Assert.Equal("mode0", match.Mode);
                Assert.Collection(match.PresentAttributes,
                                  attribute => Assert.Equal("first-attr", attribute),
                                  attribute => Assert.Equal("second-attr", attribute)
                                  );
            });
            Assert.Empty(modeMatch.PartialMatches);
            Assert.Empty(modeMatch.PartiallyMatchedAttributes);
        }
Пример #2
0
        public void DetermineMode_FindsFullAndPartialModeMatchWithMultipleAttribute()
        {
            // Arrange
            var modeInfo = new[]
            {
                ModeAttributes.Create("mode0", new [] { "second-attr" }),
                ModeAttributes.Create("mode1", new [] { "first-attr", "third-attr" }),
                ModeAttributes.Create("mode2", new [] { "first-attr", "second-attr", "third-attr" }),
                ModeAttributes.Create("mode3", new [] { "fourth-attr" })
            };
            var attributes = new Dictionary <string, object>
            {
                ["second-attr"]     = "value",
                ["third-attr"]      = "value",
                ["not-in-any-mode"] = "value"
            };
            var context = MakeTagHelperContext(attributes);

            // Act
            var modeMatch = AttributeMatcher.DetermineMode(context, modeInfo);

            // Assert
            Assert.Collection(modeMatch.FullMatches, match =>
            {
                Assert.Equal("mode0", match.Mode);
                Assert.Collection(match.PresentAttributes, attribute => Assert.Equal("second-attr", attribute));
            });
            Assert.Collection(modeMatch.PartialMatches,
                              match =>
            {
                Assert.Equal("mode1", match.Mode);
                Assert.Collection(match.PresentAttributes, attribute => Assert.Equal("third-attr", attribute));
                Assert.Collection(match.MissingAttributes, attribute => Assert.Equal("first-attr", attribute));
            },
                              match =>
            {
                Assert.Equal("mode2", match.Mode);
                Assert.Collection(match.PresentAttributes,
                                  attribute => Assert.Equal("second-attr", attribute),
                                  attribute => Assert.Equal("third-attr", attribute)
                                  );
                Assert.Collection(match.MissingAttributes, attribute => Assert.Equal("first-attr", attribute));
            });
            Assert.Collection(modeMatch.PartiallyMatchedAttributes, attribute => Assert.Equal("third-attr", attribute));
        }