public void Can_Generate_Api_Xml()
        {
            //Arrange
            string expected =
                new XElement("CompositeValue",
                             new XElement("Field",
                                          new XAttribute("name", "foo"),
                                          new XAttribute("type", "bar"),
                                          new XCData("baz"))).ToString();



            var cv = new CompositeValue
            {
                Fields = new List <Field>
                {
                    new Field
                    {
                        Name  = "foo",
                        Type  = "bar",
                        Value = "baz"
                    }
                }
            };

            //Act
            string actual = cv.ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Example #2
0
        private static void CheckCodingFlexible(CompositeValue comp, Dictionary <string, string> elements)
        {
            var elementsToCheck = elements.Where(e => e.Value != null);
            var nrOfElements    = elementsToCheck.Count();

            Assert.Equal(nrOfElements, comp.Components.Length);
            foreach (var c in comp.Components)
            {
                Assert.IsType <IndexValue>(c);
            }

            foreach (var element in elementsToCheck)
            {
                var elementIv = (IndexValue)comp.Components.Where(c => (c as IndexValue).Name == element.Key)
                                .FirstOrDefault();
                Assert.NotNull(elementIv);       //, $"Expected a component '{element.Key}'");
                Assert.Single(elementIv.Values); //, $"Expected exactly one component '{element.Key}'");
                Assert.IsType <StringValue>(
                    elementIv.Values[
                        0]); //, $"Expected component '{element.Key}' to be of type {nameof(StringValue)}");
                var codeSv = (StringValue)elementIv.Values[0];
                Assert.Equal(
                    element.Value,
                    codeSv.Value); //, $"Expected component '{element.Key}' to have the value '{element.Value}'");
            }
        }
 private static void CheckCoding(CompositeValue comp, string code, string system, string text)
 {
     CheckCodingFlexible(comp, new Dictionary <string, string>()
     {
         { "code", code }, { "system", system }, { "text", text }
     });
 }
        public void Can_Instantiate_New_CompositeValue()
        {
            //Act
            var cv = new CompositeValue();

            //Assert
            Assert.That(cv, Is.Not.Null);
        }
 public ActionResult Post([FromBody] CompositeValue value)
 {
     if (!Values.Any(v => v.Id == value.Id))
     {
         Values.Add(value);
         return(CreatedAtRoute("GetCompositeValue", new { id = value.Id }, value));
     }
     return(StatusCode(409));
 }
        public ActionResult Put(int id, [FromBody] CompositeValue newValue)
        {
            var value = Values.FirstOrDefault(v => v.Id == id);

            if (value != null)
            {
                value.Value = newValue.Value;
                return(Ok(value));
            }
            return(NotFound());
        }
        public void ToAdsml_Returns_Empty_CompositeValue_Tag_If_No_Fields()
        {
            //Arrange
            string expected = new XElement("CompositeValue").ToString();
            var    cv       = new CompositeValue();

            //Act
            string actual = cv.ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Example #8
0
        private BsonValue MapExpression(CompositeValue composite)
        {
            BsonDocument compositeDocument = new BsonDocument();

            foreach (var component in composite.Components)
            {
                if (component is IndexValue)
                {
                    compositeDocument.Add(IndexValueToElement((IndexValue)component));
                }
                else
                {
                    throw new ArgumentException("All Components of composite are expected to be of type IndexValue");
                }
            }
            return(compositeDocument);
        }
        public void HandleComposites()
        {
            var pX = new CompositeValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(14.8M) });
            var pY = new TokenValue("NOK", "http://somesuch.org");
            var p1 = new ChoiceValue(new ValueExpression[] { pX, pY });

            Assert.AreEqual(@"hello\, world!$14.8,http://somesuch.org|NOK", p1.ToString());

            var crit1 = ChoiceValue.Parse(@"hello\, world$14.8,http://somesuch.org|NOK");

            Assert.AreEqual(2, crit1.Choices.Length);
            Assert.IsTrue(crit1.Choices[0] is CompositeValue);
            var comp1 = crit1.Choices[0] as CompositeValue;

            Assert.AreEqual(2, comp1.Components.Length);
            Assert.AreEqual("hello, world", ((UntypedValue)comp1.Components[0]).AsStringValue().Value);
            Assert.AreEqual(14.8M, ((UntypedValue)comp1.Components[1]).AsNumberValue().Value);
            Assert.AreEqual("http://somesuch.org|NOK", ((UntypedValue)crit1.Choices[1]).AsTokenValue().ToString());
        }
        private static void CheckCoding(CompositeValue comp, string code, string system, string text)
        {
            var nrOfElements = new List <string> {
                code, system, text
            }.Where(s => s != null).Count();

            Assert.AreEqual(nrOfElements, comp.Components.Count());
            foreach (var c in comp.Components)
            {
                Assert.IsInstanceOfType(c, typeof(IndexValue));
            }

            if (code != null)
            {
                var codeIV = (IndexValue)comp.Components.Where(c => (c as IndexValue).Name == "code").FirstOrDefault();
                Assert.IsNotNull(codeIV);
                Assert.AreEqual(1, codeIV.Values.Count());
                Assert.IsInstanceOfType(codeIV.Values[0], typeof(StringValue));
                var codeSV = (StringValue)codeIV.Values[0];
                Assert.AreEqual(code, codeSV.Value);
            }

            if (system != null)
            {
                var systemIV = (IndexValue)comp.Components.Where(c => (c as IndexValue).Name == "system").FirstOrDefault();
                Assert.IsNotNull(systemIV);
                Assert.AreEqual(1, systemIV.Values.Count());
                Assert.IsInstanceOfType(systemIV.Values[0], typeof(StringValue));
                var systemSV = (StringValue)systemIV.Values[0];
                Assert.AreEqual(system, systemSV.Value);
            }

            if (text != null)
            {
                var textIV = (IndexValue)comp.Components.Where(c => (c as IndexValue).Name == "text").FirstOrDefault();
                Assert.IsNotNull(textIV);
                Assert.AreEqual(1, textIV.Values.Count());
                Assert.IsInstanceOfType(textIV.Values[0], typeof(StringValue));
                var textSV = (StringValue)textIV.Values[0];
                Assert.AreEqual(text, textSV.Value);
            }
        }
        private static void CheckCodingFlexible(CompositeValue comp, Dictionary <string, string> elements)
        {
            var elementsToCheck = elements.Where(e => e.Value != null);
            var nrOfElements    = elementsToCheck.Count();

            Assert.AreEqual(nrOfElements, comp.Components.Count());
            foreach (var c in comp.Components)
            {
                Assert.IsInstanceOfType(c, typeof(IndexValue));
            }

            foreach (var element in elementsToCheck)
            {
                var elementIV = (IndexValue)comp.Components.Where(c => (c as IndexValue).Name == element.Key).FirstOrDefault();
                Assert.IsNotNull(elementIV, $"Expected a component '{element.Key}'");
                Assert.AreEqual(1, elementIV.Values.Count(), $"Expected exactly one component '{element.Key}'");
                Assert.IsInstanceOfType(elementIV.Values[0], typeof(StringValue), $"Expected component '{element.Key}' to be of type {nameof(StringValue)}");
                var codeSV = (StringValue)elementIV.Values[0];
                Assert.AreEqual(element.Value, codeSV.Value, $"Expected component '{element.Key}' to have the value '{element.Value}'");
            }
        }
