[Test] public void TestImplicitExpr()
 {
     Assert.AreEqual(LongV.Of(10), (Expr)10);
     Assert.AreEqual(LongV.Of(10), (Expr)10L);
     Assert.AreEqual(BooleanV.True, (Expr)true);
     Assert.AreEqual(BooleanV.False, (Expr)false);
     Assert.AreEqual(DoubleV.Of(3.14), (Expr)3.14);
     Assert.AreEqual(StringV.Of("a string"), (Expr)"a string");
     Assert.AreEqual(StringV.Of("create"), (Expr)ActionType.Create);
     Assert.AreEqual(StringV.Of("delete"), (Expr)ActionType.Delete);
     Assert.AreEqual(StringV.Of("second"), (Expr)TimeUnit.Second);
     Assert.AreEqual(StringV.Of("millisecond"), (Expr)TimeUnit.Millisecond);
     Assert.AreEqual(StringV.Of("microsecond"), (Expr)TimeUnit.Microsecond);
     Assert.AreEqual(StringV.Of("nanosecond"), (Expr)TimeUnit.Nanosecond);
     Assert.AreEqual(DateV.Of("2000-01-01"), (Expr) new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc));
     Assert.AreEqual(DateV.Of("2000-01-01"), (Expr) new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero));
     Assert.AreEqual(TimeV.Of("2000-01-01T01:01:01.123Z"), (Expr) new DateTime(2000, 1, 1, 1, 1, 1, 123, DateTimeKind.Utc));
     Assert.AreEqual(TimeV.Of("2000-01-01T01:01:01.123Z"), (Expr) new DateTimeOffset(2000, 1, 1, 1, 1, 1, 123, TimeSpan.Zero));
     Assert.AreEqual(NullV.Instance, (Expr)(string)null);
     Assert.AreEqual(
         ObjectV.With("name", "foo", "count", 42),
         (Expr) new Dictionary <string, Expr>()
     {
         { "name", "foo" }, { "count", 42 }
     });
 }
 public void TestEnumTypes()
 {
     Assert.AreEqual(StringV.Of("x86_32"), Encode(CpuTypes.X86));
     Assert.AreEqual(StringV.Of("x86_64"), Encode(CpuTypes.X86_64));
     Assert.AreEqual(StringV.Of("ARM"), Encode(CpuTypes.ARM));
     Assert.AreEqual(StringV.Of("MIPS"), Encode(CpuTypes.MIPS));
 }
Exemple #3
0
        [Test] public void TestArray()
        {
            AssertJsonEqual(ArrayV.Of(LongV.Of(1), StringV.Of("a string"), DoubleV.Of(3.14), BooleanV.True, NullV.Instance),
                            "[1, \"a string\", 3.14, true, null]");

            AssertJsonEqual(ArrayV.Empty, "[]");
        }
Exemple #4
0
        [Test] public void TestObjectLiteral()
        {
            AssertJsonEqual(ObjectV.With("@name", StringV.Of("Test")),
                            "{\"@obj\":{\"@name\":\"Test\"}}");

            AssertJsonEqual(ObjectV.Empty, "{\"@obj\":{}}");
        }
        public void TestPrimitive()
        {
            Assert.AreEqual(StringV.Of("a string"), Encode("a string"));

            Assert.AreEqual(BooleanV.True, Encode(true));
            Assert.AreEqual(BooleanV.False, Encode(false));

            Assert.AreEqual(NullV.Instance, Encode((object)null));

            Assert.AreEqual(new BytesV(1, 2, 3, 4), Encode(new byte[] { 1, 2, 3, 4 }));

            Assert.AreEqual(new DateV("2001-01-01"), Encode(new DateTime(2001, 1, 1)));
            Assert.AreEqual(new TimeV("2000-01-01T01:10:30.123Z"), Encode(new DateTime(2000, 1, 1, 1, 10, 30, 123)));

            Assert.AreEqual(new DateV("2001-01-01"), Encode(new DateTimeOffset(2001, 1, 1, 0, 0, 0, TimeSpan.Zero)));
            Assert.AreEqual(new TimeV("2000-01-01T01:10:30.123Z"), Encode(new DateTimeOffset(2000, 1, 1, 1, 10, 30, 123, TimeSpan.Zero)));

            //float point
            Assert.AreEqual(DoubleV.Of((float)3.14), Encode((float)3.14));
            Assert.AreEqual(DoubleV.Of(3.14), Encode((double)3.14));
            Assert.AreEqual(DoubleV.Of(3.14), Encode((decimal)3.14));

            //signed values
            Assert.AreEqual(LongV.Of(10), Encode((sbyte)10));
            Assert.AreEqual(LongV.Of(10), Encode((short)10));
            Assert.AreEqual(LongV.Of(10), Encode((int)10));
            Assert.AreEqual(LongV.Of(10), Encode((long)10));

            //unsigned values
            Assert.AreEqual(LongV.Of(10), Encode((char)10));
            Assert.AreEqual(LongV.Of(10), Encode((byte)10));
            Assert.AreEqual(LongV.Of(10), Encode((ushort)10));
            Assert.AreEqual(LongV.Of(10), Encode((uint)10));
            Assert.AreEqual(LongV.Of(10), Encode((ulong)10));
        }
