public void GetCoapRequest_BadMethod() { HttpRequest http = new HttpRequest("FOOBAR /foo HTTP/1.1\n" + Host); TranslationException e = Assert.Throws <TranslationException>(() => HttpTranslator.GetCoapRequest(http, "xx", true)); Assert.That(e.Message, Is.EqualTo("FOOBAR method not mapped")); }
public void GetCoapRequest_SimpleForm() { HttpRequest http; string proxyUri = "coap://coap.example.com/resource"; http = new HttpRequest("GET /hc/" + proxyUri + " HTTP/1.1\n" + Host); Request req = HttpTranslator.GetCoapRequest(http, "hc/{+tu}", true); Assert.That(req.Method, Is.EqualTo(Method.GET)); Assert.That(req.ProxyUri.ToString(), Is.EqualTo(proxyUri)); proxyUri = "//coap.example.com/resource"; http = new HttpRequest("GET /hc/" + proxyUri + " HTTP/1.1\n" + Host); TranslationException e = Assert.Throws <TranslationException>(() => HttpTranslator.GetCoapRequest(http, "hc/{+tu}", true)); Assert.That(e.Message, Is.EqualTo("Schema is required")); proxyUri = "coap://coap.example.com/?query=1"; http = new HttpRequest("GET /hc/" + proxyUri + " HTTP/1.1\n" + Host); req = HttpTranslator.GetCoapRequest(http, "hc/{+tu}", true); Assert.That(req.Method, Is.EqualTo(Method.GET)); Assert.That(req.ProxyUri.ToString(), Is.EqualTo(proxyUri)); proxyUri = "coap://coap.example.com/resource?query=1"; http = new HttpRequest("GET /hc/" + proxyUri + " HTTP/1.1\n" + Host); req = HttpTranslator.GetCoapRequest(http, "hc/{+tu}", true); Assert.That(req.Method, Is.EqualTo(Method.GET)); Assert.That(req.ProxyUri.ToString(), Is.EqualTo(proxyUri)); proxyUri = "coap://coap.example.com:5848/resource"; http = new HttpRequest("GET /hc/" + proxyUri + " HTTP/1.1\n" + Host); req = HttpTranslator.GetCoapRequest(http, "hc/{+tu}", true); Assert.That(req.Method, Is.EqualTo(Method.GET)); Assert.That(req.ProxyUri.ToString(), Is.EqualTo(proxyUri)); }