protected DriverFactoryTestBase() { Dispatcher = DispatcherMock.Instance; Factory = new NodeTemplateFactoryMock(); DriverFactory = (T)Activator.CreateInstance(typeof(T)); DriverFactory.InitNodeTemplates(Factory); }
protected ModBusSlaveAttribute InitSlaveAttribute(Guid attributeType, Func <NodeInstance, NodeInstance> modifyNodeAttribute = null) { var factory = new NodeTemplateFactoryMock(); var modbusDriverFactory = new ModBusTcpMasterDriverFactory(); modbusDriverFactory.InitNodeTemplates(factory); var modbusTcpSlaveDriverFactory = new ModBusTcpSlaveDriverFactory(); modbusTcpSlaveDriverFactory.InitNodeTemplates(factory); var modbusRtuDriverFactory = new ModBusRtuMasterDriverFactory(); modbusRtuDriverFactory.InitTemplates(factory); var modbusRtuSlaveDriverFactory = new ModBusRtuSlaveDriverFactory(); modbusRtuSlaveDriverFactory.InitTemplates(factory); var driverNode = factory.CreateNodeInstance(modbusTcpSlaveDriverFactory.DriverGuid); var device = factory.CreateNodeInstance(ModBusDriverFactory.ModBusDriverFactory.DeviceTemplate); var attributeNode = factory.CreateNodeInstance(attributeType); if (modifyNodeAttribute != null) { attributeNode = modifyNodeAttribute(attributeNode); } driverNode.InverseThis2ParentNodeInstanceNavigation.Add(device); device.InverseThis2ParentNodeInstanceNavigation.Add(attributeNode); var driverContext = new DriverContextMock(driverNode, factory); var driver = modbusTcpSlaveDriverFactory.CreateDriver(driverContext); driver.Init(); driver.Configure(); return(driver.Children[0].Children[0] as ModBusSlaveAttribute); }