Exemple #1
0
        public void ShouldNotThrowWhenRemovingNonExisting()
        {
            var headers = new FluentHttpHeaders();

            headers.Remove(HeaderTypes.Authorization);
            Assert.Null(headers.Authorization);
        }
Exemple #2
0
        public void SetNotExists_ShouldBeAdded()
        {
            var headers = new FluentHttpHeaders();

            headers.Accept = new[] { "json", "msgpack" };
            Assert.Equal("json,msgpack", headers.Accept);
        }
Exemple #3
0
        public void HeaderBuilderExtMethod_ShouldBeAvailable()
        {
            var headers = new FluentHttpHeaders()
                          .WithUserAgent("leoric");

            Assert.Equal("leoric", headers.UserAgent);
        }
Exemple #4
0
        public void GetExists_ShouldReturn()
        {
            var headers = new FluentHttpHeaders()
                          .Add(HeaderTypes.Accept, new[] { "json", "msgpack" });

            Assert.Equal("json,msgpack", headers.Accept);
        }
Exemple #5
0
        public void ShouldBeSerializable()
        {
            var headers = new FluentHttpHeaders()
                          .AddRange(new Dictionary <string, string[]>
            {
                { HeaderTypes.Authorization, new[] { "the-xx" } },
                { HeaderTypes.Accept, new[] { "json", "msgpack" } },
                { HeaderTypes.XForwardedHost, new[] { "sketch7.com" } },
            });

            var headersJson   = JsonConvert.SerializeObject(headers);
            var headersCopied = JsonConvert.DeserializeObject <FluentHttpHeaders>(headersJson);

            Assert.Collection(headersCopied, x =>
            {
                Assert.Equal(HeaderTypes.Authorization, x.Key);
                Assert.Equal("the-xx", x.Value[0]);
            },
                              x =>
            {
                Assert.Equal(HeaderTypes.Accept, x.Key);
                Assert.Equal("json,msgpack", string.Join(",", x.Value));
            },
                              x =>
            {
                Assert.Equal(HeaderTypes.XForwardedHost, x.Key);
                Assert.Equal("sketch7.com", x.Value[0]);
            });
            Assert.Equal("the-xx", headersCopied.Authorization);
        }
Exemple #6
0
        public void ShouldAddSingle()
        {
            var headers = new FluentHttpHeaders();

            headers.Add(HeaderTypes.Authorization, "the-xx");
            Assert.Equal("the-xx", headers.Authorization);
        }
Exemple #7
0
        public void ShouldAddEnumerable()
        {
            var headers = new FluentHttpHeaders();

            headers.Add(HeaderTypes.Accept, new[] { "json", "msgpack" });
            Assert.Equal("json,msgpack", headers.Accept);
        }
Exemple #8
0
        public void ShouldAddWithStringValues()
        {
            var headers = new FluentHttpHeaders();

            StringValues str = new[] { "the-xx", "supersecret" };

            headers.Add(HeaderTypes.Authorization, str);
            Assert.Equal("the-xx,supersecret", headers.Authorization);
        }
Exemple #9
0
        public void SetExists_ShouldBeUpdated()
        {
            var headers = new FluentHttpHeaders
            {
                Accept = new[] { "json", "msgpack" }
            };

            headers.Accept = "json";
            Assert.Equal("json", headers.Accept);
        }
Exemple #10
0
        public void ShouldRemoveExisting()
        {
            var headers = new FluentHttpHeaders
            {
                { HeaderTypes.Authorization, "the-xx" }
            };

            headers.Remove(HeaderTypes.Authorization);
            Assert.Null(headers.Authorization);
        }
Exemple #11
0
        public void GetExists_ShouldReturn()
        {
            var headers = new FluentHttpHeaders()
                          .AddRange(new Dictionary <string, StringValues>
            {
                { HeaderTypes.Accept, new[] { "json", "msgpack" } }
            });

            Assert.Equal("json,msgpack", headers.Accept);
        }
Exemple #12
0
        public void AddRangeSame_ShouldThrow()
        {
            var headers = new FluentHttpHeaders();

            headers.AddRange(new Dictionary <string, StringValues> {
                { HeaderTypes.Accept, new[] { "json", "msgpack" } }
            });
            Assert.Throws <ArgumentException>(() => headers.AddRange(new Dictionary <string, StringValues> {
                { HeaderTypes.Accept, "xml" }
            }));
        }
        public void ShouldHashSimple()
        {
            var headers = new FluentHttpHeaders
            {
                { HeaderTypes.Authorization, "the-xx" },
                { HeaderTypes.ContentType, "json" }
            };
            var hash = headers.ToHashString();

            Assert.Equal("Authorization=the-xx&Content-Type=json", hash);
        }
        public void ShouldHashWithEnumerable()
        {
            var headers = new FluentHttpHeaders
            {
                { HeaderTypes.Authorization, "the-xx" },
                { HeaderTypes.Accept, new[] { "json", "msgpack" } }
            };
            var hash = headers.ToHashString();

            Assert.Equal("Authorization=the-xx&Accept=json,msgpack", hash);
        }
