Beispiel #1
0
        public void testStudentSnapshot15r1()
        {
            StringMapAdaptor sma = createStudentSnapshotFields();
            StudentSnapshot  ss  = new StudentSnapshot();

            ss.StudentPersonalRefId = Adk.MakeGuid();
            ss.SnapDate             = DateTime.Now;

            Mappings m = fCfg.Mappings.GetMappings("Default").Select(null,
                                                                     null, null);

            m
            .MapOutbound(sma, ss, new DefaultValueBuilder(sma),
                         SifVersion.SIF15r1);
            Console.WriteLine(ss.ToXml());

            int?onTimeGradYear = ss.OnTimeGraduationYear;

            Assertion.Assert("onTimeGraduationYear is null", onTimeGradYear.HasValue);
            Assertion.AssertEquals("OnTimeGraduationYear", 2000, onTimeGradYear.Value);

            SchemaValidator sv = USSchemaValidator.NewInstance(SifVersion.SIF15r1);

            // 3) Validate the file
            bool validated = sv.Validate(ss, SifVersion.SIF15r1);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                sv.PrintProblems(Console.Out);
                Assertion.Fail("Schema Validation Failed:");
            }
        }
        /**
         * Runs a schema validation test on a single object using the ADK
         * @param sdo
         * @throws Exception
         */
        protected void testSchemaElement(SifElement se)
        {
            bool validated = fSchemaValidator.Validate(se, fVersion);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                SifWriter outWriter = new SifWriter(fOutput);
                outWriter.Write(se, fVersion);
                outWriter.Flush();
                fSchemaValidator.PrintProblems(fOutput);
                Assertion.Assert("Errors validating...", false);
            }
        }
        private bool RunSingleTest(
            SifVersion parseVersion,
            SifVersion writeVersion,
            string fileName,
            TextWriter output,
            SchemaValidator sv)
        {
            sv.Clear();

            if (VERBOSE)
            {
                output.Write("Running test on " + fileName + "\r\n");
            }

            // 1) Read the object into memory
            SifElement se = null;

            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output
                .WriteLine("Error parsing file " + fileName + "\r\n  - "
                           + adke);
                output.WriteLine();
                return(false);
            }
            catch (Exception re)
            {
                output.WriteLine("Error parsing file " + fileName + "\r\n  - " + re);
                output.WriteLine();
                return(false);
            }

//            if (VERBOSE)
//            {
//                SifWriter writer = new SifWriter(output);
//                writer.Write(se,parseVersion);
//                output.Flush();
//            }

            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se);

            String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk";

            // 2) Write the message out to a file
            SchemaValidator.WriteObject(writeVersion, tmpFileName, smp);

            // 3) Validate the file
            bool validated = sv.Validate(tmpFileName);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                if (VERBOSE)
                {
                    SifWriter outWriter = new SifWriter(output);
                    outWriter.Write(se, writeVersion);
                    outWriter.Flush();
                }
                output.WriteLine("Errors reading/writing " + fileName);
                sv.PrintProblems(output);
                return(false);
            }

            // 5) Read the object again into memory
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output.WriteLine("Error parsing file " + fileName + ": "
                                 + adke.Message);
                return(false);
            }
            catch (Exception re)
            {
                output.Write("Error parsing file " + fileName + ": "
                             + re.Message + "\r\n");
                return(false);
            }

            return(validated);
        }
        private bool RunSingleTest(
            SifVersion parseVersion, 
            SifVersion writeVersion, 
            string fileName, 
            TextWriter output, 
            SchemaValidator sv)
        {
            sv.Clear();

            if (VERBOSE)
            {
                output.Write("Running test on " + fileName + "\r\n");
            }

            // 1) Read the object into memory
            SifElement se = null;
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output
                        .WriteLine("Error parsing file " + fileName + "\r\n  - "
                                + adke);
                output.WriteLine();
                return false;
            }
            catch (Exception re)
            {
                output.WriteLine("Error parsing file " + fileName + "\r\n  - " + re);
                output.WriteLine();
                return false;
            }

            //            if (VERBOSE)
            //            {
            //                SifWriter writer = new SifWriter(output);
            //                writer.Write(se,parseVersion);
            //                output.Flush();
            //            }

            // Before we can validate with the schema, we need to ensure that the
            // data object is wrapped in a SIF_Message elements, because the SIF
            // Schema makes that assumption
            SifMessagePayload smp = SchemaValidator.MakeSIFMessagePayload(se);

            String tmpFileName = fileName + "." + writeVersion.ToString() + ".adk";

            // 2) Write the message out to a file
            SchemaValidator.WriteObject(writeVersion, tmpFileName, smp);

            // 3) Validate the file
            bool validated = sv.Validate(tmpFileName);

            // 4) If validation failed, write the object out for tracing purposes
            if (!validated)
            {
                if (VERBOSE)
                {
                    SifWriter outWriter = new SifWriter(output);
                    outWriter.Write(se, writeVersion );
                    outWriter.Flush();
                }
                output.WriteLine("Validation failed on " + tmpFileName );
                sv.PrintProblems(output);
                return false;
            }

            // 5) Read the object again into memory
            try
            {
                se = AdkObjectParseHelper.ParseFile(fileName, parseVersion);
            }
            catch (AdkException adke)
            {
                // Parsing failed. However, since this unit test is a complete
                // test of all available objects, just emit the problem and allow
                // the test to continue (with a notification of false)
                output.WriteLine("Error parsing file " + fileName + ": "
                        + adke.Message );
                return false;
            }
            catch (Exception re)
            {
                output.Write("Error parsing file " + fileName + ": "
                        + re.Message + "\r\n");
                return false;
            }

            return validated;
        }