public HttpResponseModel Unregister(RequestRegistrationModel requestRegistrationModel) { StubRegistration outValue; _registeredRequests.TryRemove(requestRegistrationModel.GetHashCode(), out outValue); return(outValue.Response); }
public void Match_ShouldReturnNull_WhenAllAttributesAreAnyButPathDoesntMatch() { var model = Fixture.Create <HttpRequestModel>(); var requestRegistration = new RequestRegistrationModel { LocalPath = model.LocalPath + "1" }; Sut.Match(new[] { requestRegistration }, model).Should().Be(null); }
public void Match_ShouldReturnMatchingRequest_WhenAllAttributesAreAnyAndPathMatches() { var model = Fixture.Create <HttpRequestModel>(); var requestRegistration = new RequestRegistrationModel { LocalPath = model.LocalPath }; Sut.Match(new[] { requestRegistration }, model).Should().Be(requestRegistration); }
public void Match_ShouldReturnMatchingRequest_WhenBodyIsAnyAndAllOtherAttributesMatchExactly() { var model = Fixture.Create <HttpRequestModel>(); var requestRegistration = new RequestRegistrationModel { LocalPath = model.LocalPath, Body = { Any = true, Value = null }, Port = { Any = false, Value = model.Port }, Headers = { Any = false, Value = model.Headers }, Method = { Any = false, Value = model.Method }, Query = { Any = false, Value = model.Query } }; Sut.Match(new[] { requestRegistration }, model).Should().Be(requestRegistration); }
internal IRestResponse Send(RequestRegistrationModel requestRegistrationModel) { var request = new RestRequestEx(requestRegistrationModel.LocalPath, ConvertMethod(requestRegistrationModel.Method.Value)); if (requestRegistrationModel.Headers?.Value != null) { foreach (var header in requestRegistrationModel.Headers.Value.Dictionary) { request.AddHeader(header.Key, header.Value); } } request.RequestFormat = DataFormat.Json; if (!requestRegistrationModel.Body.Any) { request.AddBody(requestRegistrationModel.Body.Value); request.RequestFormat = DataFormat.Json; } return(Execute(request)); }
public void Build_ShouldPopulateAllProperties() { var builder = new RequestBuilder(new StubBuilder()); var request = builder .WithPath("test/method/1").AndMethod(Method.Get) .AndQueryString("customerId", "153").AndQueryString("orderId", "1314") .AndBody("<Html/>", "text/html") .AndHeader("X-Powered-By", "IIS") .AndPort(443) .Build(); var expectedRequest = new RequestRegistrationModel { Query = { Any = false, Value = "?customerId=153&orderId=1314" }, Method = { Any = false, Value = Method.Get }, Port = { Any = false, Value = 443 }, LocalPath = "/test/method/1", Body = { Any = false, Value = new Body() { Data = "<Html/>",ContentType = new ContentType() { MediaType = "text/html" } } }, Headers = { Any = false, Value = new Headers(new Dictionary <string, string>() { { "x-powered-by", "IIS" } }) } }; request.ShouldEqual(expectedRequest); }
internal void Clear() { _registrationModel = new RequestRegistrationModel(); }
public HttpResponseModel Get(RequestRegistrationModel matchingRequest) { return(_registeredRequests[matchingRequest.GetHashCode()].Response); }
public HttpResponseModel Find(RequestRegistrationModel requestRegistrationModel) { return(_registeredRequests[requestRegistrationModel.GetHashCode()]?.Response); }