Example #1
0
        public void RegisterRequiredServicesIfMissingAndUDPMessageHandler()
        {
            AggregateCatalog _catalog    = new AggregateCatalog(new AssemblyCatalog("UAOOI.Networking.UDPMessageHandler.dll"), new AssemblyCatalog("UAOOI.Networking.SimulatorInteroperabilityTest.dll"));
            AggregateCatalog _newCatalog = DefaultServiceRegistrar.RegisterServices(_catalog);
            int _disposingCount          = 0;

            using (CompositionContainer _container = new CompositionContainer(_newCatalog))
            {
                IServiceLocator _serviceLocator = new ServiceLocatorAdapter(_container);
                ServiceLocator.SetLocatorProvider(() => _serviceLocator);
                Assert.AreEqual <int>(14, _container.Catalog.Parts.Count <ComposablePartDefinition>());
                foreach (ComposablePartDefinition _part in _container.Catalog.Parts)
                {
                    Debug.WriteLine($"New Part: {string.Join(", ", _part.Metadata.Keys.ToArray<string>())}");
                    foreach (ImportDefinition _import in _part.ImportDefinitions)
                    {
                        Debug.WriteLine(string.Format("Imported contracts name => '{0}'", _import.ContractName));
                    }
                    foreach (ExportDefinition _export in _part.ExportDefinitions)
                    {
                        Debug.WriteLine(string.Format("Exported contracts name => '{0}'", _export.ContractName));
                    }
                }
                //UDPMessageHandler
                IMessageHandlerFactory _messageHandlerFactory = _container.GetExportedValue <IMessageHandlerFactory>();
                Assert.IsNotNull(_messageHandlerFactory);
                INetworkingEventSourceProvider _baseEventSource = _messageHandlerFactory as INetworkingEventSourceProvider;
                Assert.IsNull(_baseEventSource);
                IEnumerable <INetworkingEventSourceProvider> _diagnosticProviders = _container.GetExportedValues <INetworkingEventSourceProvider>();
                Assert.AreEqual <int>(4, _diagnosticProviders.Count <INetworkingEventSourceProvider>());
                // DataLogger
                EventSourceBootstrapper _eventSourceBootstrapper = _container.GetExportedValue <EventSourceBootstrapper>();
                LoggerManagementSetup   _logger = _container.GetExportedValue <LoggerManagementSetup>();
                _logger.DisposeCheck(x => _disposingCount++);
                Assert.IsNotNull(_logger.BindingFactory);
                Assert.IsNotNull(_logger.ConfigurationFactory);
                Assert.IsNotNull(_logger.EncodingFactory);
                Assert.IsNotNull(_logger.MessageHandlerFactory);
                SimulatorDataManagementSetup _simulator = _container.GetExportedValue <IDataRepositoryStartup>() as SimulatorDataManagementSetup;
                Assert.IsNotNull(_simulator);
                Assert.IsNotNull(_simulator.BindingFactory);
                Assert.IsNotNull(_simulator.ConfigurationFactory);
                Assert.IsNotNull(_simulator.EncodingFactory);
                Assert.IsNotNull(_simulator.MessageHandlerFactory);
                _simulator.DisposeCheck(x => _disposingCount++);
                Assert.AreEqual <int>(0, _disposingCount);
            }
            Assert.AreEqual <int>(2, _disposingCount);
        }
 public void ApplicationSettingsMEFCompositionMethod()
 {
     using (AggregateCatalog newCatalog = DefaultServiceRegistrar.RegisterServices(null))
     {
         using (CompositionContainer _container = new CompositionContainer(newCatalog))
         {
             string _ProducerConfigurationFileName = _container.GetExportedValue <string>(CompositionSettings.ConfigurationFileNameContract);
             Assert.AreEqual <string>("ConfigurationDataProducer.xml", _ProducerConfigurationFileName, $"_ProducerConfigurationFileName = {_ProducerConfigurationFileName}");
             string _ConsumerConfigurationFileName = _container.GetExportedValue <string>(ConsumerCompositionSettings.ConfigurationFileNameContract);
             Assert.AreEqual <string>("ConfigurationDataConsumer.xml", _ConsumerConfigurationFileName, $"_ConsumerConfigurationFileName = {_ConsumerConfigurationFileName}");
             ApplicationSettings _ApplicationSettings = _container.GetExportedValue <ApplicationSettings>();
             Assert.IsNotNull(_ApplicationSettings);
             ApplicationSettings _ApplicationSettings2 = _container.GetExportedValue <ApplicationSettings>();
             Assert.AreSame(_ApplicationSettings, _ApplicationSettings2);
         }
     }
 }
 public void ApplicationSettingsISLCompositionMethod()
 {
     using (AggregateCatalog newCatalog = DefaultServiceRegistrar.RegisterServices(null))
     {
         using (CompositionContainer _container = new CompositionContainer(newCatalog))
         {
             IServiceLocator _serviceLocator = new ServiceLocatorAdapter(_container);
             ServiceLocator.SetLocatorProvider(() => _serviceLocator);
             string _ProducerConfigurationFileName = _serviceLocator.GetInstance <string>(CompositionSettings.ConfigurationFileNameContract);
             Assert.AreEqual <string>("ConfigurationDataProducer.xml", _ProducerConfigurationFileName, $"_ProducerConfigurationFileName = {_ProducerConfigurationFileName}");
             string _ConsumerConfigurationFileName = _serviceLocator.GetInstance <string>(ConsumerCompositionSettings.ConfigurationFileNameContract);
             Assert.AreEqual <string>("ConfigurationDataConsumer.xml", _ConsumerConfigurationFileName, $"_ConsumerConfigurationFileName = {_ConsumerConfigurationFileName}");
             ApplicationSettings _ApplicationSettings = _serviceLocator.GetInstance <ApplicationSettings>();
             Assert.IsNotNull(_ApplicationSettings);
             ApplicationSettings _ApplicationSettings2 = _serviceLocator.GetInstance <ApplicationSettings>();
             Assert.AreSame(_ApplicationSettings, _ApplicationSettings2);
         }
     }
 }