Example #12
0
 private static object GetValue(Expression expression)
 {
     return(expression switch
     {
         StringValue stringValue => stringValue.Value,
         IndexValue indexValue => indexValue.Values.Count == 1
             ? GetValue(indexValue.Values[0])
             : indexValue.Values.Select(GetValue).ToArray(),
         CompositeValue compositeValue =>
         compositeValue.Components.OfType <IndexValue>().All(x => x.Name == "code")
                 ? compositeValue.Components.OfType <IndexValue>()
         .SelectMany(x => x.Values.Select(GetValue))
         .First()
                 : compositeValue.Components.OfType <IndexValue>()
         .ToDictionary(
             component => component.Name,
             component =>
         {
             var a = component.Values.Select(GetValue).ToArray();
             return a.Length == 1 ? a[0] : a;
         }),
         _ => expression.ToString()
     });
Example #13
0
        private void WrapperCompositeExample()
        {
            UWPStorage storage = new UWPStorage(StorageType.Local);
            // Create a composite setting
            CompositeValue composite = new CompositeValue();

            composite.SetInt32("intVal", 3434);
            composite.SetString("strVal", "string");

            storage.SetComposite("WrapperCompositeSetting", composite);

            // Read data from a composite setting
            bool           exists     = false;
            CompositeValue composite2 = storage.GetComposite("WrapperCompositeSetting", out exists);

            if (exists)
            {
                // Access data in composite2["intVal"] and composite2["strVal"]
                int    one   = composite2.GetInt32("intVal", out exists, 4444);
                string hello = composite2.GetString("strVal", out exists, "error");
            }
            // Delete a composite setting
            storage.Remove("WrapperCompositeSetting");
        }
Example #14
0
        public void HandleComposites()
        {
            var pX = new CompositeValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(14.8M) });
            var pY = new TokenValue("NOK", "http://somesuch.org");
            var p1 = new ChoiceValue(new ValueExpression[] { pX, pY });
            Assert.AreEqual(@"hello\, world!$14.8,http://somesuch.org|NOK", p1.ToString());

            var crit1 = ChoiceValue.Parse(@"hello\, world$14.8,http://somesuch.org|NOK");
            Assert.AreEqual(2, crit1.Choices.Length);
            Assert.IsTrue(crit1.Choices[0] is CompositeValue);
            var comp1 = crit1.Choices[0] as CompositeValue;
            Assert.AreEqual(2, comp1.Components.Length);
            Assert.AreEqual("hello, world", ((UntypedValue)comp1.Components[0]).AsStringValue().Value);
            Assert.AreEqual(14.8M, ((UntypedValue)comp1.Components[1]).AsNumberValue().Value);
            Assert.AreEqual("http://somesuch.org|NOK", ((UntypedValue)crit1.Choices[1]).AsTokenValue().ToString());
        }