Exemple #15
0
        public void ShouldHashSimple()
        {
            var headers = new FluentHttpHeaders()
                          .AddRange(new Dictionary <string, StringValues>
            {
                { HeaderTypes.Authorization, "the-xx" },
                { HeaderTypes.ContentType, "json" }
            });
            var hash = headers.ToHashString();

            Assert.Equal("Authorization=the-xx&Content-Type=json", hash);
        }
Exemple #16
0
        public void SetRangeSame_ShouldUpdateWithLatest()
        {
            var headers = new FluentHttpHeaders();

            headers.SetRange(new Dictionary <string, StringValues> {
                { HeaderTypes.Accept, new[] { "json", "msgpack" } }
            });
            headers.SetRange(new Dictionary <string, StringValues> {
                { HeaderTypes.Accept, "xml" }
            });
            Assert.Equal("xml", headers.Accept);
        }
Exemple #17
0
        public void ShouldFilterWithHashingFilter()
        {
            var headers = new FluentHttpHeaders()
                          .AddRange(new Dictionary <string, StringValues>
            {
                { HeaderTypes.Authorization, "the-xx" },
                { HeaderTypes.Accept, new[] { "json", "msgpack" } },
                { HeaderTypes.XForwardedHost, "sketch7.com" },
            }).WithOptions(opts => opts.WithHashingExclude(pair => pair.Key == HeaderTypes.Authorization));
            var hash = headers.ToHashString();

            Assert.Equal("Accept=json,msgpack&X-Forwarded-Host=sketch7.com", hash);
        }
Exemple #18
0
        public void ShouldInitializeFromHttpHeaders()
        {
            var httpHeaders = new HttpRequestMessage().Headers;

            httpHeaders.Add(HeaderTypes.Authorization, "the-xx");
            httpHeaders.Add(HeaderTypes.XForwardedFor, new[] { "192.168.1.1", "127.0.0.1" });

            var headers = new FluentHttpHeaders(httpHeaders);

            Assert.Equal("the-xx", headers.Authorization);
            Assert.Equal("192.168.1.1,127.0.0.1", headers.XForwardedFor);
            Assert.Equal(2, headers.Count);
        }
Exemple #19
0
        public void ShouldInitializeFromDictionaryEnumerableValue()
        {
            var headersMap = new Dictionary <string, IEnumerable <string> >
            {
                { HeaderTypes.Accept, new[] { "json", "msgpack" } },
                { HeaderTypes.XForwardedFor, new[] { "192.168.1.1", "127.0.0.1" } },
            };

            var headers = new FluentHttpHeaders(headersMap);

            Assert.Equal("json,msgpack", headers.Accept);
            Assert.Equal("192.168.1.1,127.0.0.1", headers.XForwardedFor);
            Assert.Equal(headersMap.Count, headers.Count);
        }
Exemple #20
0
        public void ShouldInitializeFromDictionary()
        {
            var headersMap = new Dictionary <string, string>
            {
                { HeaderTypes.Authorization, "the-xx" },
                { HeaderTypes.ContentType, "json" }
            };

            var headers = new FluentHttpHeaders(headersMap);

            Assert.Equal("the-xx", headers.Authorization);
            Assert.Equal("json", headers.ContentType);
            Assert.Equal(headersMap.Count, headers.Count);
        }
Exemple #21
0
        public void ToDictionary_ShouldBeConverted()
        {
            var headers = new FluentHttpHeaders
            {
                { HeaderTypes.Accept, new[] { "json", "msgpack" } }
            };

            var dictionary = headers.ToDictionary();

            var result = dictionary.GetValueOrDefault(HeaderTypes.Accept);

            Assert.Equal(2, result.Length);
            Assert.Equal("json", result[0]);
            Assert.Equal("msgpack", result[1]);
        }
Exemple #22
0
        public void IsSpecialHeaders_ForNonSpecialHeaders_Test(string headerName)
        {
            var actual = FluentHttpHeaders.IsSpecialHeader(headerName);

            Assert.Equal(-1, actual);
        }
Exemple #23
0
        public void IsSpecialHeaders_ForSpecialHeader_DiffernetCasingTest(string headerName)
        {
            var actual = FluentHttpHeaders.IsSpecialHeader(headerName);

            Assert.True(actual >= 0);
        }
Exemple #24
0
        public void GetNotExists_ShouldReturnNull()
        {
            var headers = new FluentHttpHeaders();

            Assert.Null(headers.UserAgent);
        }
Exemple #25
0
        public void IsSpecialHeaders_ForSpecialHeaders_Tests(string headerName)
        {
            var actual = FluentHttpHeaders.IsSpecialHeader(headerName);

            Assert.True(actual >= 0);
        }