private static GatewayStoreModel MockGatewayStoreModel(Func <HttpRequestMessage, Task <HttpResponseMessage> > sendFunc) { Mock <IDocumentClientInternal> mockDocumentClient = new Mock <IDocumentClientInternal>(); mockDocumentClient.Setup(client => client.ServiceEndpoint).Returns(new Uri("https://foo")); GlobalEndpointManager endpointManager = new GlobalEndpointManager(mockDocumentClient.Object, new ConnectionPolicy()); ISessionContainer sessionContainer = new SessionContainer(string.Empty); HttpMessageHandler messageHandler = new MockMessageHandler(sendFunc); return(new GatewayStoreModel( endpointManager, sessionContainer, Cosmos.ConsistencyLevel.Eventual, new DocumentClientEventSource(), new JsonSerializerSettings(), MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler)))); }
public async Task ResponseMessageHasRequestMessageAsync() { // We don't set the RequestMessage property on purpose on the Failed response // This will make it go through GatewayStoreClient.CreateDocumentClientExceptionAsync Func <HttpRequestMessage, Task <HttpResponseMessage> > sendFunc = request => { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("test") }; return(Task.FromResult(response)); }; DocumentClientEventSource eventSource = DocumentClientEventSource.Instance; HttpMessageHandler messageHandler = new MockMessageHandler(sendFunc); CosmosHttpClient cosmoshttpClient = MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler)); HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri("http://localhost")); HttpResponseMessage responseMessage = await cosmoshttpClient.SendHttpAsync(() => new ValueTask <HttpRequestMessage>(httpRequestMessage), ResourceType.Collection, null, default); Assert.AreEqual(httpRequestMessage, responseMessage.RequestMessage); }