public void LocationModification() { var rl = new ResourceLocation("http://hl7.org"); Assert.AreEqual("http://hl7.org/", rl.ToString()); rl.Service = "svc"; Assert.AreEqual("http://hl7.org/svc/", rl.ToString()); rl.Operation = "tags"; Assert.AreEqual("http://hl7.org/svc/tags", rl.ToString()); rl.Collection = "patient"; Assert.AreEqual("http://hl7.org/svc/patient/tags", rl.ToString()); rl.Id = "10"; Assert.AreEqual("http://hl7.org/svc/patient/@10/tags", rl.ToString()); rl.VersionId = "12"; Assert.AreEqual("http://hl7.org/svc/patient/@10/history/@12/tags", rl.ToString()); rl.Port = 2100; Assert.AreEqual("http://hl7.org:2100/svc/patient/@10/history/@12/tags", rl.ToString()); rl.Query = "?_count=50"; Assert.AreEqual("http://hl7.org:2100/svc/patient/@10/history/@12/tags?_count=50", rl.ToString()); }
public void ParamManipulation() { var rl = new ResourceLocation("patient/search?name=Kramer&name=Moreau&oauth=XXX"); rl.SetParam("newParamA", "1"); rl.SetParam("newParamB", "2"); Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=1&newParamB=2")); rl.SetParam("newParamA", "3"); rl.ClearParam("newParamB"); Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3")); rl.AddParam("newParamA", "4"); Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3&newParamA=4")); rl.AddParam("newParamB", "5"); Assert.IsTrue(rl.ToString().EndsWith("oauth=XXX&newParamA=3&newParamA=4&newParamB=5")); Assert.AreEqual("patient/search?name=Kramer&name=Moreau&oauth=XXX&newParamA=3&newParamA=4&newParamB=5", rl.OperationPath.ToString()); rl = new ResourceLocation("patient/search"); rl.SetParam("firstParam", "1"); rl.SetParam("sndParam", "2"); rl.ClearParam("sndParam"); Assert.AreEqual("patient/search?firstParam=1", rl.OperationPath.ToString()); rl.ClearParam("firstParam"); Assert.AreEqual("patient/search", rl.OperationPath.ToString()); rl.SetParam("firstParam", "1"); rl.SetParam("sndParam", "2"); rl.ClearParams(); Assert.AreEqual("patient/search", rl.OperationPath.ToString()); }
public void TryParseNonIdLocations() { var rl = new ResourceLocation("http://hl7.org/patient/validate/@1"); Assert.IsNull(rl.Service); Assert.AreEqual("validate", rl.Operation); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); rl = new ResourceLocation("http://hl7.org/svc/patient/myoperation"); Assert.AreEqual("svc", rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("myoperation", rl.Operation); Assert.IsNull(rl.Id); Assert.IsNull(rl.VersionId); rl = new ResourceLocation("http://hl7.org/svc/history"); Assert.AreEqual("http://hl7.org/svc/history", rl.ToString()); Assert.AreEqual("svc", rl.Service); Assert.IsNull(rl.Collection); Assert.AreEqual("history", rl.Operation); Assert.AreEqual("history", rl.OperationPath.ToString()); rl = new ResourceLocation("http://hl7.org/svc/history?_since=2010-10-30&_count=50"); Assert.AreEqual("http://hl7.org/svc/history?_since=2010-10-30&_count=50", rl.ToString()); Assert.AreEqual("svc", rl.Service); Assert.IsNull(rl.Collection); Assert.AreEqual("?_since=2010-10-30&_count=50", rl.Query); Assert.AreEqual("history", rl.Operation); Assert.AreEqual("history?_since=2010-10-30&_count=50", rl.OperationPath.ToString()); rl = new ResourceLocation("http://hl7.org:1234/svc/patient"); Assert.AreEqual("http://hl7.org:1234/svc/patient", rl.ToString()); Assert.AreEqual("svc", rl.Service); Assert.AreEqual(1234, rl.Port); Assert.IsNull(rl.Operation); Assert.AreEqual("patient", rl.Collection); rl = new ResourceLocation("http://hl7.org/svc/patient"); Assert.AreEqual("svc", rl.Service); Assert.IsNull(rl.Operation); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("patient", rl.OperationPath.ToString()); rl = new ResourceLocation("http://hl7.org/patient"); Assert.IsNull(rl.Service); Assert.IsNull(rl.Operation); Assert.AreEqual("patient", rl.Collection); rl = new ResourceLocation("http://hl7.org/svc"); Assert.AreEqual("http://hl7.org/svc", rl.ToString()); Assert.AreEqual("svc", rl.Service); Assert.IsNull(rl.Operation); Assert.IsNull(rl.Collection); rl = new ResourceLocation("http://hl7.org"); Assert.AreEqual("http://hl7.org/", rl.ToString()); Assert.IsNull(rl.Service); Assert.IsNull(rl.Operation); Assert.IsNull(rl.Collection); try { rl = new ResourceLocation("relative"); Assert.Fail("Single-argument constructor should throw exception on relative path"); } catch { // Ok! } }
public void TryParseLocationWithId() { ResourceLocation rl = new ResourceLocation("http://fhir.server.com/svc/patient/@1"); Assert.AreEqual("http://fhir.server.com/svc/patient/@1", rl.ToString()); Assert.AreEqual("http", rl.Scheme); Assert.AreEqual("fhir.server.com", rl.Host); Assert.AreEqual("/svc/patient/@1", rl.Path); Assert.AreEqual("svc", rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.AreEqual("http://fhir.server.com/svc/", rl.ServiceUri.ToString()); Assert.AreEqual("patient/@1", rl.OperationPath.ToString()); rl = new ResourceLocation("http://fhir.server.com/patient/@1/history/@9/myoperation"); Assert.AreEqual("http://fhir.server.com/patient/@1/history/@9/myoperation", rl.ToString()); Assert.AreEqual("fhir.server.com", rl.Host); Assert.IsNull(rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.AreEqual("9", rl.VersionId); Assert.AreEqual("myoperation", rl.Operation); Assert.AreEqual("patient/@1/history/@9/myoperation", rl.OperationPath.ToString()); rl = new ResourceLocation("http://fhir.server.com/patient/@1/history/@9"); Assert.AreEqual("http://fhir.server.com/patient/@1/history/@9", rl.ToString()); Assert.IsNull(rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.AreEqual("9", rl.VersionId); Assert.IsNull(rl.Operation); Assert.AreEqual("patient/@1/history/@9", rl.OperationPath.ToString()); rl = new ResourceLocation("http://fhir.server.com/patient/@1/history"); Assert.AreEqual("http://fhir.server.com/patient/@1/history", rl.ToString()); Assert.IsNull(rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.IsNull(rl.VersionId); Assert.AreEqual("history",rl.Operation); Assert.AreEqual("patient/@1/history", rl.OperationPath.ToString()); rl = new ResourceLocation("http://fhir.server.com/patient/@1"); Assert.AreEqual("http://fhir.server.com/patient/@1", rl.ToString()); Assert.IsNull(rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.IsNull(rl.VersionId); Assert.IsNull(rl.Operation); Assert.AreEqual("patient/@1", rl.OperationPath.ToString()); rl = new ResourceLocation("http://www.hl7.org", "svc/patient/@1"); Assert.AreEqual("http://www.hl7.org/svc/patient/@1", rl.ToString()); Assert.AreEqual("svc", rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); rl = new ResourceLocation("http://www.hl7.org/root", "svc/patient/@1"); Assert.AreEqual("http://www.hl7.org/root/svc/patient/@1", rl.ToString()); Assert.AreEqual("root/svc", rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); rl = new ResourceLocation("http://www.hl7.org/svc/organization/", "../patient/@1/myoperation"); Assert.AreEqual("www.hl7.org", rl.Host); Assert.AreEqual("svc", rl.Service); Assert.AreEqual("patient", rl.Collection); Assert.AreEqual("1", rl.Id); Assert.AreEqual("myoperation", rl.Operation); }