public Lamp(string name, int deviceCode, IX10LowLevelDriver lowLevelDriver) { this.name = name; this.deviceCode = deviceCode; this.lowLevelDriver = lowLevelDriver; Trace.WriteLine("new lamp '" + name + "' created with device code " + deviceCode); }
public void ShouldCreateTheCm11DriverBasedOnType() { X10Configuration configuration = new X10Configuration(); configuration.DeviceType = ControllerType.CM11.ToString(); configuration.ComPort = "COM1"; LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration); try { IX10LowLevelDriver driver = factory.getDriver(); // factory will return null driver if it can't create one - caller needs to check! if (driver != null) { Assert.IsInstanceOfType(typeof(Cm11LowLevelDriver), driver, "driver should be correct type"); } } catch (ApplicationException appEx) { // this test only works if COM1 is available...fail if the message is anything other than // something about the com port not being there. Assert.IsTrue(appEx.InnerException.Message.Contains("The port 'COM1' does not exist."), "threw an exception, but the message was wrong"); } }
public IX10LowLevelDriver getDriver() { // Make sure we shut down the old driver before creating a new // or, they will compete for resources. lock (padLock) { if (driver != null) { driver.CloseDriver(); } ControllerType type = (ControllerType)Enum.Parse(typeof(ControllerType), configuration.DeviceType); switch (type) { case ControllerType.CM11: driver = new Cm11LowLevelDriver(configuration.HouseCode, configuration.ComPort); break; case ControllerType.CM17A: driver = new Cm17LowLevelDriver(configuration.HouseCode, configuration.ComPort); break; } return driver; } }
public IX10LowLevelDriver getDriver() { // Make sure we shut down the old driver before creating a new // or, they will compete for resources. lock (padLock) { if (driver != null) { driver.CloseDriver(); } ControllerType type = (ControllerType)Enum.Parse(typeof(ControllerType), configuration.DeviceType); switch (type) { case ControllerType.CM11: driver = new Cm11LowLevelDriver(configuration.HouseCode, configuration.ComPort); break; case ControllerType.CM17A: driver = new Cm17LowLevelDriver(configuration.HouseCode, configuration.ComPort); break; } return(driver); } }
public void SetUp() { x10LowLevelDriverMock = new Mock <IX10LowLevelDriver>(MockBehavior.Strict); X10Configuration configuration = new X10Configuration(); configuration.SuccessUnitCode = GREEN_LAMP_DEVICE_CODE; configuration.BuildingUnitCode = YELLOW_LAMP_DEVICE_CODE; configuration.FailureUnitCode = RED_LAMP_DEVICE_CODE; IX10LowLevelDriver x10LowLevelDriver = x10LowLevelDriverMock.Object as IX10LowLevelDriver; lampController = new LampController(configuration, x10LowLevelDriver); }
public void SetUp() { x10LowLevelDriverMock = new DynamicMock(typeof(IX10LowLevelDriver)); x10LowLevelDriverMock.Strict = true; X10Configuration configuration = new X10Configuration(); configuration.SuccessUnitCode = GREEN_LAMP_DEVICE_CODE; configuration.BuildingUnitCode = YELLOW_LAMP_DEVICE_CODE; configuration.FailureUnitCode = RED_LAMP_DEVICE_CODE; IX10LowLevelDriver x10LowLevelDriver = x10LowLevelDriverMock.MockInstance as IX10LowLevelDriver; lampController = new LampController(configuration, x10LowLevelDriver); }
public LampController(X10Configuration configuration, IX10LowLevelDriver lowLevelDriver) { if (configuration != null){ int successUnitCode = configuration.SuccessUnitCode; int buildingUnitCode = configuration.BuildingUnitCode; int failureUnitCode = configuration.FailureUnitCode; LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration); if (lowLevelDriver == null){ lowLevelDriver = factory.getDriver(); } red = new Lamp("red", failureUnitCode, lowLevelDriver); yellow = new Lamp("yellow", buildingUnitCode, lowLevelDriver); green = new Lamp("green", successUnitCode, lowLevelDriver); } }
public void ShouldCreateTheCm17aDriverBasedOnType() { X10Configuration configuration = new X10Configuration(); configuration.DeviceType = ControllerType.CM17A.ToString(); configuration.ComPort = "COM1"; LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration); IX10LowLevelDriver driver = factory.getDriver(); // factory will return null driver if it can't create one - caller needs to check! if (driver != null) { Assert.IsInstanceOfType(typeof(Cm17LowLevelDriver), driver); } }
public LampController(X10Configuration configuration, IX10LowLevelDriver lowLevelDriver) { if (configuration != null) { int successUnitCode = configuration.SuccessUnitCode; int buildingUnitCode = configuration.BuildingUnitCode; int failureUnitCode = configuration.FailureUnitCode; LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration); if (lowLevelDriver == null) { lowLevelDriver = factory.getDriver(); } red = new Lamp("red", failureUnitCode, lowLevelDriver); yellow = new Lamp("yellow", buildingUnitCode, lowLevelDriver); green = new Lamp("green", successUnitCode, lowLevelDriver); } }