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()") ); }
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()); }
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()); }
/// <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); }) ) { }
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("")); }
/// <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 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); }
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 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 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()") ); }
public void CachesXmlOnRead() { var xml = (XNode) new XDocument(new XElement("root", new XText("potato"))); var mem = new RamMnemonic(); var cache = new CachedMnemonic(mem); cache.Contents().Xml("cashy", () => xml); //read 1 mem.Contents().UpdateXml("cashy", (XNode) new XDocument(new XElement("root", new XText("")))); Assert.Contains( "potato", new XMLCursor( cache.Contents() .Xml("cashy", () => throw new ApplicationException($"Assumed to have memory")) ).Values("/root/text()") ); }
public void FindsNodes() { var mem = new RamMnemonic(); mem.Contents() .UpdateXml( "xml-xocks", new XMLCursor( new InputOf("<root><item>A</item><item>B</item></root>") ).AsNode() ); var xoc = new MemorizedXocument("xml-xocks", mem); Assert.Equal( 1, xoc.Nodes("//item[text() = 'A']").Count ); }
public void HasNodeContent() { var mem = new RamMnemonic(); mem.Contents() .UpdateXml( "xml-xocks", new XMLCursor( new InputOf("<root><item>A</item><item>B</item></root>") ).AsNode() ); var xoc = new MemorizedXocument("xml-xocks", mem); Assert.Equal( "A", xoc.Nodes("//item")[0].Values("text()")[0] ); }
public void CachesBytesOnRead() { var mem = new RamMnemonic(); var cache = new CachedMnemonic(mem); var data = new BytesOf(new InputOf("splashy")).AsBytes(); cache.Contents().Bytes("cashy", () => data); //read 1 mem.Contents().UpdateBytes("cashy", new byte[0]); Assert.Equal( "splashy", new TextOf( new InputOf( cache.Contents() .Bytes("cashy", () => throw new ApplicationException($"Assumed to have memory")) ) ).AsString() ); }