public async void CreateSimpleExtendedConfiguration_IoTCEvent(string testFilename, int configuredSessions,
                                                                      int configuredSubscriptions, int configuredMonitoredItems, int configuredMonitoredEvents)
        {
            string methodName     = UnitTestHelper.GetMethodName();
            string fqTempFilename = string.Empty;
            string fqTestFilename = $"{Directory.GetCurrentDirectory()}/testdata/event/{testFilename}";

            fqTempFilename = $"{Directory.GetCurrentDirectory()}/tempdata/{methodName}_{testFilename}";
            if (File.Exists(fqTempFilename))
            {
                File.Delete(fqTempFilename);
            }
            File.Copy(fqTestFilename, fqTempFilename);
            PublisherNodeConfiguration.PublisherNodeConfigurationFilename = fqTempFilename;
            _output.WriteLine($"now testing: {PublisherNodeConfiguration.PublisherNodeConfigurationFilename}");
            Assert.True(File.Exists(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));

            UnitTestHelper.SetPublisherDefaults();

            try
            {
                NodeConfiguration = PublisherNodeConfiguration.Instance;
                Assert.True(NodeConfiguration.OpcSessions.Count == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSessionsConfigured == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSubscriptionsConfigured == configuredSubscriptions, "wrong # of subscriptions");
                Assert.True(NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured == configuredMonitoredEvents, "wrong # of events");
                Assert.True(NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured == configuredMonitoredItems, "wrong # of monitored items");
                _output.WriteLine($"sessions configured {NodeConfiguration.NumberOfOpcSessionsConfigured}, connected {NodeConfiguration.NumberOfOpcSessionsConnected}");
                _output.WriteLine($"subscriptions configured {NodeConfiguration.NumberOfOpcSubscriptionsConfigured}, connected {NodeConfiguration.NumberOfOpcSubscriptionsConnected}");
                _output.WriteLine($"items configured {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured}, monitored {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsMonitored}, " +
                                  $"toRemove {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsToRemove}, events configured {NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured}, " +
                                  $"monitored {NodeConfiguration.NumberOfOpcEventMonitoredItemsMonitored}");

                await NodeConfiguration.UpdateNodeConfigurationFileAsync().ConfigureAwait(false);

                _configurationFileEntries = new List <PublisherConfigurationFileEntryLegacyModel>();
                _configurationFileEntries = JsonConvert.DeserializeObject <List <PublisherConfigurationFileEntryLegacyModel> >(File.ReadAllText(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));
                Assert.True(_configurationFileEntries[0].OpcNodes[0].IotCentralItemPublishMode == IotCentralItemPublishMode.Setting);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].EventNotifierId != null);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].Key != null);
                Assert.True(_configurationFileEntries[0].OpcEvents[0].IotCentralEventPublishMode == IotCentralEventPublishMode.Event);

                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[0].BrowsePaths[0] == "EventId");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[1].BrowsePaths[0] == "Message");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[2].BrowsePaths[0] == "/2:CycleId");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].SelectClauses[3].BrowsePaths[0] == "/2:CurrentStep");

                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause[0].Operator == "OfType");
                Assert.True(_configurationFileEntries[0].OpcEvents[0].WhereClause[0].Operands[0].Literal == "ns=2;i=235");
            }
            finally
            {
                NodeConfiguration.Dispose();
                NodeConfiguration = null;
            }
        }
        public async void CreateOpcCommandMonitoring(string testFilename, int configuredSessions,
                                                     int configuredSubscriptions, int configuredMonitoredItems, int configuredMonitoredEvents)
        {
            string methodName     = UnitTestHelper.GetMethodName();
            string fqTempFilename = string.Empty;
            string fqTestFilename = $"{Directory.GetCurrentDirectory()}/testdata/ait/{testFilename}";

            fqTempFilename = $"{Directory.GetCurrentDirectory()}/tempdata/{methodName}_{testFilename}";
            if (File.Exists(fqTempFilename))
            {
                File.Delete(fqTempFilename);
            }
            File.Copy(fqTestFilename, fqTempFilename);
            PublisherNodeConfiguration.PublisherNodeConfigurationFilename = fqTempFilename;
            _output.WriteLine($"now testing: {PublisherNodeConfiguration.PublisherNodeConfigurationFilename}");
            Assert.True(File.Exists(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));

            UnitTestHelper.SetPublisherDefaults();

            try
            {
                NodeConfiguration = PublisherNodeConfiguration.Instance;
                Assert.True(NodeConfiguration.OpcSessions.Count == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSessionsConfigured == configuredSessions, "wrong # of sessions");
                Assert.True(NodeConfiguration.NumberOfOpcSubscriptionsConfigured == configuredSubscriptions, "wrong # of subscriptions");
                Assert.True(NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured == configuredMonitoredEvents, "wrong # of events");
                Assert.True(NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured == configuredMonitoredItems, "wrong # of monitored items");
                _output.WriteLine($"sessions configured {NodeConfiguration.NumberOfOpcSessionsConfigured}, connected {NodeConfiguration.NumberOfOpcSessionsConnected}");
                _output.WriteLine($"subscriptions configured {NodeConfiguration.NumberOfOpcSubscriptionsConfigured}, connected {NodeConfiguration.NumberOfOpcSubscriptionsConnected}");
                _output.WriteLine($"items configured {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsConfigured}, monitored {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsMonitored}, " +
                                  $"toRemove {NodeConfiguration.NumberOfOpcDataChangeMonitoredItemsToRemove}, events configured {NodeConfiguration.NumberOfOpcEventMonitoredItemsConfigured}, " +
                                  $"monitored {NodeConfiguration.NumberOfOpcEventMonitoredItemsMonitored}");

                await NodeConfiguration.UpdateNodeConfigurationFileAsync().ConfigureAwait(false);

                _configurationFileEntries = new List <PublisherConfigurationFileEntryLegacyModel>();
                _configurationFileEntries = JsonConvert.DeserializeObject <List <PublisherConfigurationFileEntryLegacyModel> >(File.ReadAllText(PublisherNodeConfiguration.PublisherNodeConfigurationFilename));

                Assert.True(_configurationFileEntries[0].OpcNodes.Count == 1);
                Assert.True(_configurationFileEntries[0].OpcNodes[0].OpcSamplingInterval == 2000);
                Assert.True(_configurationFileEntries[0].OpcNodes[0].OpcPublishingInterval == 5000);
                Assert.True(_configurationFileEntries[0].OpcNodes[0].IotCentralItemPublishMode == IotCentralItemPublishMode.Command);

                // mock IoTHub communication
                var hubMockBase = new Mock <HubCommunicationBase>();
                var hubMock     = hubMockBase.As <IHubCommunication>();
                hubMock.CallBase = true;
                Hub = hubMock.Object;

                // configure hub client mock
                var hubClientMockBase = new Mock <HubClient>();
                var hubClientMock     = hubClientMockBase.As <IHubClient>();

                IotHubCommunication.IotHubClient = hubClientMock.Object;
                Hub.InitHubCommunicationAsync(hubClientMockBase.Object, true, true).Wait();
                var methodRequest = new MethodRequest("GetMonitoredItems", Encoding.ASCII.GetBytes("{\"commandParameters\":{ \"SubscriptionId\" : 41 } }"));
                hubClientMock.Setup(x => x.DefaultCommandHandlerAsync(It.IsAny <MethodRequest>(), null)).Returns(Task.FromResult(new MethodResponse(200)));
                var methodResponse = await IotHubCommunication.IotHubClient.DefaultCommandHandlerAsync(methodRequest, null);

                Assert.True(methodResponse != null);
                Assert.True(methodResponse.Status == 200);
            }
            finally
            {
                NodeConfiguration?.Dispose();
                NodeConfiguration = null;
            }
        }