public void TestRLMFilter() { Bo4eUri uri = new Bo4eUri("bo4e://marktlokation?filter=bilanzierungsmethode%20%3D%20%27RLM%27"); JObject query = uri.GetQueryObject(); Assert.IsTrue(query.ContainsKey("bilanzierungsmethode")); }
public void TestRoundTripUriFilterQueryObject() { JObject qo = JObject.Parse("{'marktlokationsId':'543212345', 'messlokationsId':'DE123', 'bilanzierungsmethode':'SLP'}"); Bo4eUri uri = (new Bo4eUri("bo4e://marktlokation?search=something")).AddFilter(JsonConvert.DeserializeObject <IDictionary <string, object> >(qo.ToString())); Assert.IsNotNull(uri); Assert.AreEqual("bo4e://marktlokation/?search=something&filter=marktlokationsId+eq+%27543212345%27+and+bilanzierungsmethode+eq+%27SLP%27", uri.ToString()); JObject qo2 = uri.GetQueryObject(); Assert.IsTrue(qo2.ContainsKey("marktlokationsId")); Assert.IsTrue(qo2.ContainsKey("bilanzierungsmethode")); Assert.AreEqual("543212345", qo2.GetValue("marktlokationsId")); Assert.AreEqual("SLP", qo2.GetValue("bilanzierungsmethode")); }
public void TestUriConstructionAndKeyDeconstruction() { string[] files = Directory.GetFiles($"bo4eURITests/", "*.json"); foreach (string file in files) { JObject json; using (StreamReader r = new StreamReader(file)) { string jsonString = r.ReadToEnd(); json = JsonConvert.DeserializeObject <JObject>(jsonString); } Assert.IsNotNull(json, $"The content of file {file} seems to be no valid JSON."); Assert.IsNotNull(json["input"], $"The file {file} does not contain the mandatory 'input' key."); Assert.IsNotNull(json["expectedUri"], $"The file {file} does not contain the mandatory 'expectedUri' key."); //string boType = (string)json["input"]["boTyp"]; //Assert.IsNotNull(boType, $"The JSON content of file {file} is missing the obligatory 'boTyp' attribute."); BusinessObject bo = JsonConvert.DeserializeObject <BusinessObject>(json["input"].ToString()); Assert.IsNotNull(bo, $"The business object in file {file} is not a valid BO4E."); Bo4eUri uri = Bo4eUri.GetUri(bo); string uriString = uri.AbsoluteUri; Assert.AreEqual(json["expectedUri"], uriString, "The URI doesn't match the expectations."); Assert.IsNotNull(json["expectedQueryObject"], $"Please specify the query object result in file {file}, key 'expectedQueryObject'."); JObject queryObject = uri.GetQueryObject(); var jdp = new JsonDiffPatch(); JToken left = json["expectedQueryObject"]; JToken right = queryObject; var patch = jdp.Diff(left, right); if (patch != null) { if (patch.ToString() .Replace("\n", "") .Replace("\r", "") .Replace(" ", "") == "{\"vorname\":[null,null]}") { continue; } Assert.IsNull(patch, patch.ToString()); } else { Assert.IsNull(patch); // witzlos. } } }
public void TestEmptyUriQueryObject() { var uri = new Bo4eUri("bo4e://Energiemenge"); bool exceptionThrown = false; string result = String.Empty; try { result = uri.GetQueryObject().ToString(); } catch (Exception) { // must not happen! exceptionThrown = true; } Assert.IsFalse(exceptionThrown); Assert.IsTrue(result.Contains("ENERGIEMENGE")); }