Example #15
0
        /// <summary>
        /// Используется для объединения дельтациклов в один объект TimeStampInfo
        /// </summary>
        /// <param name="elements"></param>
        /// <returns></returns>
        public static TimeStampInfo CombineTimestamps(ModellingType groupModellingType, IList <TimeStampInfo> elements)
        {
            TimeStampInfo res = new TimeStampInfo();

            List <AbstractValue>         values    = new List <AbstractValue>();
            List <TimeStampInfoIterator> iterators = new List <TimeStampInfoIterator>();
            int currentDeltaCycle = int.MaxValue;

            foreach (TimeStampInfo inf in elements)
            {
                if (inf != null)
                {
                    values.Add(inf[0]);
                    iterators.Add(new TimeStampInfoIterator(inf));
                    if (inf.ElementAt(0).Key < currentDeltaCycle)
                    {
                        currentDeltaCycle = inf.ElementAt(0).Key;
                    }
                }
            }

            bool IsDone = false;

            while (IsDone == false)
            {
                IsDone = true;
                foreach (TimeStampInfoIterator i in iterators)
                {
                    if (i.IsDone == false)
                    {
                        IsDone = false;
                        break;
                    }
                }

                if (IsDone == true)
                {
                    break;
                }

                currentDeltaCycle = int.MaxValue;

                foreach (TimeStampInfoIterator i in iterators)
                {
                    if ((i.IsDone == false) && (i.Current.Key < currentDeltaCycle))
                    {
                        currentDeltaCycle = i.Current.Key;
                    }
                }

                CompositeValue compValue = CompositeValue.CreateCompositeValue(groupModellingType, values);
                res.info.Add(currentDeltaCycle, compValue);

                for (int i = 0; i < iterators.Count; i++)
                {
                    TimeStampInfoIterator iter = iterators[i];
                    if (iter.Current.Key == currentDeltaCycle)
                    {
                        iter.MoveNext();
                        values[i] = iter.Current.Value;
                    }
                }
            }

            return(res);
        }