Пример #1
0
        private void ValidateDefaultDocument(IDictionary <Type, DefaultObjectPopulatingVisitor.PrimitiveValueBuilder> propertyValueBuilders, Func <SarifLog, SarifLog> postPopulationCallback = null)
        {
            var visitor = new DefaultObjectPopulatingVisitor(_schema, propertyValueBuilders);

            var sarifLog = new SarifLog();

            visitor.Visit(sarifLog);

            sarifLog.Version = SarifVersion.Current;

            sarifLog.InlineExternalProperties[0].Version = SarifVersion.Current;

            if (postPopulationCallback != null)
            {
                sarifLog = postPopulationCallback(sarifLog);
            }

            string toValidate = JsonConvert.SerializeObject(sarifLog, Formatting.Indented);

            var validator = new Validator(_schema);

            // Guid here simply creates a verifiably non-existent file name. This name is only
            // used in validation reporting, there's no code that attempts to access the file.
            Result[] errors = validator.Validate(toValidate, Guid.NewGuid().ToString() + ".sarif");

            var sb = new StringBuilder();

            if (errors.Length > 0)
            {
                sb.AppendLine(FailureReason(errors));
            }

            sb.Length.Should().Be(0, sb.ToString());

            SarifLog clonedLog = sarifLog.DeepClone();

            clonedLog.ValueEquals(sarifLog).Should().BeTrue();

            JObject jObjectSarifLog = JObject.Parse(toValidate);

            // The following validations ensure NotYetAutoGenerated fields work as expected.

            // see .src/sarif/NotYetAutoGenerated/ReportingConfiguration.cs (Rank property)
            // see .src/sarif/NotYetAutoGenerated/Result.cs (Rank property)
            bool isRankSerialized = RecursivePropertySearch(jObjectSarifLog, "rank");

            isRankSerialized.Should().BeFalse();

            // TODO: why does this line of code provoke a stack overflow exception?
            // clonedLog.Should().BeEquivalentTo(sarifLog);
        }
Пример #2
0
        private void ValidateDefaultDocument(IDictionary <Type, DefaultObjectPopulatingVisitor.PrimitiveValueBuilder> propertyValueBuilders, Func <SarifLog, SarifLog> postPopulationCallback = null)
        {
            var visitor = new DefaultObjectPopulatingVisitor(_schema, propertyValueBuilders);

            var sarifLog = new SarifLog();

            visitor.Visit(sarifLog);

            sarifLog.Version = SarifVersion.Current;

            sarifLog.InlineExternalProperties[0].Version = SarifVersion.Current;

            if (postPopulationCallback != null)
            {
                sarifLog = postPopulationCallback(sarifLog);
            }

            string toValidate = JsonConvert.SerializeObject(sarifLog);

            var validator = new Validator(_schema);

            // Guid here simply creates a verifiably non-existent file name. This name is only
            // used in validation reporting, there's no code that attempts to access the file.
            Result[] errors = validator.Validate(toValidate, Guid.NewGuid().ToString() + ".sarif");

            var sb = new StringBuilder();

            if (errors.Length > 0)
            {
                sb.AppendLine(FailureReason(errors));
            }

            sb.Length.Should().Be(0, sb.ToString());

            SarifLog clonedLog = sarifLog.DeepClone();

            clonedLog.ValueEquals(sarifLog).Should().BeTrue();

            // TODO: why does this line of code provoke a stack overflow exception?
            // clonedLog.Should().BeEquivalentTo(sarifLog);
        }