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));
        }
        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));
        }
        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));
        }
Ejemplo n.º 4
0
 public static Task <T> Upsert <T>(this IFaunaClient client, T obj) where T : IReferenceType
 {
     return(client.Upsert(obj, obj.Id));
 }