Esempio n. 1
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()
                );
        }
Esempio n. 2
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);
        }
Esempio n. 3
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"));
        }
Esempio n. 4
0
        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()")
                );
        }
Esempio n. 5
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()
                );
        }