public async Task TestDriverConfigValuesPassedToDriverSucceeds()
        {
            // Arrange
            var testConfigProvider = new TestConfigProvider();
            var testDriverConfigName = "testDriverConfigName";
            var testDriverConfigValue = "testDriverConfigValue";

            var testConfig = new TextDisplayConfig()
            {
                DriverType = "MockDisplayDriver.MockDisplayDriver",
                DriverAssembly = "MockDisplayDriver",
                Height = 0,
                Width = 0
            };

            testConfig.DriverConfigurationValues.Add(testDriverConfigName, testDriverConfigValue);
            (testConfigProvider.Configs as List<TextDisplayConfig>).Add(testConfig);

            List<ITextDisplay> returnedDisplays;

            // Act
            returnedDisplays = await TextDisplayManager.GetDisplaysForProvider(testConfigProvider) as List<ITextDisplay>;
            // Assert
            Assert.AreEqual(1, returnedDisplays.Count, "1 display should be returned");
            var mockDriver = returnedDisplays[0] as MockDisplayDriver.MockDisplayDriver;
            Assert.IsNotNull(mockDriver);
            Assert.AreEqual(mockDriver.Config.DriverConfigurationValues[testDriverConfigName], testDriverConfigValue);
        }
        public IAsyncOperation<IEnumerable<TextDisplayConfig>> GetConfiguredDisplaysAsync()
        {
            return Task.Run(async () =>
            {
                var displaysConfig = new List<TextDisplayConfig>();

                try
                {
                    var configFile = await StorageFile.GetFileFromApplicationUriAsync(this.configFileLocation);

                    var xmlString = await FileIO.ReadTextAsync(configFile);

                    var xml = XElement.Parse(xmlString);

                    var displaysConfigXml = xml.Descendants("Screen");

                    foreach (var displayConfigXml in displaysConfigXml)
                    {
                        var displayConfig = new TextDisplayConfig();
                        var driverTypeAttribute = displayConfigXml.Attributes().Where(a => a.Name == "driverType").FirstOrDefault();

                        if (null != driverTypeAttribute)
                        {
                            displayConfig.DriverType = driverTypeAttribute.Value;
                        }

                        var commonConfigElement = displayConfigXml.Descendants("CommonConfiguration").FirstOrDefault();
                        if (null != commonConfigElement)
                        {
                            var heightElement = commonConfigElement.Descendants("Height").FirstOrDefault();
                            var widthElement = commonConfigElement.Descendants("Width").FirstOrDefault();

                            if (null != heightElement &&
                                null != widthElement)
                            {
                                displayConfig.Height = Convert.ToUInt32(heightElement.Value);
                                displayConfig.Width = Convert.ToUInt32(widthElement.Value);
                            }
                        }

                        var driverConfigElement = displayConfigXml.Descendants("DriverConiguration").FirstOrDefault();
                        foreach (var configValue in displayConfigXml.Descendants())
                        {
                            displayConfig.DriverConfigurationValues.Add(configValue.Name.ToString(), configValue.Value);
                        }

                        displaysConfig.Add(displayConfig);
                    }
                }
                catch (FileNotFoundException)
                {
                    Debug.WriteLine("TextDisplayManager: Screen config file not found");
                }

                return displaysConfig as IEnumerable<TextDisplayConfig>;
            }).AsAsyncOperation();
        }
