コード例 #1
0
        private static void CatchAllWhereTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var i1 = 1;
            var i2 = 2;
            var q  = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a =>
                                                                                     (a.Indexed1 == "test1" && a.Indexed2 != "test2") ||
                                                                                     (i2 > i1 && i1 < i2 && i1 <= i2 && i2 >= i1));

            var manual = Filter(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), arg1 => Or(
                                    And(
                                        EqualsFn(
                                            Select(Arr("data", "indexed1"), arg1), "test1"
                                            ),
                                        Not(EqualsFn(Select(Arr("data", "Indexed2"), arg1), "test2"))
                                        ),
                                    And(
                                        And(
                                            And(
                                                GT(2, 1),
                                                LT(1, 2)
                                                ),
                                            LTE(1, 2)
                                            ),
                                        GTE(2, 1)
                                        )
                                    ));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #2
0
        public static async Task <T> Get <T>(this IFaunaClient client, string @ref)
        {
            var result = await client.Query(Language.Get(Ref(@ref)));

            return(typeof(IReferenceType).IsAssignableFrom(typeof(T))
                ? result.To <T>().Value
                : result.To <FaunaResult <T> >().Value.Data);
        }
コード例 #3
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, string index, params Expr[] args)
        {
            var result = await client.Query(If(Exists(Match(Index(index), args)),
                                               Map(Match(Index(index), args), a => Language.Update(a, obj.ToFaunaObj())),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
コード例 #4
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, string id)
        {
            var result = await client.Query(If(Exists(id),
                                               Language.Update(id, obj.ToFaunaObj()),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
コード例 #5
0
        private static void GetTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Get <ReferenceModel>("test1");

            var manual = Get(Ref("test1"));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #6
0
        private static void RefQueryTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>("ref1");

            var manual = Get(Ref("ref1"));

            q.Provider.Execute <object>(q.Expression);
            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #7
0
        public static IQueryable <T> Query <T>(this IFaunaClient client, Expression <Func <T, bool> > selector)
        {
            if (!(selector.Body is BinaryExpression binary))
            {
                throw new ArgumentException("Index selector must be binary expression.");
            }

            return(new FaunaQueryableData <T>(client, Map(WalkSelector(binary), arg0 => Language.Get(arg0))));
        }
コード例 #8
0
        private static void FromRefPaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q      = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, fromRef: "testRef");
            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, after: Ref("testRef"));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #9
0
        private static void DateTimePaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, timeStamp: new DateTime(2017, 1, 1));

            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, ts: Time(new DateTime(2017, 1, 1).ToString("O")));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #10
0
        private static void SingleBooleanSelectorTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test2");

            q.Provider.Execute <object>(q.Expression);
            var parsed = lastQuery;
            var manual = Map(Match(Index("index_1"), "test2"), arg0 => Get(arg0));

            Assert.IsTrue(parsed.Equals(manual));
        }
コード例 #11
0
        private static void AllOptionsPaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, timeStamp: new DateTime(2017, 1, 1), fromRef: "testRef", sortDirection: ListSortDirection.Descending);

            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, ts: Time(new DateTime(2017, 1, 1).ToString("O")), before: Ref("testRef"));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #12
0
        private static void CompositeWithTupleTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.CompositeIndex == Tuple.Create("test1", "test2"));

            var manual = Map(Match(Index("composite_index"), "test1", "test2"), arg0 => Get(arg0));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #13
0
        private static void UpdateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Id = "testId", Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Update(model).Result;

            var manual = Update(Ref(model.Id), model.ToFaunaObj());

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #14
0
        private static void CreateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Create(model).Result;

            var manual = Create(Ref(Class("reference_model"), 1), Obj("data", model.ToFaunaObj()));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #15
0
        private static void DeleteTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Id = "testId", Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Delete(model);

            var manual = Delete(Ref(model.Id));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #16
0
        private static void MemberInitTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a => a == new ReferenceModel {
                Indexed1 = "test1"
            });
            var manual = Filter(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), arg1 => EqualsFn(arg1, Obj("indexed1", "test1", "Indexed2", Null())));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #17
0
        private static void SelectStringConcatTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Select(a => a.Indexed1 + "concat");

            var manual = Map(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)),
                             arg1 => Concat(Arr(Select(Arr("data", "indexed1"), arg1), "concat")));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #18
0
        private static void UpsertTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Id = "testId", Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Upsert(model);

            var manual = If(Exists(Ref(model.Id)), Update(Ref(model.Id), model.ToFaunaObj()),
                            Create(Ref(Class("reference_model"), 1), model.ToFaunaObj()));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #19
0
        private static void UpsertCompositeIndexWithArgsTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Upsert(model, a => a.CompositeIndex, "test1", "test2");

            var matchExpr = Match(Index("composite_index"), "test1", "test2");
            var manual    = If(Exists(matchExpr), Map(matchExpr, a => Update(a, model.ToFaunaObj())), Create(model.GetClassRef(), model.ToFaunaObj()));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #20
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, Expression <Func <T, bool> > indices)
        {
            if (!(indices.Body is BinaryExpression binary))
            {
                throw new ArgumentException("Index selector must be binary expression.");
            }
            var selectorExpr = WalkSelector(binary);

            var result = await client.Query(If(Exists(selectorExpr), Map(selectorExpr, a => Language.Update(a, obj.ToFaunaObj())),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
コード例 #21
0
        public static void ChainedQueryTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a => a.Indexed1 == "test1").Select(a => a.Indexed1);

            var selectorManual = Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0));
            var filterManual   = Filter(selectorManual, arg1 => EqualsFn(Select(Arr("data", "indexed1"), arg1), "test1"));
            var selectManual   = Map(filterManual, arg2 => Select(Arr("data", "indexed1"), arg2));
            var manual         = selectManual;

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(manual.Equals(lastQuery));
        }
