public void Initialize() { m_factory = new MockHandlerFactory(); IRestServiceHandler testHandler = m_factory.Create<ITestService>("~/test-service/new", m => m.Post(null)); Assert.That(testHandler, Is.Not.Null); Assert.That(testHandler.Context, Is.Not.Null); IRestServiceHandler selfContainedHandler = m_factory.Create<TestSelfContainedService>("~/test-ok-fail/ok", m => m.GetOK()); Assert.That(selfContainedHandler, Is.Not.Null); Assert.That(selfContainedHandler.Context, Is.Not.Null); }
public void GetMethod_ShouldFailDueToNegativeIdValue() { const string url = "~/test-service/-1"; const HttpMethod method = HttpMethod.Get; using (var factory = new MockHandlerFactory()) { IRestServiceHandler handler = factory.Create<ITestService>(url, m => m.Get(-1)); Assert.That(handler, Is.Not.Null); Assert.That(handler, Is.InstanceOf<RestServiceHandler>()); Assert.That(handler.Context, Is.Not.Null); Assert.That(handler.Context.Request, Is.Not.Null); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Request.Url, Is.EqualTo(ToAbsoluteUri(url))); Assert.That(handler.Context.Request.Method, Is.EqualTo(method)); ProcessRequest(handler); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Response.GetStatusCode(), Is.EqualTo(HttpStatusCode.OK)); } }
public void DeleteMethod() { const string url = "~/test-service/1"; const HttpMethod method = HttpMethod.Delete; using (var factory = new MockHandlerFactory()) { IRestServiceHandler handler = factory.Create<ITestService>(url, m => m.Delete(1)); Assert.That(handler, Is.Not.Null); Assert.That(handler, Is.InstanceOf<RestServiceHandler>()); Assert.That(handler.Context, Is.Not.Null); Assert.That(handler.Context.Request, Is.Not.Null); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Request.Url, Is.EqualTo(ToAbsoluteUri(url))); Assert.That(handler.Context.Request.Method, Is.EqualTo(method)); ProcessRequest(handler); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Response.GetStatusCode(), Is.EqualTo(HttpStatusCode.NoContent)); } }
public void PostMethod_ShouldFailDueToMismatchedUrlTemplate() { const string url = "~/test-service/1"; const HttpMethod method = HttpMethod.Post; using (var factory = new MockHandlerFactory()) { IRestServiceHandler handler = factory.Create<ITestService>(url, m => m.Post(null), method); Assert.That(handler, Is.Not.Null); Assert.That(handler, Is.InstanceOf<RestServiceHandler>()); Assert.That(handler.Context, Is.Not.Null); Assert.That(handler.Context.Request, Is.Not.Null); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Request.Url, Is.EqualTo(ToAbsoluteUri(url))); Assert.That(handler.Context.Request.Method, Is.EqualTo(method)); ProcessRequest(handler); Assert.That(handler.Context.Response, Is.Not.Null); Assert.That(handler.Context.Response.GetStatusCode(), Is.EqualTo(HttpStatusCode.Created)); Assert.That(handler.Context.Response.GetHeader("Location"), Is.EqualTo(String.Concat(handler.Context.Request.Url.OperationUrl, "/1"))); } }