Example #1
0
        public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsNotOpen_GetCompletedErrorIsNull()
        {
            var mockFb = new Mock<FuntownClient> { 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("/4"), 5000);

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

            Assert.NotNull(error);
        }
Example #2
0
        public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsNotOpen_DeleteCompletedIsNotCalled()
        {
            var mockFb = new Mock<FuntownClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<WebExceptionWrapper> mockWebException;

            mockFb.NoInternetConnection(out mockRequest, out mockWebException);

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

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

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

            Assert.Equal(0, called);
        }
        public void Sync_DoesNotCallPostCompletedEvent()
        {
            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;

            fb.PostCompleted += (o, e) => ++called;

            fb.Get(_parameters);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.Equal(0, called);
        }
        public void Sync_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;

            fb.PostCompleted += (o, e) => ++called;

            fb.Get("/4");

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyGetResponse();
            mockResponse.VerifyGetResponseStream();

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

            mockFb.FiddlerNoInternetConnection(out mockRequest, out mockResponse, 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();
            mockResponse.VerifyGetResponseStream();

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

            mockFb.NoInternetConnection(out mockRequest, 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();

            Assert.Null(result);
        }
        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 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);
        }
        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);
        }
        public void SyncReturnsJsonArrayIfArray()
        {
            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;
            dynamic result = fb.Get(_parameters);

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.IsAssignableFrom<IList<object>>(result);
            Assert.IsType<JsonArray>(result);
        }
        public void Async_GetCompletedErrorIsNull()
        {
            var mockFb = new Mock<FuntownClient> { 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;
            Exception error = null;

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

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

            Assert.Null(error);
        }
Example #12
0
        public void SyncReturnsJsonObjectIfObject()
        {
            var mockFb = new Mock<FuntownClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<HttpWebResponseWrapper> mockResponse;
            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.funtown.com\\/zuck\",\"username\":\"zuck\",\"gender\":\"male\",\"locale\":\"en_US\"}",
                out mockRequest, out mockResponse);

            var fb = mockFb.Object;
            dynamic result = fb.Get("/4");

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyGetResponse();
            mockResponse.VerifyGetResponseStream();

            Assert.IsAssignableFrom<IDictionary<string, object>>(result);
            Assert.IsType<JsonObject>(result);
        }
Example #13
0
        public void Async_GetCompletedGetResultDataIsOfTypeJsonObjectIfObject()
        {
            var mockFb = new Mock<FuntownClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.funtown.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);
        }
Example #14
0
        public void Async_GetCompletedErrorIsNull()
        {
            var mockFb = new Mock<FuntownClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<HttpWebResponseWrapper> mockResponse;

            mockFb.ReturnsJson("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.funtown.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);
        }
Example #15
0
        public void Async_DoesNotCallDeleteCompletedEvent()
        {
            var mockFb = new Mock<FuntownClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<HttpWebResponseWrapper> mockResponse;

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

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

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

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

            Assert.Equal(0, called);
        }
        public void AsyncWhenThereIsNoInternetConnectionAndFiddlerIsOpen_PostCompletedIsNotCalled()
        {
            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.PostCompleted += (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 SyncWhenThereIsNotInternetConnectionAndFiddlerIsNotOpen_ThrowsWebExceptionWrapper()
        {
            var mockFb = new Mock<FacebookClient> { CallBase = true };
            Mock<HttpWebRequestWrapper> mockRequest;
            Mock<WebExceptionWrapper> mockWebException;

            mockFb.NoInternetConnection(out mockRequest, out mockWebException);

            Exception exception = null;

            try
            {
                var fb = mockFb.Object;
                fb.Get(_parameters);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            mockFb.VerifyCreateHttpWebRequest(Times.Once());
            mockRequest.VerifyGetResponse();
            mockWebException.VerifyGetReponse();

            Assert.IsAssignableFrom<WebExceptionWrapper>(exception);
        }