コード例 #22
0
        private static void UpsertBooleanExpressionTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var model = new ReferenceModel {
                Indexed1 = "test1", Indexed2 = "test2"
            };
            var q = client.Upsert(model, a => a.Indexed1 == "test1");

            var matchExpr = Match(Index("index_1"), "test1");
            var manual    = If(Exists(matchExpr), Map(matchExpr, a => Update(a, model.ToFaunaObj())),
                               Create(model.GetClassRef(), model.ToFaunaObj()));

            Assert.IsTrue(lastQuery.Equals(manual));
        }
コード例 #23
0
        private static void MultiSelectorTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q1 = client.Query <ReferenceModel>(a => a.Indexed1 == "test1" && a.Indexed2 == "test2");
            var q2 = client.Query <ReferenceModel>(a => a.Indexed1 == "test1" || a.Indexed2 == "test2");

            var manual1 = Map(Intersection(Match(Index("index_1"), "test1"), Match(Index("index_2"), "test2")), arg0 => Get(arg0));
            var manual2 = Map(Union(Match(Index("index_1"), "test1"), Match(Index("index_2"), "test2")), arg0 => Get(arg0));

            q1.Provider.Execute <object>(q1.Expression);
            Assert.IsTrue(lastQuery.Equals(manual1));

            q2.Provider.Execute <object>(q2.Expression);
            Assert.IsTrue(lastQuery.Equals(manual2));
        }
コード例 #24
0
        public static IQueryable <T> Query <T>(this IFaunaClient client, Expression <Func <T, object> > index, params Expr[] args)
        {
            if (!(index.Body is MemberExpression member))
            {
                throw new ArgumentException("Index selector must be a member.");
            }

            var propInfo  = member.GetPropertyInfo();
            var indexAttr = propInfo.GetCustomAttribute <IndexedAttribute>();

            if (indexAttr == null)
            {
                throw new ArgumentException("Can't use unindexed property as selector!", nameof(index));
            }
            var indexName = indexAttr.Name;

            return(client.Query <T>(indexName, args));
        }
コード例 #25
0
        internal static IDbContext CreateMappingContext(IFaunaClient mock)
        {
            var builder = DbContext.StartBuilding(mock);

            builder.RegisterMapping <ReferenceModelMapping>();
            builder.RegisterMapping <PrimitivesReferenceModelMapping>();
            builder.RegisterMapping <ReferenceTypesReferenceModelMapping>();
            builder.RegisterMapping <ValueTypesReferenceModelMapping>();
            builder.RegisterMapping <NamedPropertyModelMapping>();
            builder.RegisterMapping <ModelWithUnmappedReferenceMapping>();
            builder.RegisterMapping <SupportedCustomCollectionModelMapping>();
            builder.RegisterMapping <SupportedCustomCollectionModelMapping2>();
            builder.RegisterMapping <UnsupportedCustomCollectionModelMapping>();
            builder.RegisterMapping <UnsupportedCustomCollectionModelMapping2>();
            builder.RegisterMapping <UnsupportedCustomCollectionModelMapping3>();
            builder.RegisterMapping <IncludeModelMapping>();
            builder.RegisterMapping <ConstructorTestModelMapping>();
            return(builder.Build());
        }
コード例 #26
0
        internal static IDbContext CreateAttributeContext(IFaunaClient mock)
        {
            var builder = DbContext.StartBuilding(mock);

            builder.RegisterReferenceModel <ReferenceModel>();
            builder.RegisterReferenceModel <PrimitivesReferenceModel>();
            builder.RegisterReferenceModel <ReferenceTypesReferenceModel>();
            builder.RegisterReferenceModel <ValueTypesReferenceModel>();
            builder.RegisterReferenceModel <NamedPropertyModel>();
            builder.RegisterReferenceModel <ModelWithUnmappedReference>();
            builder.RegisterReferenceModel <SupportedCustomCollectionModel>();
            builder.RegisterReferenceModel <SupportedCustomCollectionModel2>();
            builder.RegisterReferenceModel <UnsupportedCustomCollectionModel>();
            builder.RegisterReferenceModel <UnsupportedCustomCollectionModel2>();
            builder.RegisterReferenceModel <UnsupportedCustomCollectionModel3>();
            builder.RegisterReferenceModel <IncludeModel>();
            builder.RegisterReferenceModel <ConstructorTestModel>();
            return(builder.Build());
        }
コード例 #27
0
 public static Task Delete(this IFaunaClient client, IReferenceType obj)
 {
     return(client.Delete(obj.Id));
 }
コード例 #28
0
 public static Task Delete(this IFaunaClient client, string id)
 {
     return(client.Query(Language.Delete(Ref(id))));
 }
コード例 #29
0
 public DbContextBuilder(IFaunaClient client)
 {
     _client = client;
 }
コード例 #30
0
 public static Task <T> Upsert <T>(this IFaunaClient client, T obj) where T : IReferenceType
 {
     return(client.Upsert(obj, obj.Id));
 }