public void WritesComplexInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("X", mem);

            Parallel.For(0, 256, i =>
            {
                var id = $"mech-{i}";
                hive.Shifted("machine").Catalog().Add(id);
                hive.Shifted("machine").Comb(id).Props().Refined("checksum", id);
            });

            Parallel.For(0, 256, i =>
            {
                var id = $"mech-{i}";
                using (var xoc = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                {
                    var name = xoc.Value($"/stuff/thing/text()", "");
                    xoc.Modify(new Directives().Xpath("//name").Set(Guid.NewGuid()));
                    using (var xoc2 = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                    {
                        var name2 = xoc.Value($"/stuff/thing/text()", "");
                        xoc2.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));
                        using (var xoc3 = hive.Shifted("machine").Comb(id).Xocument("stuff.xml"))
                        {
                            var name3 = xoc.Value($"/stuff/thing/text()", "");
                            xoc3.Modify(new Directives().Xpath("/stuff").AddIf("thing").Set(Guid.NewGuid()));
                        }
                    }
                }
                Assert.Equal(1, hive.Shifted("machine").Comb(id).Xocument("stuff.xml").Nodes("//thing").Count);
            });
        }
Exemple #2
0
        public void ModifiesContent()
        {
            var mem = new RamMnemonic();

            mem.Contents()
            .UpdateXml(
                "xml-xocks",
                new XMLCursor(
                    new InputOf("<root><item>A</item></root>")
                    ).AsNode()
                );

            var xoc = new MemorizedXocument("xml-xocks", mem);

            xoc.Modify(
                new Directives()
                .Xpath("//item")
                .Set("B")
                );

            Assert.Contains(
                "B",
                xoc.Values("//item/text()")
                );
        }
Exemple #3
0
        public void RejectsUnknownSingleItem()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            Assert.Throws <ArgumentException>(() =>
                                              idx.Comb("123")
                                              );
        }
Exemple #4
0
        public void RemovesCells()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123").Cell("xunit-test").Update(new InputOf("content"));
            idx.Remove("123");
            Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge());
        }
Exemple #5
0
        public void RemovesXmls()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123").Xocument("xunit-test").Modify(new Directives().Xpath("/xunit-test").Add("content").Set("boo"));
            idx.Remove("123");
            Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge());
        }
Exemple #6
0
 /// <summary>
 /// A cell which exists in memory.
 /// Note: This memory cell lives only as long as this object lives.
 /// If you create two cells with the same path using this ctor,
 /// they will not have the same content.
 /// </summary>
 public RamCell(string path, IBytes content) : this(
         new Live <string>(() => path),
         new Solid <IMnemonic>(() =>
 {
     var mem = new RamMnemonic();
     mem.Contents().UpdateBytes(path, content.AsBytes());
     return(mem);
 })
         )
 { }
Exemple #7
0
        public void HasProps()
        {
            var memory = new RamMnemonic();
            var comb   = new RamComb("my-comb", memory);

            comb.Props().Refined("name", "value");
            Assert.Equal(
                "value",
                comb.Props().Value("name")
                );
        }
Exemple #8
0
        public void RemovesProp()
        {
            var memory = new RamMnemonic();
            var comb   = new RamComb("my-comb", memory);

            comb.Props().Refined("name", "value", "value2");
            comb.Props().Refined("name");
            Assert.Empty(
                comb.Props().Names()
                );
        }
Exemple #9
0
        public void HasArrayProps()
        {
            var memory = new RamMnemonic();
            var comb   = new RamComb("my-comb", memory);

            comb.Props().Refined("name", "value", "value2");
            Assert.Equal(
                new ManyOf("value", "value2"),
                comb.Props().Values("name")
                );
        }
        public void WritesPropsInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

            Parallel.For(0, Environment.ProcessorCount << 4, i =>
                    {
                    hive.Comb("2CV").Props().Refined("looping", "louie");
                });

            Assert.Equal("louie", hive.Comb("2CV").Props().Value("looping"));
        }
        public void AddsInParallel()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("cars", mem);

            Parallel.For(0, Environment.ProcessorCount << 4, (i) =>
                    {
                    hive.Catalog().Add("supercar");
                });

            Assert.Equal(1, hive.Catalog().List().Count);
        }
        public void ShiftsScope()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("twilight-zone");

            Assert.Empty(shifted.Catalog().List());
        }
