Example #1
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;
 }
Example #2
0
        private static ValueExpression splitIntoComposite(string text)
        {
            var composite = CompositeValue.Parse(text);

            // If there's only one component, this really was a single value
            if (composite.Components.Length == 1)
            {
                return(composite.Components[0]);
            }
            else
            {
                return(composite);
            }
        }
Example #3
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 #4
0
        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);
            }
        }
Example #5
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());
		}