Exemplo n.º 1
0
            public void DoesNotChangeUrlWhenParametersEmpty()
            {
                var uri = new Uri("https://example.com");

                var uriWithEmptyParameters = uri.ApplyParameters(new Dictionary<string, string>());
                var uriWithNullParameters = uri.ApplyParameters(null);

                Assert.Equal(uri, uriWithEmptyParameters);
                Assert.Equal(uri, uriWithNullParameters);
            }
Exemplo n.º 2
0
            public void DoesNotChangePassedInDictionary()
            {
                var uri = new Uri("https://api.github.com/repositories/1/milestones?state=closed&sort=due_date&direction=asc&page=2");

                var parameters = new Dictionary<string, string> { { "state", "open" }, { "sort", "other" } };

                uri.ApplyParameters(parameters);

                Assert.Equal(2, parameters.Count);
            }
Exemplo n.º 3
0
            public void ThrowsExceptionWhenNullValueProvided()
            {
                var uri = new Uri("https://example.com");

                var parameters = new Dictionary<string, string>
                {
                    {"foo", null },
                };

                Assert.Throws<ArgumentNullException>(() => uri.ApplyParameters(parameters));
            }
Exemplo n.º 4
0
            public void AppendsParametersAsQueryStringToRelativeUri()
            {
                var uri = new Uri("issues", UriKind.Relative);

                var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
                {
                    {"foo", "fooval"},
                    {"bar", "barval"}
                });

                Assert.Equal(new Uri("issues?foo=fooval&bar=barval", UriKind.Relative), uriWithParameters);
            }
Exemplo n.º 5
0
            public void AppendsParametersAsQueryString()
            {
                var uri = new Uri("https://example.com");

                var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
                {
                    {"foo", "foo val"},
                    {"bar", "barval"}
                });

                Assert.Equal(new Uri("https://example.com?foo=foo%20val&bar=barval"), uriWithParameters);
            }
Exemplo n.º 6
0
            public void OverwritesExistingParameters()
            {
                var uri = new Uri("https://example.com?crap=crapola");

                var uriWithParameters = uri.ApplyParameters(new Dictionary<string, string>
                {
                    {"foo", "fooval"},
                    {"bar", "barval"}
                });

                Assert.Equal(new Uri("https://example.com?foo=fooval&bar=barval"), uriWithParameters);
            }
Exemplo n.º 7
0
            public void CombinesExistingParametersWithNewParameters()
            {
                var uri = new Uri("https://api.github.com/repositories/1/milestones?state=closed&sort=due_date&direction=asc&page=2");

                var parameters = new Dictionary<string, string> { { "state", "open" }, { "sort", "other"} };

                var actual = uri.ApplyParameters(parameters);

                Assert.True(actual.Query.Contains("state=open"));
                Assert.True(actual.Query.Contains("sort=other"));
                Assert.True(actual.Query.Contains("direction=asc"));
                Assert.True(actual.Query.Contains("page=2"));
            }