Exemple #13
0
        public void DeliversXocument()
        {
            var memory = new RamMnemonic();
            var comb   = new RamComb("my-comb", memory);

            using (var xoc = comb.Xocument("some.xml"))
            {
                Assert.Equal(
                    1,
                    xoc.Nodes("/some").Count
                    );
            }
        }
Exemple #14
0
        public void XocumentRootSkipsSubDir()
        {
            var memory = new RamMnemonic();
            var comb   = new RamComb("my-comb", memory);

            using (var xoc = comb.Xocument("sub/some.xml"))
            {
                Assert.Equal(
                    1,
                    xoc.Nodes("/some").Count
                    );
            }
        }
Exemple #15
0
        public void RemovesXml()
        {
            var mem   = new RamMnemonic();
            var cache = new CachedMnemonic(mem);
            var data  = new BytesOf(new InputOf("splashy")).AsBytes();

            cache.Contents().UpdateXml("splashy.xml", new XDocument(new XElement("splashy")));
            cache.Contents().UpdateXml("splashy.xml", new XDocument());

            Assert.Equal(
                "<root />",
                cache.Contents().Xml("splashy.xml", () => new XDocument(new XElement("root"))).ToString()
                );
        }
        public void PrependsScopeToCombName()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("prepend-this", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("prepend-this");

            Assert.StartsWith("prepend-this",
                              hive.Comb("123", false).Name()
                              );
        }
        public void DistinguishesScope()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.Catalog()
            .Add("123");

            var shifted = hive.Shifted("twilight-zone");

            shifted.Catalog().Add("789");

            Assert.Contains("twilight-zone/hq/catalog.cat", mem.Contents().Knowledge(""));
        }
Exemple #18
0
        public void RemembersProps()
        {
            var memory = new RamMnemonic();

            new RamComb("my-comb", memory)
            .Props()
            .Refined("beer", "astra");

            Assert.Equal(
                "astra",
                new RamComb("my-comb", memory)
                .Props()
                .Value("beer")
                );
        }
Exemple #19
0
        public void CachesItems()
        {
            var mem = new RamMnemonic();
            var idx = new TextIndex("test", mem);

            idx.Add("123");

            new MemorizedXocument(
                $"test/hq/catalog.xml",
                mem
                ).Modify(
                new Directives().Xpath("/catalog/*").Remove()
                );
            Assert.True(idx.Has("123"));
        }
