Esempio n. 1
0
        static private List <string> GetTestDevicesList(OptionManager optionMgr, CloudServices cloudServices)
        {
            // Get list of devices from IoT Hub
            List <string> deviceList = GetDevicesListAsync(cloudServices.IoTRegistryManager).GetAwaiter().GetResult();;

            // If user just needs to list the devices, do that and quit.
            if (optionMgr._list)
            {
                foreach (string deviceId in deviceList)
                {
                    Console.WriteLine(deviceId);
                }
                System.Environment.Exit(0);
            }

            List <string> testDeviceList = new List <string>();

            // If user provided devices he wants to test, parse them and filter to only leave those devices
            if (optionMgr._devices != null)
            {
                testDeviceList = deviceList.Intersect(optionMgr._devices).ToList();
                ReportNotFoundDevices(optionMgr._devices /*required*/, testDeviceList /*found*/);
            }

            return(testDeviceList);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            OptionManager optionMgr = new OptionManager();

            try
            {
                optionMgr.ComputeOptions(args);

                if (optionMgr._connectionString == null)
                {
                    throw new OptionException(OptionManager._connectionStringArgumentName +
                                              " argument is required!",
                                              OptionManager._connectionStringArgumentName);
                }

                // Initialize the log...
                _logger = new Logger();
                _logger.TargetLogPath = optionMgr._logPath;
                _logger.CreateNewFile();
                _logger.Log(LogLevel.Information, "Log file is: " + _logger.GetLogFileName());

                // Initialize cloud service access...
                CloudServices cloudServices = new CloudServices(optionMgr._connectionString, optionMgr._storageConnectionString);

                // Initialize the test running...
                TestCaseRunner runner = new TestCaseRunner(
                    _logger,
                    cloudServices);

                // Set target devices...
                runner.DevicesToTest = GetTestDevicesList(optionMgr, cloudServices);

                // Set target tests
                runner.LoadFolderScenarios(optionMgr._scenariosFolder);
                runner.LoadFileScenarios(optionMgr._scenarioFiles);

                // Run the tests...
                runner.Execute();

                Environment.Exit(0);
            }
            catch (OptionException e)
            {
                Console.Write("DMValidator: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Showing help prompt...");
                Console.WriteLine();
                optionMgr.ShowHelp();

                Environment.Exit(-1);
            }
            catch (Exception e)
            {
                if (_logger != null)
                {
                    _logger.Log(LogLevel.Error, e.Message);
                }
                else
                {
                    Console.WriteLine("Error", e.Message);
                }

                Environment.Exit(-1);
            }
        }
Esempio n. 3
0
 public TestCaseRunner(Logger logger, CloudServices cloudServices)
 {
     _logger        = logger;
     _cloudServices = cloudServices;
 }