Esempio n. 1
0
        public void UpsertWithFor()
        {
            var db = DatabaseGenerator.Get();

            var query = db.Query <Host>()
                        .Upsert(h => new Host {
                Key = h.Key
            },
                                h => new Host {
            },
                                (h, old) => new Host {
                Tags = AQL.Append(h.Tags, old.Tags)
            });

            var queryData = query.GetQueryData();

            Assert.Equal(queryData.Query.RemoveSpaces(), @"
for `h` in `hosts`
upsert { `_key` : `h`.`_key` }
insert @P1
update { `tags` : append( `h`.`tags` , `OLD` .`tags` ) }
in `hosts`
".RemoveSpaces());

            ObjectUtility.AssertSerialize(queryData.BindVars[0].Value, new { }, db);
        }
        public void UpsertOnCollection()
        {
            // insert a host
            db.Insert <Host>(new Host {
                Key = "123", Tags = new string[] { "1", "2", "3" }
            });

            var result = db.Query <Host>()
                         .Upsert(h => new Host {
                Key = h.Key
            },
                                 h => new Host {
            },
                                 (h, old) => new Host {
                Tags = AQL.Append(h.Tags, old.Tags)
            }).Select((n, o) => n).ToList();

            Assert.Equal(result.Count, 1);
            Assert.Equal(result[0].Tags.Count, 6);
            Assert.Equal(result[0].Tags.Count(t => t == "2"), 2);
        }