Пример #1
0
        public void BeginEndFetchInternalTest()
        {
            var requestProvider = new MockRequestProvider {
                CreateSuspendedRequests = true
            };
            var request = new MockServiceRequest <string>(requestProvider);

            // Request validation is done in the MockSchemaAwareRequestExecutor.
            string       result = null;
            IAsyncResult async  = request.BeginFetchInternal(
                cb => result = request.EndFetch(cb), null, res => request.FetchObject(res.GetResponse()));

            // Test that the operation is not yet completed.
            Assert.IsFalse(async.IsCompleted);
            Assert.IsFalse(async.CompletedSynchronously);
            Assert.IsNotNull(async.AsyncWaitHandle);
            Assert.IsNull(async.AsyncState);

            // Let the async operation continue.
            requestProvider.LastRequest.SuspendAsyncRequest = false;
            if (!async.AsyncWaitHandle.WaitOne(5000))
            {
                Assert.Fail("Async Operation seems to be stuck.");
            }

            // Check the result.
            Assert.IsTrue(async.IsCompleted);
            Assert.AreEqual("FooBar", result);
            Assert.IsFalse(async.CompletedSynchronously);
        }
Пример #2
0
        public void FetchTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            // Request validation is done in the MockSchemaAwareRequestExecutor.
            Assert.AreEqual("FooBar", request.Fetch());
        }
Пример #3
0
        public void FetchAsStreamTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            // Request validation is done in the MockSchemaAwareRequestExecutor.
            Assert.IsNotNull(request.FetchAsStream());
        }
Пример #4
0
        public void UserIpTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            request.UserIp = "FooBar";

            // Confirm that the E-tag and the behavior is passed along.
            MockRequest result = (MockRequest)request.BuildRequest();

            Assert.AreEqual("FooBar", result.UserIp);
        }
Пример #5
0
        public void ETagTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            request.ETag       = "FooBar";
            request.ETagAction = ETagAction.IfMatch;

            // Confirm that the E-tag and the behavior is passed along.
            MockRequest result = (MockRequest)request.BuildRequest();

            Assert.AreEqual("FooBar", result.ETag);
            Assert.AreEqual(ETagAction.IfMatch, result.ETagAction);
        }
Пример #6
0
        public void CreateParameterDictionaryTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            request.TestParameterA = 42;
            request.TestParameterB = 43;
            request.TestParameterC = 44;

            IDictionary <string, object> parameters = request.CreateParameterDictionary();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(42, parameters["testparametera"]);
            Assert.AreEqual(43, parameters["B"]);
        }
Пример #7
0
        public void ETagTypedBodyTest()
        {
            var mockBody = new Mock <IDirectResponseSchema>();

            mockBody.Setup(b => b.ETag).Returns("FooBar");

            var request = new MockServiceRequest <IDirectResponseSchema>(new MockRequestProvider());

            request.ETagAction = ETagAction.IfMatch;
            request.Body       = mockBody.Object;

            // Confirm that the E-tag and the behavior is passed along.
            MockRequest result = (MockRequest)request.BuildRequest();

            Assert.AreEqual("FooBar", result.ETag);
            Assert.AreEqual(ETagAction.IfMatch, result.ETagAction);
            mockBody.Verify();
        }
Пример #8
0
        public void FetchAsyncTest()
        {
            var request = new MockServiceRequest <string>(new MockRequestProvider());

            // Request validation is done in the MockSchemaAwareRequestExecutor.
            var wait = new AutoResetEvent(false);

            request.FetchAsync();
            request.FetchAsync((response) =>
            {
                Assert.AreEqual("FooBar", response.GetResult());
                wait.Set();
            });
            if (!wait.WaitOne(5000))
            {
                Assert.Fail("Async-task was not finished.");
            }
        }
Пример #9
0
        public void BeginEndFetchAsStreamTest()
        {
            var requestProvider = new MockRequestProvider {
                CreateSuspendedRequests = true
            };
            var request = new MockServiceRequest <string>(requestProvider);

            Stream       result = null;
            IAsyncResult async  = request.BeginFetchAsStream(cb => result = request.EndFetchAsStream(cb), null);

            // Check the result.
            Assert.IsFalse(async.AsyncWaitHandle.WaitOne(30));
            Assert.IsFalse(async.IsCompleted);
            requestProvider.LastRequest.SuspendAsyncRequest = false;
            if (!async.AsyncWaitHandle.WaitOne(5000))
            {
                Assert.Fail("Asynchronous Fetch operation seems to be stuck.");
            }
            Assert.IsInstanceOf <MemoryStream>(result);
        }