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