Exemple #1
0
        private static FdbPath RemoveIndirection(FdbPath path)
        {
            Contract.Requires(path.IsAbsolute, "Path must be absolute");

            var segments = new Stack <FdbPathSegment>(path.Count);

            foreach (var seg in path.Segments.Span)
            {
                if (seg.Name == ".")
                {
                    continue;
                }
                if (seg.Name == "..")
                {
                    if (segments.Count == 0)
                    {
                        throw new InvalidOperationException("The specified path is invalid.");
                    }
                    segments.Pop();
                    continue;
                }
                segments.Push(seg);
            }
            return(FdbPath.Absolute(segments.ToArray()));
        }
        /// <summary>Connect to the local test partition</summary>
        public static Task <IFdbDatabase> OpenTestPartitionAsync(CancellationToken ct)
        {
            var options = new FdbConnectionOptions
            {
                ClusterFile    = TestClusterFile,
                Root           = FdbPath.Absolute(FdbPathSegment.Partition("Tests"), FdbPathSegment.Create("Fdb"), FdbPathSegment.Partition(Environment.MachineName)),
                DefaultTimeout = TimeSpan.FromMilliseconds(DefaultTimeout),
            };

            return(Fdb.OpenAsync(options, ct));
        }
        public void Test_FdbPath_Substring_Absolute()
        {
            var path = FdbPath.Absolute("Foo", "Bar", "Baz");

            var slice = path.Substring(0, 2);

            Assert.That(slice.IsAbsolute, Is.True);
            Assert.That(slice[0].Name, Is.EqualTo("Foo"));
            Assert.That(slice[0].LayerId, Is.EqualTo(string.Empty));
            Assert.That(slice[1].Name, Is.EqualTo("Bar"));
            Assert.That(slice[1].LayerId, Is.EqualTo(string.Empty));
        }
        public void Test_FdbPath_Simple_Absolute()
        {
            var foo = FdbPath.Absolute("Foo");

            Assert.That(foo.ToString(), Is.EqualTo("/Foo"));
            Assert.That(foo.IsAbsolute, Is.True);
            Assert.That(foo.IsEmpty, Is.False);
            Assert.That(foo.IsRoot, Is.False);
            Assert.That(foo.Count, Is.EqualTo(1));
            Assert.That(foo[0].Name, Is.EqualTo("Foo"));
            Assert.That(foo[0].LayerId, Is.EqualTo(string.Empty));
            Assert.That(foo.Name, Is.EqualTo("Foo"));
            Assert.That(foo.ToArray(), Is.EqualTo(new [] { FdbPathSegment.Create("Foo") }));
            Assert.That(foo.StartsWith(FdbPath.Root), Is.True);
            Assert.That(foo.IsChildOf(FdbPath.Root), Is.True);
            Assert.That(foo.EndsWith(FdbPath.Root), Is.False);
            Assert.That(foo.IsParentOf(FdbPath.Root), Is.False);

            var fooBar = foo["Bar"];

            Assert.That(fooBar.ToString(), Is.EqualTo("/Foo/Bar"));
            Assert.That(fooBar.IsAbsolute, Is.True);
            Assert.That(fooBar.IsEmpty, Is.False);
            Assert.That(fooBar.IsRoot, Is.False);
            Assert.That(fooBar.Count, Is.EqualTo(2));
            Assert.That(fooBar[0].Name, Is.EqualTo("Foo"));
            Assert.That(fooBar[0].LayerId, Is.EqualTo(string.Empty));
            Assert.That(fooBar[1].Name, Is.EqualTo("Bar"));
            Assert.That(fooBar[1].LayerId, Is.EqualTo(string.Empty));
            Assert.That(fooBar.Name, Is.EqualTo("Bar"));
            Assert.That(fooBar.ToArray(), Is.EqualTo(new [] { FdbPathSegment.Create("Foo"), FdbPathSegment.Create("Bar") }));
            Assert.That(fooBar.StartsWith(FdbPath.Root), Is.True);
            Assert.That(fooBar.IsChildOf(FdbPath.Root), Is.True);
            Assert.That(fooBar.IsParentOf(FdbPath.Root), Is.False);
            Assert.That(fooBar.EndsWith(FdbPath.Root), Is.False);
            Assert.That(fooBar.StartsWith(foo), Is.True);
            Assert.That(fooBar.IsChildOf(foo), Is.True);
            Assert.That(fooBar.IsParentOf(foo), Is.False);
            Assert.That(fooBar.EndsWith(foo), Is.False);
        }