コード例 #1
0
        public void PreservesCase()
        {
            var mem = new CachedXmlContents(new RamContents());

            mem.Xml(@"BIG\subdir/file", () => new XDocument(new XElement("root", new XElement("years", new XText("1980's")))));
            Assert.Equal(
                "BIG/subdir/file",
                new FirstOf <string>(mem.Knowledge()).Value()
                );
        }
コード例 #2
0
        public void NormalizesSlashes()
        {
            var mem = new CachedXmlContents(new RamContents());

            mem.Xml(@"childhood\subdir/file", () => new XDocument(new XElement("root", new XElement("years", new XText("1980's")))));
            Assert.Equal(
                @"childhood/subdir/file",
                new FirstOf <string>(mem.Knowledge()).Value()
                );
        }
コード例 #3
0
        public void RemovesXmlFromOriginIfEmpty()
        {
            var mem      = new ConcurrentDictionary <string, byte[]>();
            var contents = new CachedXmlContents(new RamContents(mem));

            contents.Xml("a/b/c.xml", () => new XDocument(new XElement("first", "read")));
            contents.UpdateXml("a/b/c.xml", new XDocument());

            Assert.False(
                mem.ContainsKey("a/b/c.xml")
                );
        }
コード例 #4
0
        public void UpdatesXmlInCache()
        {
            var mem = new CachedXmlContents(new RamContents());

            mem.Xml("a/b/c.xml", () => new XDocument(new XElement("first", "read")));
            mem.UpdateXml("a/b/c.xml", new XDocument(new XElement("updated", "read")));

            Assert.Equal(
                "<updated>read</updated>",
                mem.Xml("a/b/c.xml", () => throw new ApplicationException("This must not occur")).ToString()
                );
        }
コード例 #5
0
        public void CachesOnUpdate()
        {
            var cache = new ConcurrentDictionary <string, XNode>();
            var data  =
                new CachedXmlContents(
                    new RamContents(),
                    cache,
                    new ManyOf()
                    );

            data.UpdateXml("a/b/c.xml", new XDocument(new XElement("more", @"contents for everyone \o/")));

            Assert.Contains("a/b/c.xml", cache.Keys);
        }
コード例 #6
0
        public void CachesOnRead()
        {
            var cache = new ConcurrentDictionary <string, XNode>();
            var data  =
                new CachedXmlContents(
                    new RamContents(),
                    cache,
                    new ManyOf()
                    );

            data.Xml("a/b/c.xml", () => new XDocument(new XElement("more", "than 8 chars")));

            Assert.Contains("a/b/c.xml", cache.Keys);
        }
コード例 #7
0
        public void DoesNotCacheBlacklisted()
        {
            var cache = new ConcurrentDictionary <string, XNode>();
            var data  =
                new CachedXmlContents(
                    new RamContents(
                        new KeyValuePair <string, byte[]>(
                            "a/b/c.xml",
                            new BytesOf(
                                new XDocument(
                                    new XElement("my", "document")
                                    ).ToString()
                                ).AsBytes()
                            )
                        ),
                    cache,
                    new ManyOf("*.xml")
                    ).Bytes("a/b/c.xml", () => throw new ApplicationException("This should not occur"));

            Assert.DoesNotContain("a/b/c.xml", cache.Keys);
        }