Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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"
            });
        }
        public void AddArangoConnectionString()
        {
            var collection = new ServiceCollection();

            collection.AddArango(UniqueTestRealm());

            var serviceProvider = collection.BuildServiceProvider();

            Arango = serviceProvider.GetRequiredService <IArangoContext>();

            Arango.GetVersionAsync();
        }
        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);
        }