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()); }
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); }
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); }