public static void Setup(TestContext context)
        {
#pragma warning disable CA1062
            _classTestContext = context;
            _verifyPassed     = (_classTestContext.Properties["verifyPassed"] as bool?) ?? true;
            _cleanLogFolder   = (_classTestContext.Properties["cleanLogFolder"] as bool?) ?? false;
            FactoryOrchestratorClient testClientConnection;
#pragma warning restore CA1062

            try
            {
                _serviceIp = _classTestContext.Properties["serviceIp"]?.ToString() ?? "127.0.0.1";
                Logger.LogMessage($"Attempting to connect to {_serviceIp}");
                testClientConnection = new FactoryOrchestratorClient(IPAddress.Parse(_serviceIp));
                // Try to connect to given IP, will throw exception if it fails
                testClientConnection.Connect().Wait();
            }
            catch (Exception e)
            {
                // TODO: Create FOServiceExe instance if one isn't detected and localhost (127.0.0.1) was used.
                Logger.LogMessage(e.ToString());
                Assert.Inconclusive("This test requires a running FactoryOrchestratorService!");
                return;
            }

            testClientConnection.ResetService(false, false).Wait();
            _testContentSrc  = _classTestContext.Properties["testContentSrc"]?.ToString() ?? @"C:\TestContentSrc";
            _testContentDest = _classTestContext.Properties["testContentDest"]?.ToString() ?? @"C:\TestContent";

            _logDest = _classTestContext.Properties["logDest"]?.ToString() ?? Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "clientsampleintegrationtests");
        }
 public static void Cleanup()
 {
     if (_testExecuted)
     {
         // Reset service
         var clientConnection = new FactoryOrchestratorClient(IPAddress.Parse(_serviceIp));
         clientConnection.Connect().Wait();
         clientConnection.ResetService(false, false).Wait();
     }
 }
        public void RunClientSample()
        {
            _testExecuted = true;
            Logger.LogMessage($"Microsoft.FactoryOrchestrator.ClientSample {_serviceIp} {_testContentSrc} {_testContentDest} {_logDest}");
            Logger.LogMessage($"verifyPassed {_verifyPassed}");

            if (_cleanLogFolder && Directory.Exists(_logDest))
            {
                Directory.Delete(_logDest, true);
            }
            // Run client sample, will create a testlist based on files in _testContentSrc if one isn't found in _testContentSrc
            var result = Microsoft.FactoryOrchestrator.ClientSample.FactoryOrchestratorNETCoreClientSample.Main(new string[] { _serviceIp, _testContentSrc, _testContentDest, _logDest }).Result;

            if (_verifyPassed)
            {
                // Get details on all failed tasks, if any.
                // The GUIDs of failed TaskRuns from the ClientSample's execution are stored in the public "List<Guid> FailedRunGuids" parameter.
                var clientConnection = new FactoryOrchestratorClient(IPAddress.Parse(_serviceIp));
                clientConnection.Connect().Wait();

                string errorString = "";
                foreach (var guid in Microsoft.FactoryOrchestrator.ClientSample.FactoryOrchestratorNETCoreClientSample.FailedRunGuids)
                {
                    // Output the task path, the reason the task failed, and the entire task output to the error string.
                    // This helps ensure failures have a unique "fingerprint" depending on what task failed and how it failed.
                    var run = clientConnection.QueryTaskRun(guid).Result;
                    errorString = $"{run.TaskPath} failed with status {run.TaskStatus}.";
                    foreach (var line in run.TaskOutput)
                    {
                        errorString += $"\n{line}";
                    }
                }

                if (!string.IsNullOrWhiteSpace(errorString))
                {
                    Assert.Fail(errorString);
                }

                Assert.AreEqual(result, 0);
            }
            else
            {
                Assert.IsTrue(result == 0 || result == 1);
            }

            // Assume at least 1 log file was created
            var logFiles = Directory.EnumerateFiles(_logDest, "*.log", SearchOption.AllDirectories);

            Assert.AreNotEqual(logFiles.Count(), 0);
        }