Esempio n. 1
0
        private void RunTest(
            string testName,
            IIonValue testCase,
            IIonValue expectedHashLog,
            TestIonHasherProvider hasherProvider,
            IonHashTester testObject
            )
        {
            if (expectedHashLog == null)
            {
                return;
            }

            IIonValue ionValue  = testCase.GetField("ion");
            IIonValue ionBinary = testCase.GetField("10n");

            if (ionValue != null && ionBinary != null)
            {
                throw new Exception("Test must not define both 'ion' and '10n' fields");
            }

            var reader = ionValue == null
                ? testObject.GetIonReader(ContainerToBytes(ionBinary))
                : testObject.GetIonReader(ionValue);

            testObject.Traverse(reader, hasherProvider);

            IIonValue actualHashLog         = testObject.GetHashLog();
            IIonValue actualHashLogFiltered = FilterHashLog(actualHashLog, expectedHashLog);

            Assert.AreEqual(HashLogToString(expectedHashLog), HashLogToString(actualHashLogFiltered));
        }
Esempio n. 2
0
            internal virtual void Traverse(IIonReader reader, TestIonHasherProvider hasherProvider)
            {
                this.hasherProvider = hasherProvider;
                IIonHashReader ihr = new IonHashReader(reader, hasherProvider);

                Traverse(ihr);
                ihr.Digest();
            }
Esempio n. 3
0
 public void RunWriterTest(
     string testName,
     IIonValue testCase,
     IIonValue expectedHashLog,
     TestIonHasherProvider hasherProvider
     )
 {
     RunTest(testName, testCase, expectedHashLog, hasherProvider, new WriterTest());
 }
Esempio n. 4
0
            internal override void Traverse(IIonReader reader, TestIonHasherProvider hasherProvider)
            {
                this.hasherProvider = hasherProvider;
                MemoryStream   ms     = new MemoryStream();
                StreamWriter   sw     = new StreamWriter(ms);
                IIonWriter     writer = IonTextWriterBuilder.Build(sw);
                IIonHashWriter ihw    = new IonHashWriter(writer, this.hasherProvider);

                ihw.WriteValues(reader);
                ihw.Digest();
                ihw.Dispose();
            }
        public IEnumerable <object[]> GetData(MethodInfo methodInfo)
        {
            var dataList = new List <object[]>();

            var loader          = IonLoader.Default;
            var file            = DirStructure.IonHashDotnetTestFile("ion_hash_tests.ion");
            var ionHashTests    = loader.Load(file);
            var testsEnumerator = ionHashTests.GetEnumerator();

            while (testsEnumerator.MoveNext())
            {
                IIonValue testCase = testsEnumerator.Current;

                string testName = "unknown";
                if (testCase.ContainsField("ion"))
                {
                    testName = testCase.GetField("ion").ToPrettyString();
                }

                IReadOnlyCollection <SymbolToken> annotations = testCase.GetTypeAnnotationSymbols();
                if (annotations.Count > 0)
                {
                    testName = annotations.ElementAt(0).Text;
                }

                IIonValue expect           = testCase.GetField("expect");
                var       expectEnumerator = expect.GetEnumerator();
                while (expectEnumerator.MoveNext())
                {
                    IIonValue expectedHashLog = expectEnumerator.Current;
                    String    hasherName      = expectedHashLog.FieldNameSymbol.Text;

                    object[] data = new object[] {
                        hasherName.Equals("identity") ? testName : testName + "." + hasherName,
                        testCase,
                        expectedHashLog,
                        TestIonHasherProvider.GetInstance(hasherName)
                    };
                    dataList.Add(data);
                }
            }

            return(dataList);
        }