public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsOpen_GetCompletedGetResultDataIsNull()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;
            Mock <WebExceptionWrapper>    mockWebException;

            mockFb.FiddlerNoInternetConnection(out mockRequest, out mockResponse, out mockWebException);

            object result = null;
            var    fb     = mockFb.Object;

            TestExtensions.Do(evt =>
            {
                fb.GetCompleted += (o, e) =>
                {
                    result = e.GetResultData();
                    evt.Set();
                };
            }
                              , () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockWebException.VerifyGetReponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Null(result);
        }
        public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsOpen_DeleteCompletedIsNotCalled()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;
            Mock <WebExceptionWrapper>    mockWebException;

            mockFb.FiddlerNoInternetConnection(out mockRequest, out mockResponse, out mockWebException);

            int called = 0;
            var fb     = mockFb.Object;

            TestExtensions.Do(evt =>
            {
                fb.DeleteCompleted += (o, e) =>
                {
                    ++called;
                    evt.Set();
                };
            }
                              , () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockWebException.VerifyGetReponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Equal(0, called);
        }
        public void Async_DoesNotCallDeleteCompletedEvent()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("[{\"uid\":\"4\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"name\":\"Mark Zuckerberg\"}]",
                               out mockRequest, out mockResponse);

            var fb     = mockFb.Object;
            int called = 0;

            TestExtensions.Do(evt =>
            {
                fb.DeleteCompleted += (o, e) => ++ called;
            },
                              () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Equal(0, called);
        }
        public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsNotOpen_GetCompletedErrorIsWebExceptionWrapper()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper> mockRequest;
            Mock <WebExceptionWrapper>   mockWebException;

            mockFb.NoInternetConnection(out mockRequest, out mockWebException);

            Exception error = null;
            var       fb    = mockFb.Object;

            TestExtensions.Do(evt =>
            {
                fb.GetCompleted += (o, e) =>
                {
                    error = e.Error;
                    evt.Set();
                };
            },
                              () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockWebException.VerifyGetReponse();

            Assert.IsAssignableFrom <WebExceptionWrapper>(error);
        }
        public void Async_GetCompletedGetResultDataIsOfTypeJsonArrayIfArray()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("[{\"uid\":\"4\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"name\":\"Mark Zuckerberg\"}]",
                               out mockRequest, out mockResponse);

            var    fb     = mockFb.Object;
            object result = null;

            TestExtensions.Do(evt => fb.GetCompleted += (o, e) => result = e.GetResultData(),
                              () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.IsAssignableFrom <IList <object> >(result);
            Assert.IsType <JsonArray>(result);
        }
예제 #6
0
        public void Async_DoesNotCallPostCompletedEvent()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.facebook.com\\/zuck\",\"username\":\"zuck\",\"gender\":\"male\",\"locale\":\"en_US\"}",
                               out mockRequest, out mockResponse);

            var fb     = mockFb.Object;
            int called = 0;

            TestExtensions.Do(evt =>
            {
                fb.PostCompleted += (o, e) => ++ called;
            },
                              () => fb.GetAsync("/4"), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Equal(0, called);
        }
예제 #7
0
        public void Async_GetCompletedGetResultDataIsOfTypeJsonObjectIfObject()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.facebook.com\\/zuck\",\"username\":\"zuck\",\"gender\":\"male\",\"locale\":\"en_US\"}",
                               out mockRequest, out mockResponse);

            var    fb     = mockFb.Object;
            object result = null;

            TestExtensions.Do(evt => fb.GetCompleted += (o, e) => result = e.GetResultData(),
                              () => fb.GetAsync("/4"), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.IsAssignableFrom <IDictionary <string, object> >(result);
            Assert.IsType <JsonObject>(result);
        }
        public void AsyncWithoutUserState_GetCompletedUserStateIsNull()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("[{\"uid\":\"4\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"name\":\"Mark Zuckerberg\"}]",
                               out mockRequest, out mockResponse);

            var    fb        = mockFb.Object;
            object userState = null;

            TestExtensions.Do(evt => fb.GetCompleted += (o, e) => userState = e.UserState,
                              () => fb.GetAsync(_parameters), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Null(userState);
        }
예제 #9
0
        public void Async_GetCompletedErrorIsNull()
        {
            var mockFb = new Mock <FacebookClient> {
                CallBase = true
            };
            Mock <HttpWebRequestWrapper>  mockRequest;
            Mock <HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.facebook.com\\/zuck\",\"username\":\"zuck\",\"gender\":\"male\",\"locale\":\"en_US\"}",
                               out mockRequest, out mockResponse);

            var       fb    = mockFb.Object;
            Exception error = null;

            TestExtensions.Do(evt => fb.GetCompleted += (o, e) => error = e.Error,
                              () => fb.GetAsync("/4"), 5000);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyBeginGetResponse();
            mockRequest.VerifyEndGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Null(error);
        }