Exemple #6
0
        public async Task TestCallFunction()
        {
            var query = QueryV.Of((x, y) => Concat(Arr(x, "/", y)));

            await client.Query(CreateFunction(Obj("name", "my_concat", "body", query)));

            var result = await client.Query(Call(new FunctionV("my_concat"), "a", "b"));

            Assert.AreEqual(StringV.Of("a/b"), result);
        }
Exemple #7
0
        [Test] public void TestNestedObject()
        {
            var nested = ObjectV.With("foo", ObjectV.With("bar", "a string"));

            Assert.AreEqual(StringV.Of("a string"),
                            nested.Get(Field.At("foo", "bar")));

            Assert.Throws(typeof(InvalidOperationException),
                          () => nested.Get(Field.At("foo", "nonexistent")),
                          "Cannot find path \"foo/nonexistent\". Object key \"nonexistent\" not found");
        }
Exemple #8
0
        public void TestEnumTypes()
        {
            Assert.AreEqual(CpuTypes.X86, Decode <CpuTypes>(StringV.Of("x86_32")));
            Assert.AreEqual(CpuTypes.X86_64, Decode <CpuTypes>(StringV.Of("x86_64")));
            Assert.AreEqual(CpuTypes.ARM, Decode <CpuTypes>(StringV.Of("ARM")));
            Assert.AreEqual(CpuTypes.MIPS, Decode <CpuTypes>(StringV.Of("MIPS")));

            var ex = Assert.Throws <InvalidOperationException>(() => Decode <CpuTypes>(StringV.Of("AVR")));

            Assert.AreEqual("Enumeration value 'AVR' not found in Test.DecoderTest+CpuTypes", ex.Message);
        }
Exemple #9
0
        [Test] public void TestObjectKey()
        {
            var obj = ObjectV.With("foo", "bar");

            Assert.AreEqual(StringV.Of("bar"),
                            obj.Get(Field.At("foo")));

            Assert.AreEqual(None(),
                            obj.GetOption(Field.At("nonexistent")));

            Assert.Throws(typeof(InvalidOperationException),
                          () => obj.Get(Field.At("nonexistent")),
                          "Cannot find path \"nonexistent\". Object key \"nonexistent\" not found");
        }
Exemple #10
0
 [Test] public void TestImplicit()
 {
     Assert.AreEqual(LongV.Of(10), (Expr)10);
     Assert.AreEqual(LongV.Of(10), (Expr)10L);
     Assert.AreEqual(BooleanV.True, (Expr)true);
     Assert.AreEqual(BooleanV.False, (Expr)false);
     Assert.AreEqual(DoubleV.Of(3.14), (Expr)3.14);
     Assert.AreEqual(StringV.Of("a string"), (Expr)"a string");
     Assert.AreEqual(StringV.Of("create"), (Expr)ActionType.Create);
     Assert.AreEqual(StringV.Of("delete"), (Expr)ActionType.Delete);
     Assert.AreEqual(StringV.Of("second"), (Expr)TimeUnit.Second);
     Assert.AreEqual(StringV.Of("millisecond"), (Expr)TimeUnit.Millisecond);
     Assert.AreEqual(StringV.Of("microsecond"), (Expr)TimeUnit.Microsecond);
     Assert.AreEqual(StringV.Of("nanosecond"), (Expr)TimeUnit.Nanosecond);
     Assert.AreEqual(NullV.Instance, (Expr)(string)null);
 }