Example #4
0
 public void RegisterRequiredServicesIfMissingTest()
 {
     using (AggregateCatalog newCatalog = DefaultServiceRegistrar.RegisterServices(null))
     {
         using (CompositionContainer _container = new CompositionContainer(newCatalog))
         {
             foreach (ComposablePartDefinition _part in _container.Catalog.Parts)
             {
                 foreach (ExportDefinition export in _part.ExportDefinitions)
                 {
                     Debug.WriteLine(string.Format("Part contract name => '{0}'", export.ContractName));
                 }
             }
             Assert.AreEqual <int>(11, _container.Catalog.Parts.Count());
             MainWindow _MainWindowExportedValue = _container.GetExportedValue <MainWindow>();
             Assert.IsNotNull(_MainWindowExportedValue);
             Assert.IsNotNull(_MainWindowExportedValue.MainWindowViewModel);
             IEnumerable <INetworkingEventSourceProvider> _diagnosticProviders = _container.GetExportedValues <INetworkingEventSourceProvider>();
             Assert.AreEqual <int>(3, _diagnosticProviders.Count <INetworkingEventSourceProvider>());
         }
     }
 }
Example #5
0
        public void RegisterRequiredServicesIfMissingAndUDPMessageHandler()
        {
            AggregateCatalog _catalog    = new AggregateCatalog(new AssemblyCatalog("UAOOI.Networking.UDPMessageHandler.dll"));
            AggregateCatalog _newCatalog = DefaultServiceRegistrar.RegisterServices(_catalog);

            using (CompositionContainer _container = new CompositionContainer(_newCatalog))
            {
                Assert.AreEqual <int>(9, _container.Catalog.Parts.Count <ComposablePartDefinition>());
                foreach (ComposablePartDefinition _part in _container.Catalog.Parts)
                {
                    Debug.WriteLine("New Part");
                    foreach (ImportDefinition _import in _part.ImportDefinitions)
                    {
                        Debug.WriteLine(string.Format("Imported contracts name => '{0}'", _import.ContractName));
                    }
                    foreach (ExportDefinition _export in _part.ExportDefinitions)
                    {
                        Debug.WriteLine(string.Format("Exported contracts name => '{0}'", _export.ContractName));
                    }
                }
                IMessageHandlerFactory _messageHandlerFactory = _container.GetExportedValue <IMessageHandlerFactory>();
                Assert.IsNotNull(_messageHandlerFactory);
                INetworkingEventSourceProvider _baseEventSource = _messageHandlerFactory as INetworkingEventSourceProvider;
                Assert.IsNull(_baseEventSource);
                IEnumerable <INetworkingEventSourceProvider> _diagnosticProviders = _container.GetExportedValues <INetworkingEventSourceProvider>();
                Assert.AreEqual <int>(3, _diagnosticProviders.Count <INetworkingEventSourceProvider>());
                using (CompositeDisposable _Components = new CompositeDisposable())
                {
                    EventSourceBootstrapper _eventSourceBootstrapper = _container.GetExportedValue <EventSourceBootstrapper>();
                    _Components.Add(_eventSourceBootstrapper);
                    Assert.AreEqual <int>(3, _eventSourceBootstrapper.EventSources.Count <INetworkingEventSourceProvider>());
                    ConsumerDataManagementSetup m_ConsumerConfigurationFactory = _container.GetExportedValue <ConsumerDataManagementSetup>();
                    _Components.Add(m_ConsumerConfigurationFactory);
                    OPCUAServerProducerSimulator m_OPCUAServerProducerSimulator = _container.GetExportedValue <OPCUAServerProducerSimulator>();
                    _Components.Add(m_OPCUAServerProducerSimulator);
                    Assert.AreEqual <int>(3, _Components.Count);
                }
            }
        }
Example #6
0
 public void RegisterRequiredServicesIfMissingNullArgumentTestM()
 {
     using (AggregateCatalog newCatalog = DefaultServiceRegistrar.RegisterServices(null)) { }
 }