C# Class Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.MockHttpServer

A mock server implementation for capturing and replaying Http Web Requests.
Inheritance: IDisposable
ファイルを表示 Open project: Azure/azure-powershell Class Usage Examples

Public Properties

Property Type Description
DefaultHttpsServerPrefixUri System.Uri
DefaultServerPrefixUri System.Uri

Public Methods

Method Description
CreateWebException ( HttpStatusCode status, MemoryStream content, Action contextHandler ) : WebException

Create a WebException with the specified content.

CreateWebException ( HttpStatusCode status, string content, Action contextHandler ) : WebException

Create a WebException with the specified content.

Dispose ( ) : void

Stop and closes the listener.

MockHttpServer ( AsyncExceptionManager exceptionManager, Uri baseUri, Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.HttpSession session ) : System

Initializes a new instance of the MockHttpServer class that record or playback responses for requests in a session.

SetupCertificates ( ) : void

Setup certificates required for the unit tests

Private Methods

Method Description
ChangeUriBase ( Uri originalUri, Uri originalUriPrefix, Uri newPrefix ) : Uri

Returns the originalUri with its prefix changed from originalUriPrefix to newPrefix, or if the prefix is not in the originalUri, return the Uri as is.

ConstructListenerResponse ( HttpMessage responseInfo, Uri baseUri, HttpListenerResponse response ) : void

Constructs the response from the specified HttpMessage.Response.

ConstructRequestInfo ( HttpListenerRequest originalRequest ) : HttpMessage.Request

Create an HttpMessage.Request object out of the given originalRequest.

ConstructResponseInfo ( Uri serviceBaseUri, HttpWebResponse response ) : HttpMessage.Response

Create an HttpMessage.Response object out of the response from a service.

CreateListener ( Action contextHandler, int requestsToHandle ) : HttpListener

Create a HttpListener to handles requests.

ExecuteProcess ( string filename, string arguments ) : Process

Helper method to execute and wait for process to complete.

GetResponseInfoFromService ( HttpListenerRequest request, Uri baseUri, Uri serviceBaseUri, Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.HttpSession session ) : HttpMessage

Retrieves an HttpMessage object from a real service.

HandleMockRequest ( HttpListenerContext context, Uri baseUri, Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.HttpSession session ) : void

The async delegate that handles an incoming request, passing it through to a real service and record the response if serviceBaseUri was specified, or plays back responses from a pre-recorded session if it was not.

HandleRequest ( IAsyncResult ar, Action contextHandler, int requestsToHandle ) : void

The async delegate that handles an incoming request.

MakeServiceRequest ( HttpMessage originalRequest ) : HttpWebResponse

Make an request to the real service and retrieve the response.

MockHttpServer ( AsyncExceptionManager exceptionManager, Uri baseUri ) : System

Initializes a new instance of the MockHttpServer class with a specified server prefix.

Method Details

CreateWebException() public static method

Create a WebException with the specified content.
public static CreateWebException ( HttpStatusCode status, MemoryStream content, Action contextHandler ) : WebException
status HttpStatusCode The status code to use in the exception.
content System.IO.MemoryStream A of the exception content.
contextHandler Action An action that adds extra info to the response.
return System.Net.WebException

CreateWebException() public static method

Create a WebException with the specified content.
public static CreateWebException ( HttpStatusCode status, string content, Action contextHandler ) : WebException
status HttpStatusCode The status code to use in the exception.
content string The exception content.
contextHandler Action An action that adds extra info to the response.
return System.Net.WebException

Dispose() public method

Stop and closes the listener.
public Dispose ( ) : void
return void

MockHttpServer() public method

Initializes a new instance of the MockHttpServer class that record or playback responses for requests in a session.
public MockHttpServer ( AsyncExceptionManager exceptionManager, Uri baseUri, Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.HttpSession session ) : System
exceptionManager AsyncExceptionManager /// The exception manager that captures all async exceptions. ///
baseUri System.Uri The server prefix to use.
session Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.MockServer.HttpSession The object that stores request/response information.
return System

SetupCertificates() public static method

Setup certificates required for the unit tests
public static SetupCertificates ( ) : void
return void

Property Details

DefaultHttpsServerPrefixUri public_oe static_oe property

The HTTPS server prefix for tests which is been used in cert auth based unit tests
public static Uri,System DefaultHttpsServerPrefixUri
return System.Uri

DefaultServerPrefixUri public_oe static_oe property

The HTTP server prefix for tests
public static Uri,System DefaultServerPrefixUri
return System.Uri