public static void ChooseBasicComparisons() { // Load same file twice // change the other a little, save it and reload so we get a fresh instance // bypassing some bugs that lead to not everything updating on the fly :( var path = Path.Combine("data", "minimal.xbrl"); var tempPath = Path.GetTempFileName(); var first = Instance.FromFile(path); var second = Instance.FromFile(path); var period = new Period(2050, 12, 31); var entity = new Entity("foo", "bar"); foreach (var context in second.Contexts) { context.Period = period; context.Entity = entity; } second.ToFile(tempPath); second = Instance.FromFile(tempPath); ComparisonReport report = null; string[] expectedMessages = null; BasicComparisons basicSelection; // Full comparison outputs both Entity and Period from basic and detailed comparion report = InstanceComparer.Report(first, second, ComparisonTypes.All); Assert.False(report.Result); expectedMessages = new string[] { "Different Entity", "Different Period", $"(a) {first.Contexts[0].Entity}", $"(b) {second.Contexts[0].Entity}", $"(a) {first.Contexts[0].Period}", $"(b) {second.Contexts[0].Period}" }; Assert.Equal(expectedMessages, report.Messages);//, report.Messages.Join(Environment.NewLine)); // basic comparison with all flags reports Entity and Period basicSelection = BasicComparisons.All; report = InstanceComparer.Report(first, second, ComparisonTypes.Basic); Assert.False(report.Result); expectedMessages = new string[] { "Different Entity", "Different Period", }; Assert.Equal(expectedMessages, report.Messages);//, report.Messages.Join(Environment.NewLine)); // basic comparison without Entity and Period flags does not list any differences basicSelection &= ~BasicComparisons.Entity; basicSelection &= ~BasicComparisons.Period; report = InstanceComparer.Report(first, second, ComparisonTypes.Basic, basicSelection); Assert.True(report.Result); }
List <ComparisonReport> TestZippedFiles(string zipFile, string outputFolder) { output.WriteLine(zipFile); var result = new List <ComparisonReport>(); using (var file = File.OpenRead(zipFile)) using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) { foreach (var entry in zip.Entries.Where(e => Path.GetExtension(e.Name) == ".xbrl")) { output.WriteLine($"\t{entry.Name}"); var outputFile = Path.Combine(outputFolder, Path.ChangeExtension(entry.Name, "out")); var memoryStream = new MemoryStream(); using (var zipStream = entry.Open()) zipStream.CopyTo(memoryStream); var instance = Instance.FromStream(memoryStream); instance.ToFile(outputFile); var report = InstanceComparer.Report(instance, Instance.FromFile(outputFile)); File.WriteAllLines(Path.Combine(outputFolder, Path.ChangeExtension(entry.Name, "log")), report.Messages); result.Add(report); } } return(result); }
public void Invalid_Field_Expression_Throws_Exception() { var comparer = InstanceComparer.For <TestClass>() .AddField(c => c.StringProperty, StringComparer.OrdinalIgnoreCase); Assert.Fail(); }
public static void ExamineFactDifferences() { // load same instance twice var path = Path.Combine("data", "ars.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // change some facts on the second instance firstInstance.Facts[0].Value = "DEADBEED"; firstInstance.Facts[1].Decimals = "16"; secondInstance.Facts[0].Value = "FOOBAR"; secondInstance.Facts[1].Decimals = "9"; // change some context members secondInstance.Contexts[4].AddExplicitMember("AO", "s2c_AO:x0"); secondInstance.Contexts[5].AddExplicitMember("RT", "s2c_RT:x52"); // generate raw differences var report = InstanceComparer.ReportObjects(firstInstance, secondInstance, ComparisonTypes.All, BasicComparisons.All); // should give negative result because differences were found Assert.False(report.Result); // should report both facts for both instances Assert.Equal(2, report.Facts.Item1.Count); Assert.Equal(2, report.Facts.Item2.Count); // try to match the facts var factReport = FactReport.FromReport(report); Assert.NotNull(factReport.Matches); }
public static void CompareDifferentUnits() { var path = Path.Combine("data", "reference.xbrl"); var first = Instance.FromFile(path); var second = Instance.FromFile(path); var unit = new Unit("uUSD", "iso4217:USD"); second.Units.Add(unit); second.Facts[1].Unit = unit; second.Units.Remove("uEUR"); // write+read just to make sure all references are updated internally :( var tmpfile = Path.GetTempFileName(); second.ToFile(tmpfile); second = Instance.FromFile(tmpfile); var report = InstanceComparer.Report(first, second, ComparisonTypes.All); Assert.False(report.Result); var expectedMessages = new string[] { "Different Units", $"(a) {first.Facts[1]} ({first.Facts[1].Context.Scenario})", $"(b) {second.Facts[1]} ({second.Facts[1].Context.Scenario})", "(a) iso4217:EUR", "(b) iso4217:USD", }; Assert.Equal(expectedMessages, report.Messages);//, report.Messages.Join(Environment.NewLine)); }
public void Valid_Expression_Returns_Expected_Results() { var comparer = InstanceComparer.For <TestClass>() .AddExpression(t => t.StringProperty.EndsWith("a")); var a = new TestClass { StringProperty = "cba" }; var b = new TestClass { StringProperty = "a" }; var c = new TestClass { StringProperty = "b" }; Assert.IsTrue(comparer.Equals(a, a)); Assert.IsTrue(comparer.Equals(b, b)); Assert.IsTrue(comparer.Equals(a, b)); Assert.IsFalse(comparer.Equals(a, null)); Assert.IsFalse(comparer.Equals(b, null)); Assert.IsFalse(comparer.Equals(c, null)); Assert.IsFalse(comparer.Equals(a, c)); Assert.IsFalse(comparer.Equals(b, c)); Assert.AreEqual(comparer.GetHashCode(a), comparer.GetHashCode(b)); Assert.AreNotEqual(comparer.GetHashCode(a), comparer.GetHashCode(c)); Assert.AreNotEqual(comparer.GetHashCode(b), comparer.GetHashCode(c)); }
public void Valid_Field_Expression_Returns_Expected_Results() { var comparer = InstanceComparer.For <TestClass>() .AddField(x => x.StringField, StringComparer.OrdinalIgnoreCase); var a = new TestClass { StringField = "a" }; var b = new TestClass { StringField = "A" }; var c = new TestClass { StringField = "b" }; Assert.IsTrue(comparer.Equals(a, a)); Assert.IsTrue(comparer.Equals(b, b)); Assert.IsTrue(comparer.Equals(a, b)); Assert.IsFalse(comparer.Equals(a, null)); Assert.IsFalse(comparer.Equals(b, null)); Assert.IsFalse(comparer.Equals(c, null)); Assert.IsFalse(comparer.Equals(a, c)); Assert.IsFalse(comparer.Equals(b, c)); Assert.AreEqual(comparer.GetHashCode(a), comparer.GetHashCode(b)); Assert.AreNotEqual(comparer.GetHashCode(a), comparer.GetHashCode(c)); Assert.AreNotEqual(comparer.GetHashCode(b), comparer.GetHashCode(c)); }
public void Null_Field_Expression_Throws_Exception() { Expression <Func <TestClass, string> > expr = null; var comparer = InstanceComparer.For <TestClass>().AddField(expr, StringComparer.OrdinalIgnoreCase); Assert.Fail(); }
static ComparisonReport TestFile(string inputFile, string outputFile, string reportFile) { Instance.FromFile(inputFile).ToFile(outputFile); var report = InstanceComparer.Report(inputFile, outputFile); File.WriteAllLines(reportFile, report.Messages); return(report); }
public static void CompareReportTest() { // load same instance twice var path = Path.Combine("data", "reference.xbrl"); var report = InstanceComparer.Report(path, path, ComparisonTypes.Contexts); Assert.True(report.Result, string.Join(Environment.NewLine, report.Messages)); }
public static void CompareTotallyDifferentInstancesReportObjects() { var firstPath = Path.Combine("data", "reference.xbrl"); var secondPath = Path.Combine("data", "ars.xbrl"); var report = InstanceComparer.ReportObjects(firstPath, secondPath); Assert.False(report.Result); }
public static void CompareDomainNamespacesOfTotallyDifferentInstances() { var firstPath = Path.Combine("data", "reference.xbrl"); var secondPath = Path.Combine("data", "ars.xbrl"); var report = InstanceComparer.Report(firstPath, secondPath, ComparisonTypes.DomainNamespaces); Assert.False(report.Result); Assert.NotEmpty(report.Messages); }
public static void InstancesAreComparableAfterCreation() { var first = new Instance(); var second = new Instance(); var comparison = InstanceComparer.Report(first, second); Assert.True(comparison.Result, string.Join(Environment.NewLine, comparison.Messages)); }
public static void CompareDomainNamespacesOfTotallyDifferentInstances() { var firstPath = Path.Combine("data", "reference.xbrl"); var secondPath = Path.Combine("data", "ars.xbrl"); var report = InstanceComparer.Report(firstPath, secondPath, ComparisonTypes.DomainNamespaces); Console.WriteLine(string.Join(Environment.NewLine, report.Messages)); Assert.IsFalse(report.Result); CollectionAssert.IsNotEmpty(report.Messages); }
public static void CompareScenarioMemberOrderDifferent() { var left = Instance.FromFile(Path.Combine("data", "memberorder0.xbrl")); var right = Instance.FromFile(Path.Combine("data", "memberorder1.xbrl")); Assert.Equal(left, right); var report = InstanceComparer.Report(left, right); Assert.True(report.Result, string.Join(Environment.NewLine, report.Messages)); }
public static void CompareInstanceToItselfWithPath() { // load same instance twice and compare var path = Path.Combine("data", "reference.xbrl"); var report = InstanceComparer.Report(path, path); // comparison should find the instances equivalent Assert.True(report.Result); // there should be no differences reported Assert.Empty(report.Messages);//, report.Messages.Join(Environment.NewLine)); }
public static void CompareEntityWithNoEntity() { var first = Instance.FromFile(Path.Combine("data", "empty_instance.xbrl")); var second = Instance.FromFile(Path.Combine("data", "empty_instance.xbrl")); second.Entity = new Entity("LEI", "00000000000000000098"); second.Period = new Period(2016, 05, 31); second.AddFilingIndicator("foo", false); // should not throw Assert.IsNotNull(InstanceComparer.Report(first, second)); }
public static void CompareInstanceToItself() { // load same instance twice and compare var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); var report = InstanceComparer.Report(firstInstance, secondInstance); Console.WriteLine(string.Join(Environment.NewLine, report.Messages)); // comparison should find the instances equivalent Assert.IsTrue(report.Result); // there should be no differences reported CollectionAssert.IsEmpty(report.Messages); }
public static void BypassTaxonomyVersion() { var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); secondInstance.TaxonomyVersion = null; var types = ComparisonTypes.All & ~ComparisonTypes.TaxonomyVersion; var report = InstanceComparer.Report(firstInstance, secondInstance, types); Assert.True(report.Result); }
public static void CompareFactWithMissingUnit() { var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // comparing this should not throw secondInstance.Facts[0].Unit = null; var report = InstanceComparer.Report(firstInstance, secondInstance); Assert.False(report.Result); Assert.Equal(2, report.Messages.Count); //, report.Messages.Join(Environment.NewLine)); }
public void DefaultNamespaceIsHandledCorrectly() { // should be completely the same instance // first has canonical prefix "xbrli" for "http://www.xbrl.org/2003/instance" // and second has it as default namespace var first = Path.Combine("data", "reference.xbrl"); var second = Path.Combine("data", "reference_defaultns.xbrl"); var report = InstanceComparer.Report(first, second); if (!report.Result) { Console.WriteLine(report); } Assert.True(report.Result); }
public static void CompareBasicNullValues() { // load same instance twice and compare var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); secondInstance.TaxonomyVersion = null; secondInstance.SchemaReference = null; var report = InstanceComparer.Report(firstInstance, secondInstance, ComparisonTypes.Basic); // comparison should find the instances different and not throw Assert.False(report.Result); Assert.NotEmpty(report.Messages);//, report.Messages.Join(Environment.NewLine)); }
public static void CompareSimilarFacts() { // load same instance twice and compare var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); secondInstance.Facts[0].Value = "0"; secondInstance.Facts[1].Value = "0"; var report = InstanceComparer.Report(firstInstance, secondInstance, ComparisonTypes.Facts); // comparison should find the instances different and not throw Assert.False(report.Result); Assert.NotEmpty(report.Messages); Assert.Equal(4, report.Messages.Count); // report.Messages.Join(Environment.NewLine)); }
public static void CompareInstancesTypedMemberDifferent() { // load same instance twice var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // change second only slightly and compare secondInstance.Contexts[1].Scenario.TypedMembers[0].Value = "abcd"; var report = InstanceComparer.Report(firstInstance, secondInstance); Console.WriteLine(string.Join(Environment.NewLine, report.Messages)); // not the same anymore Assert.IsFalse(report.Result); // should contain some differences CollectionAssert.IsNotEmpty(report.Messages); // one context is different, report should reflect this once per instance Assert.AreEqual(2, report.Messages.Count); }
public static void CompareDifferentEntityAndPeriodOnly() { var path = Path.Combine("data", "reference.xbrl"); var path2 = Path.Combine("data", "reference2.xbrl"); var report = InstanceComparer.Report(path, path2); Assert.False(report.Result); string[] expectedMessages = { "Different Entity", "Different Period", "(a) Identifier=http://standards.iso.org/iso/17442:1234567890ABCDEFGHIJ", "(b) Identifier=http://standards.iso.org/iso/17442:00000000000000000098", "(a) Instant=2014-12-31", "(b) Instant=2015-12-31" }; // Does NOT report the differences for each context Assert.Equal(expectedMessages, report.Messages);//, report.Messages.Join(Environment.NewLine)); }
public static void CompareLargeInstanceMinorDifferenceInFact() { // load same instance twice var path = Path.Combine("data", "ars.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // change second only slightly and compare // original is 0 secondInstance.Facts[33099].Value = "0.0"; var report = InstanceComparer.Report(firstInstance, secondInstance, ComparisonTypes.Facts); Console.WriteLine(string.Join(Environment.NewLine, report.Messages)); // not the same anymore Assert.IsFalse(report.Result); // should contain some differences CollectionAssert.IsNotEmpty(report.Messages); // one context is different, report should reflect this once per instance Assert.AreEqual(2, report.Messages.Count); }
public static void ComparisonReportContainsContextWithNullScenario() { // load same instance twice var path = Path.Combine("data", "reference.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // modify other one so they produce differences to report foreach (var context in secondInstance.Contexts) { context.Entity.Identifier.Value = "00000000000000000098"; } var report = InstanceComparer.Report(firstInstance, secondInstance); // comparison should find the instances different and not crash Assert.False(report.Result); // there should be some differences reported Assert.NotEmpty(report.Messages);//, report.Messages.Join(Environment.NewLine)); }
public static void CompareLargeInstanceMinorDifferenceInFactReportObjects() { // load same instance twice var path = Path.Combine("data", "ars.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // change one fact in both instances // original is 0 firstInstance.Facts[33099].Value = "FOOBAR"; secondInstance.Facts[33099].Value = "DEADBEEF"; var report = InstanceComparer.ReportObjects(firstInstance, secondInstance, ComparisonTypes.All, BasicComparisons.All); // not the same anymore Assert.False(report.Result); // one fact is different, report should reflect this once per instance Assert.Single(report.Facts.Item1); Assert.Single(report.Facts.Item2); }
public static void CompareLargeInstanceMinorDifferenceInFact() { // load same instance twice var path = Path.Combine("data", "ars.xbrl"); var firstInstance = Instance.FromFile(path); var secondInstance = Instance.FromFile(path); // change one fact in both instances // original is 0 firstInstance.Facts[33099].Value = "FOOBAR"; secondInstance.Facts[33099].Value = "DEADBEEF"; var report = InstanceComparer.Report(firstInstance, secondInstance, ComparisonTypes.Facts); // not the same anymore Assert.False(report.Result); // should contain some differences Assert.NotEmpty(report.Messages); // one fact is different, report should reflect this once per instance Assert.Equal(2, report.Messages.Count);// report.Messages.Join(Environment.NewLine)); }
public void CompareSolvencyReferenceInstance() { var instance = CreateSolvencyInstance(); // unless done when loading, duplicate objects // aren't automatically removed until serialization so do it before comparisons instance.RemoveUnusedObjects(); var referencePath = Path.Combine("data", "reference.xbrl"); var referenceInstance = Instance.FromFile(referencePath, true); // Instances are functionally equivalent: // They have the same number of contexts and scenarios of the contexts match member-by-member // Members are checked by dimension, domain and value, namespaces included // They have the same facts matched by metric, value, decimals and unit // Entity and Period are also matched // Some things are NOT checked, eg. taxonomy version, context names //Assert.Equal(instance, referenceInstance); string tempFile = "temp.xbrl"; instance.ToFile(tempFile); var newInstance = Instance.FromFile(tempFile, true); // Assert.True(newInstance.Equals(instance)); var report = InstanceComparer.Report(instance, newInstance); if (!report.Result) { Console.WriteLine(report); } Assert.Empty(report.Messages); Assert.True(newInstance.Equals(referenceInstance)); newInstance.Contexts[1].AddExplicitMember("AM", "s2c_AM:x1"); Assert.False(newInstance.Equals(referenceInstance)); }