Beispiel #1
0
        public async void String_Bad_KeepResponse(object responseValue)
        {
            using (var request = new AsyncRequester <string>(
                       responseValue,
                       settings => settings.ExposeRawResponse(true),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                Encoding.UTF8.GetBytes(r.Response).Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
                r.ResponseRaw.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
            }
        }
Beispiel #2
0
        public async void Typed_Bad_KeepResponse(object responseValue)
        {
            using (var request = new AsyncRequester <StandardResponse>(
                       responseValue,
                       settings => settings.ExposeRawResponse(true),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                Assert.IsNull(r.Response);
                r.ResponseRaw.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
            }
        }
Beispiel #3
0
        public async void ByteArray_Bad_DiscardResponse(object responseValue)
        {
            using (var request = new AsyncRequester <byte[]>(
                       responseValue,
                       settings => settings.ExposeRawResponse(false),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                r.Response.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
                r.ResponseRaw.Should().BeNull();
            }
        }
Beispiel #4
0
        public async void VoidResponse_Bad_KeepResponse(object responseValue)
        {
            using (var request = new AsyncRequester <VoidResponse>(
                       responseValue,
                       settings => settings.ExposeRawResponse(true),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                //Response and rawresponse should ALWAYS be null for VoidResponse responses
                r.Response.Should().BeNull();
                r.ResponseRaw.Should().BeNull();
            }
        }
Beispiel #5
0
        public async Task DynamicDictionary_Bad_DiscardResponse(object responseValue)
        {
            using (var request = new AsyncRequester <DynamicDictionary>(
                       responseValue,
                       settings => settings.ExposeRawResponse(false),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream),
                       client => client.InfoAsync()
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                Assert.IsNull(r.Response);
                r.ResponseRaw.Should().BeNull();
            }
        }
Beispiel #6
0
        public async void Typed_Ok_DiscardResponse(object responseValue)
        {
            using (var request = new AsyncRequester <StandardResponse>(
                       responseValue,
                       settings => settings.ExposeRawResponse(false),
                       (settings, stream) => FakeResponse.Ok(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeTrue();
                object v = r.Response.value;

                v.ShouldBeEquivalentTo(responseValue);
                r.ResponseRaw.Should().BeNull();
            }
        }
Beispiel #7
0
        public async void DynamicDictionary_Ok_KeepResponse(object responseValue)
        {
            using (var request = new AsyncRequester <DynamicDictionary>(
                       responseValue,
                       settings => settings.ExposeRawResponse(true),
                       (settings, stream) => FakeResponse.Ok(settings, response: stream),
                       client => client.InfoAsync()
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeTrue();
                object v = r.Response["value"];

                v.ShouldBeEquivalentTo(responseValue);
                r.ResponseRaw.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
            }
        }
Beispiel #8
0
        public async void Stream_Bad_DiscardResponse(object responseValue)
        {
            using (var request = new AsyncRequester <Stream>(
                       responseValue,
                       settings => settings.ExposeRawResponse(false),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                using (r.Response)
                    using (var ms = new MemoryStream())
                    {
                        r.Response.CopyTo(ms);
                        var bytes = ms.ToArray();
                        bytes.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
                    }
                r.ResponseRaw.Should().BeNull();
            }
        }
Beispiel #9
0
        public async void Stream_Bad_KeepResponse(object responseValue)
        {
            using (var request = new AsyncRequester <Stream>(
                       responseValue,
                       settings => settings.ExposeRawResponse(true),
                       (settings, stream) => FakeResponse.Bad(settings, response: stream)
                       ))
            {
                await request.Init();

                var r = request.Result;
                r.Success.Should().BeFalse();
                using (r.Response)
                    using (var ms = new MemoryStream())
                    {
                        r.Response.CopyTo(ms);
                        var bytes = ms.ToArray();
                        bytes.Should().NotBeNull().And.BeEquivalentTo(request.ResponseBytes);
                    }
                //raw response is ALWAYS null when requesting the stream directly
                //the client should not interfere with it
                r.ResponseRaw.Should().BeNull();
            }
        }