Exemple #11
0
 [Test] public void TestExplicit()
 {
     Assert.AreEqual(10, (int)LongV.Of(10));
     Assert.AreEqual(10L, (long)LongV.Of(10));
     Assert.AreEqual(true, (bool)BooleanV.True);
     Assert.AreEqual(false, (bool)BooleanV.False);
     Assert.AreEqual(3.14, (double)DoubleV.Of(3.14));
     Assert.AreEqual("a string", (string)StringV.Of("a string"));
     Assert.AreEqual(ActionType.Create, (ActionType)StringV.Of("create"));
     Assert.AreEqual(ActionType.Delete, (ActionType)StringV.Of("delete"));
     Assert.AreEqual(TimeUnit.Second, (TimeUnit)StringV.Of("second"));
     Assert.AreEqual(TimeUnit.Millisecond, (TimeUnit)StringV.Of("millisecond"));
     Assert.AreEqual(TimeUnit.Microsecond, (TimeUnit)StringV.Of("microsecond"));
     Assert.AreEqual(TimeUnit.Nanosecond, (TimeUnit)StringV.Of("nanosecond"));
     Assert.AreEqual(null, (string)(Expr)NullV.Instance);
 }
Exemple #12
0
        [Test] public void TestArrayIndex()
        {
            var array = ArrayV.Of("a string", 10);

            Assert.AreEqual(StringV.Of("a string"),
                            array.Get(Field.At(0)));

            Assert.AreEqual(LongV.Of(10),
                            array.Get(Field.At(1)));

            Assert.AreEqual(None(),
                            array.GetOption(Field.At(1234)));

            Assert.Throws(typeof(InvalidOperationException),
                          () => array.Get(Field.At(1234)),
                          "Cannot find path \"1234\". Array index \"1234\" not found");
        }
Exemple #13
0
        [Test] public void TestSetRef()
        {
            var expected = new SetRefV(new Dictionary <string, Value> {
                { "match", new RefV(id: "spells_by_element", collection: Native.INDEXES) },
                { "terms", StringV.Of("fire") }
            });

            AssertJsonEqual(expected,
                            "{" +
                            "  \"@set\": {" +
                            "    \"match\": { \"@ref\": {\"id\": \"spells_by_element\", \"collection\": {\"@ref\": {\"id\": \"indexes\"} } } }," +
                            "    \"terms\": \"fire\"" +
                            "  }" +
                            "}");

            AssertJsonEqual(new SetRefV(new Dictionary <string, Value>()),
                            "{\"@set\":{}}");
        }
 [Test] public void TestExplicitValue()
 {
     Assert.AreEqual(10, (int)LongV.Of(10));
     Assert.AreEqual(10L, (long)LongV.Of(10));
     Assert.AreEqual(true, (bool)BooleanV.True);
     Assert.AreEqual(false, (bool)BooleanV.False);
     Assert.AreEqual(3.14, (double)DoubleV.Of(3.14));
     Assert.AreEqual("a string", (string)StringV.Of("a string"));
     Assert.AreEqual(ActionType.Create, (ActionType)StringV.Of("create"));
     Assert.AreEqual(ActionType.Delete, (ActionType)StringV.Of("delete"));
     Assert.AreEqual(TimeUnit.Second, (TimeUnit)StringV.Of("second"));
     Assert.AreEqual(TimeUnit.Millisecond, (TimeUnit)StringV.Of("millisecond"));
     Assert.AreEqual(TimeUnit.Microsecond, (TimeUnit)StringV.Of("microsecond"));
     Assert.AreEqual(TimeUnit.Nanosecond, (TimeUnit)StringV.Of("nanosecond"));
     Assert.AreEqual(new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc), (DateTime)DateV.Of("2000-01-01"));
     Assert.AreEqual(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), (DateTimeOffset)DateV.Of("2000-01-01"));
     Assert.AreEqual(new DateTime(2000, 1, 1, 1, 1, 1, 123, DateTimeKind.Utc), (DateTime)TimeV.Of("2000-01-01T01:01:01.123Z"));
     Assert.AreEqual(new DateTimeOffset(2000, 1, 1, 1, 1, 1, 123, TimeSpan.Zero), (DateTimeOffset)TimeV.Of("2000-01-01T01:01:01.123Z"));
 }
 public void TestImplicitValue()
 {
     Assert.AreEqual(LongV.Of(10), (Value)10);
     Assert.AreEqual(LongV.Of(10), (Value)10L);
     Assert.AreEqual(BooleanV.True, (Value)true);
     Assert.AreEqual(BooleanV.False, (Value)false);
     Assert.AreEqual(DoubleV.Of(3.14), (Value)3.14);
     Assert.AreEqual(StringV.Of("a string"), (Value)"a string");
     Assert.AreEqual(StringV.Of("create"), (Value)ActionType.Create);
     Assert.AreEqual(StringV.Of("delete"), (Value)ActionType.Delete);
     Assert.AreEqual(StringV.Of("second"), (Value)TimeUnit.Second);
     Assert.AreEqual(StringV.Of("millisecond"), (Value)TimeUnit.Millisecond);
     Assert.AreEqual(StringV.Of("microsecond"), (Value)TimeUnit.Microsecond);
     Assert.AreEqual(StringV.Of("nanosecond"), (Value)TimeUnit.Nanosecond);
     Assert.AreEqual(DateV.Of("2000-01-01"), (Value) new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc));
     Assert.AreEqual(DateV.Of("2000-01-01"), (Value) new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero));
     Assert.AreEqual(TimeV.Of("2000-01-01T01:01:01.123Z"), (Value) new DateTime(2000, 1, 1, 1, 1, 1, 123, DateTimeKind.Utc));
     Assert.AreEqual(TimeV.Of("2000-01-01T01:01:01.123Z"), (Value) new DateTimeOffset(2000, 1, 1, 1, 1, 1, 123, TimeSpan.Zero));
     Assert.AreEqual(NullV.Instance, (Value)(string)null);
 }
