public void XmlStateWriterTest01()
        {
            // Initialize the XmlWriter & State writer
            StringWriter sw = new StringWriter();
            var          xw = XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Indent = true
            });

            // Write something at the start
            xw.WriteStartElement("myHl7ExampleInstance");
            xw.WriteAttributeString("interactionId", "MCCI_IN000000UV01");

            // State writer should always be used
            XmlStateWriter xsw = new XmlStateWriter(xw);

            // Create a simple instance
            MCCI_IN000000UV01 instance = new MCCI_IN000000UV01(
                Guid.NewGuid(),
                DateTime.Now,
                MCCI_IN000000UV01.GetInteractionId(),
                ProcessingID.Production,
                "P",
                AcknowledgementCondition.Always);

            // Setup the formatter
            IXmlStructureFormatter structureFormatter = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            structureFormatter.GraphAides.Add(new DatatypeFormatter());

            // Print current path of the xmlwriter before formatting instance
            var writeStatePreFormat = xsw.WriteState;

            Console.WriteLine("Write state pre-format: {0}", writeStatePreFormat);

            // Format
            var result = structureFormatter.Graph(xsw, instance);

            // Print current path of the xmlwriter after formatting instance
            var writeStatePostFormat = xsw.WriteState;

            Console.WriteLine("Write state post-format: {0}", writeStatePostFormat);

            // Test that the write states before and after formatting has changed.
            // This demonstrates how the state of the xml writer can be tracked while runnning.
            Assert.AreNotEqual(writeStatePreFormat, writeStatePostFormat);

            // Flush state writer
            xsw.Flush();

            // finish the stream
            xw.WriteEndElement();
        }
Пример #2
0
        public void displayGraphResultsTest04()
        {
            // Flag used to verify if the graph result
            // contains details alongside its errors.
            bool noDetails = true;

            // Create a simple instance that PASSES ValidationConformance
            MCCI_IN000000UV01 instance = new MCCI_IN000000UV01(
                Guid.NewGuid(),
                DateTime.Now,
                MCCI_IN000000UV01.GetInteractionId(),
                ProcessingID.Production,
                "P",
                AcknowledgementCondition.Never,
                null,
                new Sender(new Device(new SET <II>(Guid.NewGuid()))),
                null
                );

            // Create the Xml ITS1 formatter
            var formatter = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            // Assign R1 graphing aide
            formatter.GraphAides.Add(new DatatypeFormatter()
            {
                ValidateConformance = false
            });

            // Graph the instance where instance is any interaction type
            var graphResult = formatter.Graph(Console.OpenStandardOutput(), instance);

            // Get the results.
            // If there are any errors, list the details,
            // otherwise, acknowledge that instance creted is valid.
            if (graphResult.Code != ResultCode.Accepted)
            {
                Console.WriteLine("RESULT CODE: {0}", graphResult.Code);
                foreach (var detail in graphResult.Details)
                {
                    Console.WriteLine("{0}: {1}", detail.Type, detail.Message);
                }
                noDetails = false;
            }
            else
            {
                Console.WriteLine("No errors. Instance created is a valid instance.");
            }

            // Assert that the returned instance is valid.
            Assert.AreEqual(graphResult.Code, ResultCode.Accepted);
            Assert.AreEqual(noDetails, true);
        } // end test method
Пример #3
0
        public void displayGraphResultsTest08()
        {
            bool noDetails = true;

            // Create a simple instance that FAILS ValidationConformance
            MCCI_IN000000UV01 instance = new MCCI_IN000000UV01(
                Guid.NewGuid(),
                DateTime.Now,
                MCCI_IN000000UV01.GetInteractionId(),
                ProcessingID.Production,
                "P",
                AcknowledgementCondition.Never,
                null,
                null,
                null
                );

            // Create the Xml ITS1 formatter.
            var formatter = new XmlIts1Formatter()
            {
                ValidateConformance = false
            };

            // Assign R1 graphing aide
            formatter.GraphAides.Add(new DatatypeFormatter()
            {
                ValidateConformance = false
            });

            // Graph the instance where instance is any interaction type.
            var graphResult = formatter.Graph(Console.OpenStandardOutput(), instance);

            // Get the results.
            if (graphResult.Code != ResultCode.Accepted)
            {
                Console.WriteLine("RESULT CODE: {0}", graphResult.Code);
                foreach (var detail in graphResult.Details)
                {
                    Console.WriteLine("{0}: {1}", detail.Type, detail.Message);
                }
                noDetails = false;
            }
            else
            {
                Console.WriteLine("No errors. Instance created is a valid instance.");
            }

            // Assert:  Errors are found.
            Assert.AreEqual(noDetails, true);
            Assert.AreEqual(graphResult.Code, ResultCode.Accepted);
        } // end test method