Exemplo n.º 1
0
        public async Task QueryIntegerContains()
        {
            await Arango.CreateDatabaseAsync("test");

            await Arango.CreateCollectionAsync("test", "test", ArangoCollectionType.Document);

            await Arango.CreateDocumentsAsync("test", "test", new List <Entity>
            {
                new Entity {
                    Value = 1
                },
                new Entity {
                    Value = 2
                },
                new Entity {
                    Value = 3
                }
            });

            var select = new List <int> {
                1, 2
            };

            var res = await Arango.QueryAsync <Entity>("test", $"FOR e IN test FILTER e.Value IN {select} RETURN e");

            Assert.Equal(2, res.Count);
        }
Exemplo n.º 2
0
        public async Task CreateReplaceMode()
        {
            if (await Arango.GetVersionAsync() < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", "test", ArangoCollectionType.Document);

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key   = "abc",
                Value = "c"
            }, overwriteMode : ArangoOverwriteMode.Replace);

            var obj = await Arango.Query.SingleOrDefaultAsync <JObject>("test", "test", $"x._key == {"abc"}");

            Assert.Null(obj["Name"]);
            Assert.Equal("c", obj["Value"]);
        }
Exemplo n.º 3
0
        public async Task SingleOrDefault()
        {
            var p = await Arango.Query <Project>("test")
                    .SingleOrDefaultAsync(x => x.Name == "Project A");

            Assert.Equal("Project A", p.Name);
        }
Exemplo n.º 4
0
        public async Task CreateReplaceMode(string serializer)
        {
            await SetupAsync(serializer);

            if (await Arango.GetVersionAsync() < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", "test", ArangoCollectionType.Document);

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key   = "abc",
                Value = "c"
            }, overwriteMode : ArangoOverwriteMode.Replace);

            var obj = await Arango.Query.SingleOrDefaultAsync <Dictionary <string, string> >("test", "test", $"x._key == {"abc"}");

            Assert.DoesNotContain("Name", obj.Keys);
            Assert.Equal("c", obj["Value"]);
        }
