示例#1
0
 private static List <IdempotencyControlRule> PreprocessSettings(IdempotencySettings idempotencySettings)
 {
     return(idempotencySettings
            .Rules
            .Select(
                r => new IdempotencyControlRule
     {
         Method = r.Method,
         IsIdempotent = r.IsIdempotent,
         PathPattern = r.PathPattern == null ? null : new Wildcard(r.PathPattern.TrimStart('/'))
     })
            .Append(DefaultIdempotencyRule)
            .ToList());
 }
示例#2
0
        public void Should_trim_start_slash()
        {
            var settings = new IdempotencySettings
            {
                Rules = new List <IdempotencyRuleSetting>
                {
                    new IdempotencyRuleSetting
                    {
                        Method       = "Post",
                        PathPattern  = "/test",
                        IsIdempotent = false
                    }
                }
            };

            singsProvider.GetAsync().Returns(settings);

            var cached = cache.GetAsync().GetAwaiter().GetResult();

            cached[0].PathPattern.IsMatch("/test").Should().Be(false);
            cached[0].PathPattern.IsMatch("test").Should().Be(true);
        }
示例#3
0
        public void Should_always_add_the_last_rule()
        {
            var settings = new IdempotencySettings
            {
                Rules = new List <IdempotencyRuleSetting>
                {
                    new IdempotencyRuleSetting
                    {
                        Method       = "Post",
                        PathPattern  = "/test",
                        IsIdempotent = false
                    }
                }
            };

            singsProvider.GetAsync().Returns(settings);

            var cached = cache.GetAsync().GetAwaiter().GetResult();

            cached.Count.Should().Be(2);

            cached.Last().Method.Should().Be("*");
            cached.Last().IsIdempotent.Should().Be(true);
        }