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