Exemplo n.º 5
0
        public async Task CreateConflictMode(string serializer)
        {
            await SetupAsync(serializer);

            if ((await Arango.GetVersionAsync()).SemanticVersion < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", "test", ArangoCollectionType.Document);

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            var exception = await Assert.ThrowsAsync <ArangoException>(async() =>
            {
                await Arango.Document.CreateAsync("test", "test", new
                {
                    Key   = "abc",
                    Value = "c"
                }, overwriteMode: ArangoOverwriteMode.Conflict);
            });

            Assert.Contains("unique constraint", exception.Message);
            Assert.Collection <ArangoError>(exception.Errors,
                                            error => Assert.Equal(ArangoErrorCode.ErrorArangoUniqueConstraintViolated, error.ErrorNumber)
                                            );
        }
Exemplo n.º 6
0
        public async Task CreateUpdateMode(string serializer)
        {
            await SetupAsync(serializer);

            if ((await Arango.GetVersionAsync()).SemanticVersion < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", "test", ArangoCollectionType.Document);

            var createRes = await Arango.Document.CreateAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            var res = await Arango.Document.CreateAsync("test", "test", new
            {
                Key   = "abc",
                Value = "c"
            }, overwriteMode : ArangoOverwriteMode.Update);

            Assert.Equal(createRes.Id, res.Id);
            Assert.Equal(createRes.Key, res.Key);
            Assert.Equal(createRes.Revision, res.OldRevision);

            var obj = await Arango.Query.SingleOrDefaultAsync <Dictionary <string, string> >("test", "test", $"x._key == {"abc"}");

            Assert.Equal("a", obj["Name"]);
            Assert.Equal("c", obj["Value"]);
            Assert.Equal(res.Id, obj["_id"]);
            Assert.Equal(res.Key, obj["_key"]);
            Assert.Equal(res.Revision, obj["_rev"]);
        }
Exemplo n.º 7
0
        public async Task FilterOrder()
        {
            var q = Arango.Query <Project>("test")
                    .Where(x => (x.Name == "Project A" || x.Name == "Project B") && x.Budget <= 0);

            Assert.Equal("FOR `x` IN `Project`  FILTER  (  (  (  `x`.`Name`  ==  @P1  )  OR  (  `x`.`Name`  ==  @P2  )  )  AND  (  `x`.`Budget`  <=  @P3  )  )  RETURN   `x`", q.ToAql().aql.Trim());
        }
Exemplo n.º 8
0
        public async Task CreateConflictMode(string serializer)
        {
            await SetupAsync(serializer);

            if (await Arango.GetVersionAsync() < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", "test", ArangoCollectionType.Document);

            await Arango.Document.CreateAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            var ex = await Assert.ThrowsAsync <ArangoException>(async() =>
            {
                await Arango.Document.CreateAsync("test", "test", new
                {
                    Key   = "abc",
                    Value = "c"
                }, overwriteMode: ArangoOverwriteMode.Conflict);
            });

            Assert.Contains("unique constraint", ex.Message);
        }
Exemplo n.º 9
0
        public async Task Schema(string serializer)
        {
            await SetupAsync(serializer);

            if ((await Arango.GetVersionAsync()).SemanticVersion < Version.Parse("3.7"))
            {
                return;
            }

            await Arango.Collection.CreateAsync("test", new ArangoCollection
            {
                Name   = "test",
                Type   = ArangoCollectionType.Document,
                Schema = new ArangoSchema
                {
                    Rule = new
                    {
                        type       = "object",
                        properties = new
                        {
                            name = new { type = "string" }
                        },
                        required = new[] { "name" }
                        //additionalProperties = true
                    }
                }
            });

            await Arango.Document.CreateAsync("test", "test", new
            {
                name = "test",
            });

            var exception = await Assert.ThrowsAsync <ArangoException>(async() =>
            {
                await Arango.Document.CreateAsync("test", "test", new
                {
                    name  = 2,
                    name2 = "test"
                });
            });

            Assert.Collection <ArangoError>(exception.Errors,
                                            error => Assert.Equal(ArangoErrorCode.ErrorValidationFailed, error.ErrorNumber)
                                            );

            await Arango.Collection.UpdateAsync("test", "test", new ArangoCollectionUpdate
            {
                Schema = null
            });

            await Task.Delay(5000);

            await Arango.Document.CreateAsync("test", "test", new
            {
                name  = 2,
                name2 = "test"
            });
        }
Exemplo n.º 10
0
 public async Task SingleException()
 {
     await Assert.ThrowsAsync <InvalidOperationException>(async() =>
     {
         await Arango.Query <Project>("test")
         .SingleAsync(x => x.Name == "Nope");
     });
 }
Exemplo n.º 11
0
        public async Task StreamTransaction()
        {
            await Arango.CreateCollectionAsync("test", "test", ArangoCollectionType.Document);

            var t1 = await Arango.BeginTransactionAsync("test", new ArangoTransaction
            {
                Collections = new ArangoTransactionScope
                {
                    Write = new List <string> {
                        "test"
                    }
                }
            });

            await Arango.CreateDocumentsAsync(t1, "test", new List <Entity>
            {
                new Entity {
                    Value = 1
                },
                new Entity {
                    Value = 2
                },
                new Entity {
                    Value = 3
                }
            });

            await Arango.CommitTransactionAsync(t1);

            Assert.Equal(3, (await Arango.FindAsync <Entity>("test", "test", $"true")).Count);

            var t2 = await Arango.BeginTransactionAsync("test", new ArangoTransaction
            {
                Collections = new ArangoTransactionScope
                {
                    Write = new List <string> {
                        "test"
                    }
                }
            });

            await Arango.CreateDocumentsAsync(t2, "test", new List <Entity>
            {
                new Entity {
                    Value = 1
                },
                new Entity {
                    Value = 2
                },
                new Entity {
                    Value = 3
                }
            });

            await Arango.AbortTransactionAsync(t2);

            Assert.Equal(3, (await Arango.FindAsync <Entity>("test", "test", $"true")).Count);
        }
Exemplo n.º 12
0
        public async Task Let()
        {
            var q =
                from p in Arango.Query <Project>("test")
                let clients = (from c in Arango.Query <Client>() select c.Key)
                              select new { p.Name, Clients = Aql.As <string[]>(clients) };

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            _output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 13
0
        public async Task MultiFilter()
        {
            var q = Arango.Query <Project>("test")
                    .Where(x => x.Name == "Project A")
                    .OrderBy(x => x.Name)
                    .Where(x => x.Name == "Project B")
                    .OrderByDescending(x => x.Name)
                    .Skip(0).Take(1);

            Assert.Equal("FOR `x` IN `Project`  FILTER  (  `x`.`Name`  ==  @P1  )  SORT  `x`.`Name`  ASC   FILTER  (  `x`.`Name`  ==  @P2  )  SORT  `x`.`Name`  DESC    LIMIT  @P3   ,  @P4  RETURN   `x`", q.ToAql().aql.Trim());
        }
        public void AddArangoConnectionString()
        {
            var collection = new ServiceCollection();

            collection.AddArango(UniqueTestRealm());

            var serviceProvider = collection.BuildServiceProvider();

            Arango = serviceProvider.GetRequiredService <IArangoContext>();

            Arango.GetVersionAsync();
        }
Exemplo n.º 15
0
        public async Task MathAbs()
        {
            var q = Arango.Query <Project>("test")
                    .Select(x => new
            {
                x.Key,
                Budget = Math.Abs(x.Budget)
            });

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            //_output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 16
0
        public async Task Ternary()
        {
            var q = Arango.Query <Project>("test")
                    .Select(x => new
            {
                x.Key,
                Name = x.Name == "Test" ? "-" : x.Name
            });

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            //_output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 17
0
        public async Task Update()
        {
            var q = Arango.Query <Project>("test")
                    .Where(x => x.Name == "Project A")
                    .Update(x => new
            {
                x.Key,
                Name = Aql.Concat(x.Name, "2")
            }, x => x.Key);

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            _output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 18
0
        public async Task GroupBy()
        {
            var q = Arango.Query <Project>("test")
                    .GroupBy(y => y.ParentKey)
                    .Select(x => new
            {
                Parent = x.Key,
                Max    = x.Max(y => y.Budget)
            });

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            //_output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 19
0
        public async Task SelectDocument()
        {
            var q = Arango.Query <Project>("test")
                    .Where(x => x.Name == "Project A")
                    .Select(x => new
            {
                x.Key,
                x.Name,
                ClientName = Aql.Document <Client>("Client", x.ClientKey).Name
            });

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            _output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
Exemplo n.º 20
0
        public async Task AnalyzersViews()
        {
            var analyzers = await Arango.ListAnalyzersAsync("test");

            await Arango.CreateAnalyzerAsync("test", new ArangoAnalyzer
            {
                Name       = "text_de_nostem",
                Type       = "text",
                Properties = new ArangoAnalyzerProperties
                {
                    Locale    = "de.utf-8",
                    Case      = "lower",
                    Accent    = false,
                    Stopwords = new List <string>(),
                    Stemming  = false
                },
                Features = new List <string> {
                    "position", "norm", "frequency"
                }
            });


            await Arango.CreateCollectionAsync("test", "collection", ArangoCollectionType.Document);

            await Arango.CreateViewAsync("test", new ArangoView
            {
                Name  = "TestView",
                Links = new Dictionary <string, ArangoLinkProperty>
                {
                    ["collection"] = new ArangoLinkProperty
                    {
                        Fields = new Dictionary <string, ArangoLinkProperty>
                        {
                            ["Name"] = new ArangoLinkProperty
                            {
                                Analyzers = new List <string> {
                                    "text_de_nostem"
                                }
                            }
                        }
                    }
                }
            });

            await Arango.DropViewsAsync("test");

            await Arango.DeleteAnalyzerAsync("test", "text_de_nostem", true);
        }
Exemplo n.º 21
0
        public async Task Collection()
        {
            await Arango.CreateCollectionAsync("test", "test", ArangoCollectionType.Document);

            await Arango.CreateDocumentAsync("test", "test", new
            {
                Key  = "abc",
                Name = "a"
            });

            var res = await Arango.UpdateDocumentAsync("test", "test", new
            {
                Key  = "abc",
                Name = "c"
            }, returnNew : true, returnOld : true);
        }
Exemplo n.º 22
0
        public async Task ListContains()
        {
            var list = new List <string> {
                "CA", "CB"
            }.ToArray();

            //var q = Arango.Query<Project>("test")
            //    .Where(x => list.Contains(x.ClientKey));

            var q = Arango.Query <Project>("test")
                    .Where(x => Aql.Position(list, x.ClientKey));

            _output.WriteLine(q.ToAql().aql);
            _output.WriteLine("");
            _output.WriteLine(JsonConvert.SerializeObject(await q.ToListAsync(), Formatting.Indented));
        }
        public void AddArangoConfigurationCallback()
        {
            var collection = new ServiceCollection();

            collection.AddArango((sp, config) =>
            {
                config.ConnectionString = UniqueTestRealm();
                config.BatchSize        = 1337;
            });

            var serviceProvider = collection.BuildServiceProvider();

            Arango = serviceProvider.GetRequiredService <IArangoContext>();

            Arango.GetVersionAsync();

            Assert.Equal(1337, Arango.Configuration.BatchSize);
        }
Exemplo n.º 24
0
        public async Task Collection()
        {
            await Arango.CreateCollectionAsync("test", new ArangoCollection
            {
                Name       = "test",
                Type       = ArangoCollectionType.Document,
                KeyOptions = new ArangoKeyOptions
                {
                    Type          = ArangoKeyType.Padded,
                    AllowUserKeys = false
                }
            });

            await Arango.CreateDocumentAsync("test", "test", new
            {
                Name = "test"
            });
        }
Exemplo n.º 25
0
 public List<object> FullText(Arango.Client.API.SimpleQueryOperation.FullTextRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/fulltext");
 }
Exemplo n.º 26
0
 public Document FirstExample(Arango.Client.API.SimpleQueryOperation.ByExampleRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return GetDocument(query, "/first-example");
 }
Exemplo n.º 27
0
 public List<object> ByExampleSkipList(Arango.Client.API.SimpleQueryOperation.ByExampleIndexRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/by-example-skiplist");
 }
Exemplo n.º 28
0
 public List<object> ByConditionBitArray(Arango.Client.API.SimpleQueryOperation.ByConditionIndexRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/by-condition-bitarray");
 }
Exemplo n.º 29
0
 public List<object> All(Arango.Client.API.SimpleQueryOperation.AllRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/all");
 }
Exemplo n.º 30
0
 public List<object> Within(Arango.Client.API.SimpleQueryOperation.WithinRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/within");
 }
Exemplo n.º 31
0
 public List<object> Last(Arango.Client.API.SimpleQueryOperation.FirstLastRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return Execute(query, "/last");
 }
Exemplo n.º 32
0
 public int UpdateByExample(Arango.Client.API.SimpleQueryOperation.UpdateByExampleRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return GetDocumentIntFieldValue(query, "/update-by-example", "updated");
 }
Exemplo n.º 33
0
 public Document Any(Arango.Client.API.SimpleQueryOperation.AnyRequest request)
 {
     var query = JsonConvert.SerializeObject(request);
     return GetDocument(query, "/any");
 }