コード例 #1
0
        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.
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Get a BO4E compliant URI for this business object.
 /// </summary>
 /// Use .ToString() on the result to pass it between services.
 /// <returns>a BO4E compliant URI object</returns>
 public Bo4eUri GetURI(bool includeUserProperties = false)
 {
     return(Bo4eUri.GetUri(this, includeUserProperties));
 }