This is a migrated thread and some comments may be shown as answers.

Mock Webservices

3 Answers 104 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
joao
Top achievements
Rank 1
joao asked on 10 Sep 2010, 09:03 PM
Hi, i bought justmock, and reading JustMock  documents  i dont find how to mock web 
services, i need create a mock web services(Request,response etc..) anybody have a example?

3 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 15 Sep 2010, 08:13 AM
Hi joao,

Unfortunately, there is no specific example of mocking web services in the current documentation. However, by mocking web services you will be mocking client proxy which is similar to mocking any other .net classes. 

Additionally, I attached a solution containing some getting started examples that shows mocking of web services using JustMock. There are basic as well as an example that illustrates mocking of an async call.

Hope that helps,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yachana
Top achievements
Rank 1
answered on 07 Jul 2014, 10:55 AM
Hi

can u please provide some thing relevant to web services (web methods unit testing with out any valid url or invoking the web service).

Thanks
Yachana
0
Kaloyan
Telerik team
answered on 10 Jul 2014, 07:02 AM
Hi Yachana,

Basically, you should be able to mock almost everything with the commercial version of JustMock. However, could you provide some sample code that needs to be tested in order to see where your concerns come from?

Further, here is a simple example of mocking the System.Net.WebResponse and WebRequest classes:
// Arrange
var expectedRequest = new Uri("http://myUrl/Request");
var expectedResponse = new Uri("http://myUrl/Response");
 
var response = Mock.Create<WebResponse>();
var request = Mock.Create<WebRequest>();
 
Mock.Arrange(() => request.RequestUri).Returns(expectedRequest);
Mock.Arrange(() => response.ResponseUri).Returns(expectedResponse);
 
// Act
var actualRequest = request.RequestUri;
var actualResponse = response.ResponseUri;
 
// Assert
Assert.AreEqual(expectedRequest, actualRequest);
Assert.AreEqual(expectedResponse, actualResponse);

I hope this helps. Looking forward to your reply.

Regards,
Kaloyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
joao
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Yachana
Top achievements
Rank 1
Kaloyan
Telerik team
Share this question
or