There is a nice easy way to integrate the start and stop of the framework with Specflow. If you use the sample class provided at the bottom of this page you can simply integrate it with the use of the following specflow tags
  1. StartHL7ApplicationListeners
  2. StopHL7ApplicationListeners

These tags will run the start before each individual test and the stop after and it will setup and tear down the framework as required between tests.

The next method implements the given statement about the applications which are online. This lets use a snippet like in the specflow sample to specify which applications we want online. This will then look up the config details from the config file and create a listener based on a class name being provided.

Specflow Sample

And the HL7 applications are online and waiting to process messages
	| Application Name  | Port Name    | Message Processor |     
	| HIS                       | HIS_Default    | *DOTNETTYPENAME* |
	| ADT                      | ADT_Default  | *DOTNETTYPENAME* |
		

Class Sample



[Binding]
    public class HL7TestFramework
    {
  
        [BeforeScenario("StartHL7ApplicationListeners")]
        public void StartHL7TestFramework()
        {
            MLLPListenerManager.Instance.Configure();
        }

         [AfterScenario("StopHL7ApplicationListeners")]
        public void StopHL7TestFramework()
        {             
            MLLPListenerManager.Instance.Stop();             
        }

        [Given(@"the HL(.*) applications are online and waiting to process messages")]
        public void GivenTheHLApplicationsAreOnlineAndWaitingToProcessMessages(int p0, Table table)
        {        
            foreach(var row in table.Rows)
            {
                var applicationName = row["Application Name"];
                var portName = row["Port Name"];
                var messageProcessor = row["Message Processor"];

                var applicationSettings = HL7TestConfiguration.Current.ApplicationsToStub.Get(applicationName, portName);
                if(applicationSettings == null)
                {
                    throw new ApplicationException(string.Format("There is no application configuration for: Application Name = {0}, Port Name = {1}", applicationName, portName));
                }
                

                var processorType = Type.GetType(messageProcessor);
                var processor = Activator.CreateInstance(processorType);
                var myProcessor = processor as AppFx.HL7.Testing.Utilities.IMessageProcessor;
                if (myProcessor == null)
                    throw new ApplicationException("The processor is not the right type");

                var listenerName = string.Format("{0}-{1}", applicationName, portName);
                MLLPListenerManager.Instance.AddStandardLocalListener(listenerName, applicationSettings.Port, myProcessor);
            }

            MLLPListenerManager.Instance.Start();
        }
    }



Last edited Apr 21, 2014 at 1:56 AM by michaelstephenson, version 1