Exemple #3
0
        public IAsyncOperation <IEnumerable <TextDisplayConfig> > GetConfiguredDisplaysAsync()
        {
            return(Task.Run(async() =>
            {
                var displaysConfig = new List <TextDisplayConfig>();

                try
                {
                    var configFile = await StorageFile.GetFileFromApplicationUriAsync(this.configFileLocation);

                    var xmlString = await FileIO.ReadTextAsync(configFile);

                    var xml = XElement.Parse(xmlString);

                    var displaysConfigXml = xml.Descendants("Screen");

                    foreach (var displayConfigXml in displaysConfigXml)
                    {
                        var displayConfig = new TextDisplayConfig();
                        var driverTypeAttribute = displayConfigXml.Attributes().Where(a => a.Name == "driverType").FirstOrDefault();

                        if (null != driverTypeAttribute)
                        {
                            displayConfig.DriverType = driverTypeAttribute.Value;
                        }

                        var commonConfigElement = displayConfigXml.Descendants("CommonConfiguration").FirstOrDefault();
                        if (null != commonConfigElement)
                        {
                            var heightElement = commonConfigElement.Descendants("Height").FirstOrDefault();
                            var widthElement = commonConfigElement.Descendants("Width").FirstOrDefault();

                            if (null != heightElement &&
                                null != widthElement)
                            {
                                displayConfig.Height = Convert.ToUInt32(heightElement.Value);
                                displayConfig.Width = Convert.ToUInt32(widthElement.Value);
                            }
                        }

                        var driverConfigElement = displayConfigXml.Descendants("DriverConiguration").FirstOrDefault();
                        foreach (var configValue in displayConfigXml.Descendants())
                        {
                            displayConfig.DriverConfigurationValues.Add(configValue.Name.ToString(), configValue.Value);
                        }

                        displaysConfig.Add(displayConfig);
                    }
                }
                catch (FileNotFoundException)
                {
                    Debug.WriteLine("TextDisplayManager: Screen config file not found");
                }

                return displaysConfig as IEnumerable <TextDisplayConfig>;
            }).AsAsyncOperation());
        }
        public async Task TestOneConfigReturnsOneDisplaySucceeds()
        {
            // Arrange
            var testConfigProvider = new TestConfigProvider();
            var testConfig = new TextDisplayConfig()
            {
                DriverType = "MockDisplayDriver.MockDisplayDriver",
                DriverAssembly = "MockDisplayDriver",
                Height = 0,
                Width = 0
            };
            (testConfigProvider.Configs as List<TextDisplayConfig>).Add(testConfig);
            List<ITextDisplay> returnedDisplays;

            // Act
            returnedDisplays = await TextDisplayManager.GetDisplaysForProvider(testConfigProvider) as List<ITextDisplay>;

            // Assert
            Assert.AreEqual(1, returnedDisplays.Count, "1 display should be returned");
        }
 public HD44780GpioDriver(TextDisplayConfig config) :
     base(config)
 {
     this.gpio = GpioController.GetDefault();
 }
 public HD44780GpioDriver(TextDisplayConfig config) :
     base(config)
 {
     this.gpio = GpioController.GetDefault();
 }
 protected TextDisplayBase(TextDisplayConfig config)
 {
     this.config = config;
     this.Height = this.config.Height;
     this.Width = this.config.Width;
 }
 public MockDisplayDriver(TextDisplayConfig config)
 {
     this.Config = config;
     this.height = config.Height;
     this.width = config.Width;
 }
Exemple #9
0
 protected TextDisplayBase(TextDisplayConfig config)
 {
     this.config = config;
     this.Height = this.config.Height;
     this.Width  = this.config.Width;
 }
        public async Task TestNonExistentAssemblyDriverTypeFails()
        {
            // Arrange
            var testConfigProvider = new TestConfigProvider();
            var testConfig = new TextDisplayConfig()
            {
                DriverType = "NonExistentDriver",
                DriverAssembly = "NonExistentAssembly",
                Height = 0,
                Width = 0
            };
            (testConfigProvider.Configs as List<TextDisplayConfig>).Add(testConfig);
            List<ITextDisplay> returnedDisplays;

            // Act
            returnedDisplays = await TextDisplayManager.GetDisplaysForProvider(testConfigProvider) as List<ITextDisplay>;

            // Assert
            Assert.AreEqual(0, returnedDisplays.Count, "No displays should be returned");
        }
        public async Task TestWriteMessageToDriverSucceeds()
        {
            // Arrange
            var testConfigProvider = new TestConfigProvider();
            var testConfig = new TextDisplayConfig()
            {
                DriverType = "MockDisplayDriver.MockDisplayDriver",
                DriverAssembly = "MockDisplayDriver",
                Height = 0,
                Width = 0
            };
            (testConfigProvider.Configs as List<TextDisplayConfig>).Add(testConfig);

            var testMessage = "testMessage";

            List<ITextDisplay> returnedDisplays;

            // Act
            returnedDisplays = await TextDisplayManager.GetDisplaysForProvider(testConfigProvider) as List<ITextDisplay>;              
            await returnedDisplays[0].WriteMessageAsync(testMessage, 0);

            // Assert
            Assert.AreEqual(1, returnedDisplays.Count, "1 display should be returned");
            var mockDriver = returnedDisplays[0] as MockDisplayDriver.MockDisplayDriver;
            Assert.IsNotNull(mockDriver, "Manager did not return mock driver");
            Assert.AreEqual(testMessage, mockDriver.LastMessage);         
        }