You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a single HttpHelperFakes.cs file which can be easily added to the test projects using nuget.
This should be independent of Unit Test/Mocking frameworks. In fact mocking should not be used at all since most of these frameworks does not work in WP7/WinRT.
Here some sample usage for Facebook C# SDK.
[Fact]publicvoidTest(){varfb=newFacebookClient();FakeHttpWebRequestWrapperfakeRequest=null;FakeHttpWebResponseWrapperfakeResponse=null;fb.HttpWebRequestFactory=
uri =>fakeRequest=newFakeHttpWebRequestWrapper().WithRequestUri(uri).FakeResponse().WithResponseStreamAs("{\"id\":\"4\",\"name\":\"Mark Zuckerberg\",\"first_name\":\"Mark\",\"last_name\":\"Zuckerberg\",\"link\":\"http:\\/\\/www.facebook.com\\/zuck\",\"username\":\"zuck\",\"gender\":\"male\",\"locale\":\"en_US\"}").WithContentType("text/javascript; charset=UTF-8").WithStatusCode(200).GetFakeHttpWebRequestWrapper();dynamicresult=fb.Get("4");Assert.Equal("GET",fakeRequest.Method);Assert.Equal("https://graph.facebook.com/4",fakeRequest.RequestUri.AbsoluteUri);Assert.True(fakeRequest.ContentLength==0);Assert.IsAssignableFrom<IDictionary<string,object>>(result);Assert.Equal("4",result.id);Assert.Equal("Mark Zuckerberg",result.name);}
This will allow us to fake the entire HttpWebRequest/HttpWebResponse and we will not need to have the actual request. So integration test would not be required. Since it also executes entire code line by line, test coverage is also highly increased.
It also allows us to test the request properties such as checking if the RequestUri was generated correctly or if the HttpMethod was set correctly and so on.
Also add helper methods for Exceptions and no internet connection.
newFakeHttpWebRequest().NoInternetConnection();
Assumed request got executed but when executing response the internet got disconnected.
Create a single HttpHelperFakes.cs file which can be easily added to the test projects using nuget.
This should be independent of Unit Test/Mocking frameworks. In fact mocking should not be used at all since most of these frameworks does not work in WP7/WinRT.
Here some sample usage for Facebook C# SDK.
This will allow us to fake the entire HttpWebRequest/HttpWebResponse and we will not need to have the actual request. So integration test would not be required. Since it also executes entire code line by line, test coverage is also highly increased.
It also allows us to test the request properties such as checking if the RequestUri was generated correctly or if the HttpMethod was set correctly and so on.
Also add helper methods for Exceptions and no internet connection.
Assumed request got executed but when executing response the internet got disconnected.
The text was updated successfully, but these errors were encountered: