public async Task ShouldFindAllPrices() { Dictionary <string, double> expected = new Dictionary <string, double> { ["bk101"] = 44.95, ["bk102"] = 5.95, ["bk103"] = 5.95, ["bk104"] = 5.95, ["bk105"] = 5.95, ["bk106"] = 4.95, ["bk107"] = 4.95, ["bk108"] = 4.95, ["bk109"] = 6.95, ["bk110"] = 36.95, ["bk111"] = 36.95, ["bk112"] = 49.95 }; using (Stream source = ResourceFactory.Open("Books")) { XenonReader reader = new XenonReader(source, "book"); Dictionary <string, double?> found = new Dictionary <string, double?>(); await reader.Process(document => { found.Add(document.Get("id").ToString(), document.Get("price").ToDouble()); }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldFindAllTitles() { Dictionary <string, string> expected = new Dictionary <string, string> { ["bk101"] = "XML Developer's Guide", ["bk102"] = "Midnight Rain", ["bk103"] = "Maeve Ascendant", ["bk104"] = "Oberon's Legacy", ["bk105"] = "The Sundered Grail", ["bk106"] = "Lover Birds", ["bk107"] = "Splish Splash", ["bk108"] = "Creepy Crawlies", ["bk109"] = "Paradox Lost", ["bk110"] = "Microsoft .NET: The Programming Bible", ["bk111"] = "MSXML3: A Comprehensive Guide", ["bk112"] = "Visual Studio 7: A Comprehensive Guide" }; using (Stream source = ResourceFactory.Open("Books")) { XenonReader reader = new XenonReader(source, "book"); Dictionary <string, string> found = new Dictionary <string, string>(); await reader.Process(document => { dynamic data = document.GetDynamic(); found.Add(data.id.ToString(), data.title.ToString()); }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldFindAllDates() { Dictionary <string, DateTime> expected = new Dictionary <string, DateTime> { ["bk101"] = DateTime.Parse("2000-10-01"), ["bk102"] = DateTime.Parse("2000-12-16"), ["bk103"] = DateTime.Parse("2000-11-17"), ["bk104"] = DateTime.Parse("2001-03-10"), ["bk105"] = DateTime.Parse("2001-09-10"), ["bk106"] = DateTime.Parse("2000-09-02"), ["bk107"] = DateTime.Parse("2000-11-02"), ["bk108"] = DateTime.Parse("2000-12-06"), ["bk109"] = DateTime.Parse("2000-11-02"), ["bk110"] = DateTime.Parse("2000-12-09"), ["bk111"] = DateTime.Parse("2000-12-01"), ["bk112"] = DateTime.Parse("2001-04-16") }; using (Stream source = ResourceFactory.Open("Books")) { XenonReader reader = new XenonReader(source, "book"); Dictionary <string, DateTime?> found = new Dictionary <string, DateTime?>(); await reader.Process(document => { found.Add(document.Get("id").ToString(), document.Get("publish_date").ToDateTime()); }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldEnumerateAllRevisionsInAllPages() { HashSet <long> expected = new HashSet <long> { 607051494, 607051522, 607082459, 609806417, 610782955, 615708849, 607051549, 607053970, 607057294, 607057676, 607064502, 607064697, 607065037, 616919844, 645443958, 645444002, 653021729, 653021968, 653022435, 653783525, 674703256, 674719566, 675614952, 679157456, 682724788, 682952438 }; using (Stream source = ResourceFactory.Open("History")) { HashSet <long?> found = new HashSet <long?>(); XenonReader reader = new XenonReader(source, "page"); await reader.Process(document => { foreach (XenonNode node in document.GetEnumerable("revision")) { found.Add(node.Get("id").ToInt64()); } }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldPreserveWhiteCharactersByDefault() { const string data = @"<data> 123 </data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.ToString(), Is.EqualTo(" 123 ")); }); } }
public async Task ShouldHandleMissingProperty() { const string data = @"<data><first></first></data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.Get("second"), Is.Null); }); } }
public async Task ShouldDetectExistingProperty() { const string data = @"<data><first></first></data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.Has("first"), Is.True); }); } }
public void BenchmarkDynamic(string scenario, string node, Action <dynamic> callback) { Stopwatch watch = Stopwatch.StartNew(); TimeSpan started = Process.GetCurrentProcess().TotalProcessorTime; using (FileStream stream = File.OpenRead(path)) { XenonReader reader = new XenonReader(stream, node, 4 * 1024 * 1024); reporter.Benchmarking(scenario, "xenon-dynamic"); reader.Process(callback).Wait(); reporter.Complete(scenario, "xenon-dynamic", watch.Elapsed, Process.GetCurrentProcess().TotalProcessorTime - started); } }
public async Task ShouldParseDateTimeWithAdditionalWhiteCharacters() { const string data = "<data>\n 2007-12-31\n </data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.ToDateTime(), Is.InstanceOf <DateTime>()); Assert.That(document.ToDateTime(), Is.EqualTo(new DateTime(2007, 12, 31))); }); } }
public async Task ShouldParseDoubleWithAdditionalWhiteCharacters() { const string data = "<data>\n 123.45\n </data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.ToDouble(), Is.InstanceOf <Double>()); Assert.That(document.ToDouble(), Is.EqualTo(123.45d)); }); } }
public async Task ShouldOmitWhiteCharacters() { const string data = @"<data> 123 </data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); XenonWhiteCharacter mode = XenonWhiteCharacter.Omit; await reader.Process(document => { Assert.That(document.ToString(mode), Is.EqualTo("123")); }); } }
public async Task ShouldParseInt64() { const string data = "<data>123</data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.ToInt64(), Is.InstanceOf <Int64>()); Assert.That(document.ToInt64(), Is.EqualTo(123)); }); } }
public async Task ShouldFindOneCatalog() { using (Stream source = ResourceFactory.Open("Books")) { int counter = 0; XenonReader reader = new XenonReader(source, "catalog"); await reader.Process(document => { counter++; }); Assert.That(counter, Is.EqualTo(1)); } }
public async Task ShouldAccessNestedElement() { const string data = @"<data><first><second>abc</second></first></data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { Assert.That(document.Get("first"), Is.Not.Null); Assert.That(document.Get("first").Get("second"), Is.Not.Null); Assert.That(document.Get("first").Get("second").ToString(), Is.EqualTo("abc")); }); } }
public async Task ShouldEnumerateMissingProperty() { const string data = @"<data><first></first></data>"; using (Stream source = ResourceFactory.Inline(data)) { XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { foreach (XenonNode node in document.GetEnumerable("second")) { Assert.Fail(); } }); } }
public async Task ShouldEnumerateMixedProperty() { const string data = "<data node=\"abc\"><node/><node/></data>"; using (Stream source = ResourceFactory.Inline(data)) { int counter = 0; XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { foreach (XenonNode node in document.GetEnumerable("node")) { counter++; } }); Assert.That(counter, Is.EqualTo(3)); } }
public async Task ShouldEnumerateExistingPropertyOnce() { const string data = @"<data><first></first></data>"; using (Stream source = ResourceFactory.Inline(data)) { int counter = 0; XenonReader reader = new XenonReader(source, "data"); await reader.Process(document => { foreach (XenonNode node in document.GetEnumerable("first")) { counter++; } }); Assert.That(counter, Is.EqualTo(1)); } }
public async Task ShouldFindAllIdentifiers() { HashSet <string> expected = new HashSet <string> { "bk101", "bk102", "bk103", "bk104", "bk105", "bk106", "bk107", "bk108", "bk109", "bk110", "bk111", "bk112", }; using (Stream source = ResourceFactory.Open("Books")) { HashSet <string> found = new HashSet <string>(); XenonReader reader = new XenonReader(source, "book"); await reader.Process(document => { found.Add(document.GetDynamic().id.ToString()); }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldEnumerateAllBooks() { HashSet <string> expected = new HashSet <string> { "bk101", "bk102", "bk103", "bk104", "bk105", "bk106", "bk107", "bk108", "bk109", "bk110", "bk111", "bk112", }; using (Stream source = ResourceFactory.Open("Books")) { HashSet <string> found = new HashSet <string>(); XenonReader reader = new XenonReader(source, "catalog"); await reader.Process(document => { foreach (XenonNode node in document.GetEnumerable("book")) { found.Add(node.Get("id").ToString()); } }); Assert.That(found, Is.EquivalentTo(expected)); } }
public async Task ShouldFindAllContributors() { HashSet <string> expected = new HashSet <string> { "Darkreason", "Invertzoo", "Auric", "Mx. Granger", "OccultZone", "Yserbius", "AnomieBOT" }; using (Stream source = ResourceFactory.Open("History")) { HashSet <string> found = new HashSet <string>(); XenonReader reader = new XenonReader(source, "contributor"); await reader.Process(document => { if (document.Has("username")) { found.Add(document.Get("username").ToString()); } }); Assert.That(found, Is.EquivalentTo(expected)); } }