Exemplo n.º 1
0
        static internal string GetSpecificationInstance(SpecificationType specType)
        {
            string specInstance = string.Empty;

            // determine name of Test Instance File & check that it exists
            IValidationTest testInstance = ValidationTestFactory.Create(specType);

            // safest way to get to Test Files folder (under bin folder) in all environments
            string fileFullName = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath) + @"\Test Files\" + testInstance.testFileName + testInstance.testFileExtension;

            if (!File.Exists(fileFullName))
            {
                throw new Exception("Test Instance (" + testInstance.testFileName + ") Not Found");
            }

            // read the file into a string
            using (StreamReader sr = File.OpenText(fileFullName))
            {
                specInstance = sr.ReadToEnd();
            }

            return(specInstance);
        }
Exemplo n.º 2
0
        static internal List <string> Validate(SpecificationType specType, string testData)
        {
            List <string> validationResults = new List <string>();

            string encryptionKey = "GP2GPzENCRYPTION";
            string fileFullName  = string.Empty;

            // create Test Instance
            IValidationTest testInstance = ValidationTestFactory.Create(specType);

            try
            {
                // validate transport format
                string fileHeader     = testData.Substring(0, 10).ToUpper();
                bool   validTransport = true;

                if (testInstance.transportFormatType == FormatType.XML || testInstance.transportFormatType == FormatType.XML_NZEPS)
                {
                    validTransport = fileHeader.StartsWith(@"<?XML ");
                }
                else if (testInstance.transportFormatType == FormatType.HL7v2)
                {
                    validTransport = fileHeader.StartsWith(@"MSH|^~\&|");
                }

                if (!validTransport)
                {
                    validationResults.Add("TRANSPORT : Fail");
                    validationResults.Add("Invalid Message File Format : specification requires " + testInstance.transportFormatType.ToString());
                    validationResults.Add("FORMAT : ???");
                    validationResults.Add("Unable to validate");
                    validationResults.Add("DATA : ???");
                    validationResults.Add("Unable to validate");
                }
                else
                {
                    validationResults.Add("TRANSPORT : Pass");
                    // create temporary test file (this is supported from Windows Azure Role)
                    fileFullName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + testInstance.testFileExtension;

                    // write the test data string to the temporary test file (required for Toolkit message consumption)
                    using (StreamWriter sw = new StreamWriter(fileFullName))
                    {
                        sw.Write(testData);
                    }

                    // call test instance validate method for Format and Data checks
                    validationResults.AddRange(testInstance.ValidateTestInstance(fileFullName, encryptionKey));
                }
            }
            finally
            {
                // delete temporary test file
                if (File.Exists(fileFullName))
                {
                    File.Delete(fileFullName);
                }
            }

            return(validationResults);
        }