Esempio n. 1
0
        public void MethodsShouldBeCancellableDefault()
        {
            var fixture = new RequestBuilderImplementation(typeof(ICancellableMethods));
            var factory = fixture.RunRequest("GetWithCancellation");
            var output  = factory(new object[0]);

            var uri = new Uri(new Uri("http://api"), output.RequestMessage.RequestUri);

            Assert.Equal("/foo", uri.PathAndQuery);
            Assert.False(output.CancellationToken.IsCancellationRequested);
        }
Esempio n. 2
0
        public void ICanPostAValueTypeIfIWantYoureNotTheBossOfMe()
        {
            var fixture  = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory  = fixture.RunRequest("PostAValueType", "true");
            var guid     = Guid.NewGuid();
            var expected = string.Format("\"{0}\"", guid);
            var output   = factory(new object[] { 7, guid });


            Assert.Equal(expected, output.SendContent);
        }
Esempio n. 3
0
        public void MethodsShouldBeCancellableWithTokenDoesCancel()
        {
            var fixture = new RequestBuilderImplementation(typeof(ICancellableMethods));
            var factory = fixture.RunRequest("GetWithCancellation");

            var cts = new CancellationTokenSource();

            cts.Cancel();

            var output = factory(new object[] { cts.Token });

            Assert.True(output.CancellationToken.IsCancellationRequested);
        }
Esempio n. 4
0
        public void FormFieldGetsAliased()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostSomeAliasedUrlEncodedStuff");
            var output  = factory(
                new object[] {
                6,
                new SomeRequestData {
                    ReadablePropertyName = 99
                }
            });



            Assert.Equal("rpn=99", output.SendContent);
        }
Esempio n. 5
0
        public void BodyContentGetsUrlEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostSomeUrlEncodedStuff");
            var output  = factory(
                new object[] {
                6,
                new {
                    Foo = "Something",
                    Bar = 100,
                    Baz = default(string)
                }
            });

            Assert.Equal("Foo=Something&Bar=100&Baz=", output.SendContent);
        }
Esempio n. 6
0
        public void BodyContentGetsUrlEncoded()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostSomeUrlEncodedStuff");
            var output  = factory(
                new object[] {
                6,
                new {
                    Foo = "Something",
                    Bar = 100,
                    Baz = ""     // explicitly use blank to preserve value that would be stripped if null
                }
            });

            Assert.Equal("Foo=Something&Bar=100&Baz=", output.SendContent);
        }
Esempio n. 7
0
        public void ICanPostAValueTypeIfIWantYoureNotTheBossOfMe()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostAValueType", "true");
            var guid = Guid.NewGuid();
            var expected = string.Format("\"{0}\"", guid);
            var output = factory(new object[] { 7, guid });


            Assert.AreEqual(expected, output.SendContent);
        }
Esempio n. 8
0
        public async Task FormFieldGetsAliased()
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostSomeAliasedUrlEncodedStuff");
            var output = factory(
                new object[] {
                    6, 
                    new SomeRequestData {
                        ReadablePropertyName = 99
                    }
                });



            Assert.AreEqual("rpn=99", output.SendContent);
        }
Esempio n. 9
0
        public void BodyContentGetsUrlEncoded() 
        {
            var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
            var factory = fixture.RunRequest("PostSomeUrlEncodedStuff");
            var output = factory(
                new object[] {
                    6, 
                    new {
                        Foo = "Something", 
                        Bar = 100, 
                        Baz = default(string)
                    }
                });

            Assert.AreEqual("Foo=Something&Bar=100&Baz=", output.SendContent);
        }
Esempio n. 10
0
        public void MethodsShouldBeCancellableWithTokenDoesCancel()
        {
            var fixture = new RequestBuilderImplementation(typeof(ICancellableMethods));
            var factory = fixture.RunRequest("GetWithCancellation");

            var cts = new CancellationTokenSource();
            cts.Cancel();

            var output = factory(new object[] { cts.Token });
            Assert.IsTrue(output.CancellationToken.IsCancellationRequested);
        }
Esempio n. 11
0
        public void MethodsShouldBeCancellableWithToken()
        {
            var fixture = new RequestBuilderImplementation(typeof(ICancellableMethods));
            var factory = fixture.RunRequest("GetWithCancellation");

            var cts = new CancellationTokenSource();

            var output = factory(new object[]{cts.Token});

            var uri = new Uri(new Uri("http://api"), output.RequestMessage.RequestUri);
            Assert.AreEqual("/foo", uri.PathAndQuery);
            Assert.IsFalse(output.CancellationToken.IsCancellationRequested);
        }