Exemple #16
0
 [Test] public void TestString()
 {
     AssertJsonEqual(StringV.Of("a string"), "\"a string\"");
 }
Exemple #17
0
        public async Task TeststreamEventsOnDocumentReferenceWithOptInFields()
        {
            Value createdInstance = await adminClient.Query(
                Create(await RandomCollection(),
                       Obj("data",
                           Obj("testField", "testValue0"))));

            var docRef = createdInstance.At("ref");

            var fields = new List <EventField> {
                EventField.ActionField,
                EventField.DiffField,
                EventField.DocumentField,
                EventField.PrevField
            };

            var provider = await adminClient.Stream(docRef, fields);

            var done = new TaskCompletionSource <object>();

            List <Value> events = new List <Value>();

            var monitor = new StreamingEventMonitor(
                value =>
            {
                events.Add(value);
                if (events.Count == 4)
                {
                    provider.Complete();
                }
                else
                {
                    provider.RequestData();
                }
            },
                ex => { done.SetException(ex); },
                () => { done.SetResult(null); }
                );

            // subscribe to data provider
            monitor.Subscribe(provider);

            // push 3 updates
            await adminClient.Query(Update(docRef, Obj("data", Obj("testField", "testValue1"))));

            await adminClient.Query(Update(docRef, Obj("data", Obj("testField", "testValue2"))));

            await adminClient.Query(Update(docRef, Obj("data", Obj("testField", "testValue3"))));

            // blocking until we receive all the events
            await done.Task;

            // clear the subscription
            monitor.Unsubscribe();

            Value startEvent = events[0];

            Assert.AreEqual("start", startEvent.At("type").To <string>().Value);

            Value e1 = events[1];

            Assert.AreEqual("version", e1.At("type").To <string>().Value);
            Assert.AreEqual("update", e1.At("event", "action").To <string>().Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue1")),
                ((ObjectV)e1.At("event", "diff", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue1")),
                ((ObjectV)e1.At("event", "document", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue0")),
                ((ObjectV)e1.At("event", "prev", "data")).Value);

            Value e2 = events[2];

            Assert.AreEqual("version", e2.At("type").To <string>().Value);
            Assert.AreEqual("update", e2.At("event", "action").To <string>().Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue2")),
                ((ObjectV)e2.At("event", "diff", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue2")),
                ((ObjectV)e2.At("event", "document", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue1")),
                ((ObjectV)e2.At("event", "prev", "data")).Value);

            Value e3 = events[3];

            Assert.AreEqual("version", e3.At("type").To <string>().Value);
            Assert.AreEqual("update", e3.At("event", "action").To <string>().Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue3")),
                ((ObjectV)e3.At("event", "diff", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue3")),
                ((ObjectV)e3.At("event", "document", "data")).Value);
            Assert.AreEqual(
                FaunaDB.Collections.ImmutableDictionary.Of("testField", StringV.Of("testValue2")),
                ((ObjectV)e3.At("event", "prev", "data")).Value);
        }