Esempio n. 1
0
 public void TestValidity()
 {
     foreach (string testString in validationResults.Keys)
     {
         Assert.AreEqual(validationResults[testString], Bo4eUri.IsValid(testString), $"URI validation failed for {testString} .");
     }
 }
Esempio n. 2
0
        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"));
        }
Esempio n. 3
0
        public void TestUPInclusion()
        {
            string       emString = @"{'versionStruktur':1,'boTyp':'ENERGIEMENGE','lokationsId':'DE0000000000000000000000010000400','lokationstyp':'MeLo','zw':'000000000030000301','anlagennummer':'4000000199','messlokationsId':'DE0000000000000000000000010000400','marktlokationsId':''}";
            Energiemenge em       = JsonConvert.DeserializeObject <Energiemenge>(emString);

            Assert.IsNotNull(em.UserProperties);
            Assert.IsTrue(em.UserProperties.Keys.Count > 0);
            Bo4eUri uri = em.GetURI(true);

            Assert.IsTrue(uri.ToString().Contains("messlokationsId="));
            Assert.IsTrue(uri.ToString().Contains("anlagennummer=4000000199"));
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
 public void TestBoNamesAndTypes()
 {
     foreach (string testString in boNameResults.Keys)
     {
         try
         {
             Bo4eUri uri = new Bo4eUri(testString);
             Assert.AreEqual(boNameResults[testString], uri.GetBoName(), $"boName validation failed for {testString}.");
             Assert.IsTrue(uri.GetBoType().ToString().EndsWith(boNameResults[testString]));
         }
         catch (ArgumentException)
         {
             Assert.IsNull(boNameResults[testString]);
         }
     }
 }
Esempio n. 6
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.
                }
            }
        }
Esempio n. 7
0
        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"));
        }
Esempio n. 8
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));
 }
Esempio n. 9
0
        public void TestWellformedKannmichmal()
        {
            var uri = new Bo4eUri("bo4e://messlokation/?filter=bilanzierungsmethode eq 'RLM'or bilanzierungsmethode eq 'IMS'");

            Assert.IsNotNull(uri);
        }
Esempio n. 10
0
 private bool ThisMethodOnlyAcceptsBo4eUri(Bo4eUri uri)
 {
     return(true);
 }
Esempio n. 11
0
#pragma warning disable IDE0060 // Remove unused parameter
        private bool ThisMethodOnlyAcceptsBo4eUri(Bo4eUri uri)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            return(true);
        }