Exemple #20
0
 /// <summary>
 /// A cell which exists in memory.
 /// Note: This memory cell lives only as long as this object lives.
 /// If you create two cells with the same path using this ctor,
 /// they will not have the same content.
 /// </summary>
 public RamCell(IScalar <string> path, MemoryStream content) : this(
         path,
         new Solid <IMnemonic>(() =>
 {
     var mem = new RamMnemonic();
     mem.Contents()
     .UpdateBytes(
         path.Value(),
         new BytesOf(
             new InputOf(content)
             ).AsBytes()
         );
     return(mem);
 })
         )
 { }
        public void InitializesWithMemory()
        {
            var mem = new RamMnemonic();

            mem.Contents().UpdateBytes("my-cell", new byte[1] {
                0x02
            });

            using (var cell = new MemorizedCell("my-cell", mem))
            {
                Assert.True(
                    cell.Content()[0]
                    .Equals(0x02)
                    );
            }
        }
        public void IsInsensitiveToSeparatorChars()
        {
            var mem = new RamMnemonic();

            using (var cell = new MemorizedCell("this-is/my-cell", mem))
            {
                cell.Update(new InputOf("its so hot outside"));
            }
            using (var cell = new MemorizedCell(@"this-is\my-cell", mem))
            {
                Assert.Equal(
                    "its so hot outside",
                    new TextOf(cell.Content()).AsString()
                    );
            }
        }
        public void IsCaseSensitive()
        {
            var mem = new RamMnemonic();

            using (var cell = new MemorizedCell("this-is/MY-cell", mem))
            {
                cell.Update(new InputOf("its so cold outside"));
            }
            using (var cell = new MemorizedCell(@"this-is\MY-cell", mem))
            {
                Assert.Equal(
                    "its so cold outside",
                    new TextOf(cell.Content()).AsString()
                    );
            }
        }
        public void MemorizesXml()
        {
            var mem = new RamMnemonic();

            new MemorizedComb("beverage", mem)
            .Xocument("coke.xml")
            .Modify(new Directives().Xpath("/coke").Add("light").Set("yes please"));


            Assert.Equal(
                "yes please",
                new MemorizedComb("beverage", mem)
                .Xocument("coke.xml")
                .Value("/coke/light/text()", "")
                );
        }
        public void MemorizesProps()
        {
            var mem = new RamMnemonic();

            new TextIndex(
                "beverage",
                mem
                ).Add("fritz-kola");

            mem.Props("beverage", "fritz-kola").Refined("light", "yes please");

            Assert.Equal(
                "yes please",
                mem.Props("beverage", "fritz-kola").Value("light")
                );
        }
Exemple #26
0
        public void DoesNotCacheOversized()
        {
            var mem   = new RamMnemonic();
            var cache = new CachedMnemonic(mem, 4);
            var cell  =
                new MemorizedCell(
                    "a/file/which/is/oversized",
                    cache
                    );

            cell.Update(new InputOf(new byte[128]));
            cell.Content();
            mem.Contents().UpdateBytes("a/file/which/is/oversized", new byte[0]);

            Assert.True(cache.Contents().Bytes("a/file/which/is/oversized", () => new byte[0]).Length == 0);
        }
Exemple #27
0
        public void IgnoresItems()
        {
            var mem   = new RamMnemonic();
            var cache = new CachedMnemonic(mem, "a/*/blacklisted/*");
            var cell  =
                new MemorizedCell(
                    "a/file\\which/is\\blacklisted/data.dat",
                    cache
                    );

            cell.Content();
            mem.Contents()
            .UpdateBytes("a/file\\which/is\\blacklisted/data.dat", new byte[128]);

            Assert.False(cache.Contents().Knowledge().Contains("a/file\\which/is\\blacklisted/data.dat"));
        }
        public void DeliversHQXocument()
        {
            var mem  = new RamMnemonic();
            var hive = new MemorizedHive("in-memory", mem);

            hive.HQ().Cell("A").Update(new InputOf(new byte[1] {
                0xAB
            }));

            Assert.Equal(
                new byte[1] {
                0xAB
            },
                hive.HQ().Cell("A").Content()
                );
        }
        public void RemembersComb()
        {
            var mem = new RamMnemonic();

            new MemorizedHive("in-memory", mem)
            .Catalog()
            .Add("123");

            Assert.Equal(
                "in-memory/123",
                new MemorizedHive("in-memory", mem)
                .Catalog()
                .List()[0]
                .Name()
                );
        }
Exemple #30
0
        public void ReadsContent(string expected)
        {
            var mem = new RamMnemonic();

            mem.Contents()
            .UpdateXml(
                "xml-xocks",
                new XMLCursor(
                    new InputOf("<root><item>A</item><item>B</item></root>")
                    ).AsNode()
                );

            Assert.Contains(
                expected,
                new MemorizedXocument("xml-xocks", mem).Values("//item/text()")
                );
        }