Ejemplo n.º 1
0
        public void EndToEnd_Add_Remove()
        {
            const string testFolder = "testAdd";

            if (Directory.Exists(testFolder))
            {
                Directory.Delete(testFolder, true);
            }

            Directory.CreateDirectory(testFolder);
            DroneDB.Init(testFolder);

            File.WriteAllText(Path.Join(testFolder, "file.txt"), "test");
            File.WriteAllText(Path.Join(testFolder, "file2.txt"), "test");
            File.WriteAllText(Path.Join(testFolder, "file3.txt"), "test");

            Assert.Throws <DDBException>(() => DroneDB.Add(testFolder, "invalid"));

            var entry = DroneDB.Add(testFolder, Path.Join(testFolder, "file.txt"))[0];

            entry.Path.Should().Be("file.txt");
            entry.Hash.Should().NotBeNullOrWhiteSpace();

            var entries = DroneDB.Add(testFolder, new[] { Path.Join(testFolder, "file2.txt"), Path.Join(testFolder, "file3.txt") });

            entries.Should().HaveCount(2);

            DroneDB.Remove(testFolder, Path.Combine(testFolder, "file.txt"));

            Assert.Throws <DDBException>(() => DroneDB.Remove(testFolder, "invalid"));
        }
Ejemplo n.º 2
0
        public void MetaList_Ok()
        {
            using var area = new TestArea("metaListOkTest");
            DroneDB.Init(area.TestFolder);

            DroneDB.MetaAdd(area.TestFolder, "annotations", "123");
            DroneDB.MetaAdd(area.TestFolder, "examples", "abc");
            DroneDB.MetaList(area.TestFolder).Should().HaveCount(2);
        }
Ejemplo n.º 3
0
        public void MetaAdd_Ok()
        {
            using var area = new TestArea("metaAddOkTest");
            DroneDB.Init(area.TestFolder);

            FluentActions.Invoking(() => DroneDB.MetaAdd(area.TestFolder, "test", "123")).Should()
            .Throw <DDBException>();    // Needs plural key
            // DroneDB.MetaAdd("metaAddTest", "", "tests", "123").Data.ToObject<int>().Should().Be(123);
        }
Ejemplo n.º 4
0
        public void Init_NonExistant_Exception()
        {
            Action act = () => DroneDB.Init("nonexistant");

            act.Should().Throw <DDBException>();

            act = () => DroneDB.Init(null);
            act.Should().Throw <DDBException>();
        }
Ejemplo n.º 5
0
        public void MetaRemove_Ok()
        {
            using var area = new TestArea("metaRemoveOkTest");
            DroneDB.Init(area.TestFolder);

            var id = DroneDB.MetaSet(area.TestFolder, "test", "123").Id;

            DroneDB.MetaRemove(area.TestFolder, "invalid").Should().Be(0);
            DroneDB.MetaRemove(area.TestFolder, id).Should().Be(1);
            DroneDB.MetaRemove(area.TestFolder, id).Should().Be(0);
        }
Ejemplo n.º 6
0
        public void MetaAdd_Json()
        {
            using var area = new TestArea("metaAddJsonTest");
            DroneDB.Init(area.TestFolder);

            var res = DroneDB.MetaAdd(area.TestFolder, "tests", "{\"test\": true}");

            JsonConvert.SerializeObject(res.Data).Should().Be("{\"test\":true}");
            res.Id.Should().NotBeNull();
            res.ModifiedTime.Should().BeCloseTo(DateTime.UtcNow, new TimeSpan(0, 0, 1));
        }
Ejemplo n.º 7
0
        public void MetaGet_Ok2()
        {
            using var area = new TestArea("metaGetOkTest");
            DroneDB.Init(area.TestFolder);

            DroneDB.MetaAdd(area.TestFolder, "tests", "{\"test\":true}");
            DroneDB.MetaAdd(area.TestFolder, "tests", "{\"test\":false}");
            DroneDB.MetaAdd(area.TestFolder, "tests", "{\"test\":null}");

            var res = JsonConvert.DeserializeObject <Meta[]>(DroneDB.MetaGet(area.TestFolder, "tests"));

            res.Should().HaveCount(3);
        }
Ejemplo n.º 8
0
        public void Init_EmptyFolder_Ok()
        {
            const string folder = "testInit";

            if (Directory.Exists(folder))
            {
                Directory.Delete(folder, true);
            }
            Directory.CreateDirectory(folder);

            DroneDB.Init(folder).Should().Contain(folder);
            Directory.Exists(Path.Join(folder, ".ddb")).Should().BeTrue();
        }
Ejemplo n.º 9
0
        public void MetaUnset_Ok()
        {
            using var area = new TestArea("metaUnsetOkTest");
            DroneDB.Init(area.TestFolder);

            var f = Path.Join(area.TestFolder, "test.txt");

            File.WriteAllText(f, null);

            DroneDB.Add(area.TestFolder, f);

            DroneDB.MetaSet(area.TestFolder, "abc", "[1,2,3]");
            DroneDB.MetaUnset(area.TestFolder, "abc", f).Should().Be(0);
            DroneDB.MetaUnset(area.TestFolder, "abc").Should().Be(1);
            DroneDB.MetaUnset(area.TestFolder, "abc").Should().Be(0);
        }
Ejemplo n.º 10
0
        public void MetaGet_Ok()
        {
            using var area = new TestArea("metaGetOkTest");
            DroneDB.Init(area.TestFolder);

            DroneDB.MetaSet(area.TestFolder, "abc", "true");

            FluentActions.Invoking(() => DroneDB.MetaGet(area.TestFolder, "nonexistant")).Should()
            .Throw <DDBException>();

            FluentActions.Invoking(() => DroneDB.MetaGet(area.TestFolder, "abc", "123")).Should()
            .Throw <DDBException>();

            JsonConvert.DeserializeObject <Meta>(DroneDB.MetaGet(area.TestFolder, "abc")).Data
            .Should().Be(true);
        }
Ejemplo n.º 11
0
        public void MetaSet_Ok()
        {
            using var area = new TestArea("metaSetOkTest");
            DroneDB.Init(area.TestFolder);

            var f = Path.Join(area.TestFolder, "test.txt");

            File.WriteAllText(f, null);

            DroneDB.Add(area.TestFolder, f);

            FluentActions.Invoking(() => DroneDB.MetaSet(area.TestFolder, "tests", "123", f)).Should()
            .Throw <DDBException>();    // Needs singular key

            DroneDB.MetaSet(area.TestFolder, "test", "abc", f).Data.Should().Be("abc");
            DroneDB.MetaSet(area.TestFolder, "test", "efg", f).Data.Should().Be("efg");
        }