public void SelectMultipleEntries_BothMatch_OrderedByTemplate()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry1 = CreateEntry(new { controller = "Store", action = "Buy" });

            entry1.TemplateText = "a";
            entries.Add(entry1);

            var entry2 = CreateEntry(new { controller = "Store", action = "Buy" });

            entry2.TemplateText = "b";
            entries.Add(entry2);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(new { controller = "Store", action = "Buy" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Equal(entries, matches);
        }
        public void SelectMultipleEntries_BothMatch_CriteriaSubset()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry1 = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry1);

            var entry2 = CreateEntry(new { controller = "Store" });

            entry2.Order = 1;
            entries.Add(entry2);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(
                values: new { controller = "Store" },
                ambientValues: new { controller = "Store", action = "Buy" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Equal(entries, matches);
        }
        public void SelectMultipleEntries_OneDoesntMatch()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry1 = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry1);

            var entry2 = CreateEntry(new { controller = "Store", action = "Cart" });

            entries.Add(entry2);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(
                values: new { controller = "Store" },
                ambientValues: new { controller = "Store", action = "Buy" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Same(entry1, Assert.Single(matches));
        }
        public void SelectMultipleEntries_BothMatch_OrderedByPrecedence()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry1 = CreateEntry(new { controller = "Store", action = "Buy" });

            entry1.Precedence = 0;
            entries.Add(entry1);

            var entry2 = CreateEntry(new { controller = "Store", action = "Buy" });

            entry2.Precedence = 1;
            entries.Add(entry2);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(new { controller = "Store", action = "Buy" });

            // Act
            var matches = tree.GetMatches(context).Select(m => m.Entry).ToList();

            // Assert
            Assert.Equal(entries, matches);
        }
        public void SelectSingleEntry_MultipleCriteria_AmbientValues()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(values: null, ambientValues: new { controller = "Store", action = "Buy" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Same(entry, Assert.Single(matches));
        }
        public void SelectSingleEntry_NoCriteria()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry = CreateEntry(new { });

            entries.Add(entry);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(new { });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Same(entry, Assert.Single(matches));
        }
        public void SelectSingleEntry_MultipleCriteria_NoMatch()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(new { controller = "Store", action = "AddToCart" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Empty(matches);
        }
        public void SelectMultipleEntries_BothMatch_NonOverlappingCriteria()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry1 = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry1);

            var entry2 = CreateEntry(new { slug = "1234" });

            entry2.Order = 1;
            entries.Add(entry2);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(new { controller = "Store", action = "Buy", slug = "1234" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            Assert.Equal(entries, matches);
        }
        public void SelectSingleEntry_MultipleCriteria_Replaced()
        {
            // Arrange
            var entries = new List <AttributeRouteLinkGenerationEntry>();

            var entry = CreateEntry(new { controller = "Store", action = "Buy" });

            entries.Add(entry);

            var tree = new LinkGenerationDecisionTree(entries);

            var context = CreateContext(
                values: new { action = "Buy" },
                ambientValues: new { controller = "Store", action = "Cart" });

            // Act
            var matches = tree.GetMatches(context);

            // Assert
            var match = Assert.Single(matches);

            Assert.Same(entry, match.Entry);
            Assert.False(match.IsFallbackMatch);
        }