public void Integration_Api_CreateConfigToShutdownConfig()
        {
            const int numPollsForDesiredState = 20;

            var user = new SkytapUser();
            var timeBetweenPolls = new TimeSpan(0, 0, 0, 5);

            var tfsConfigIdParam = user.ConfigRunningTfs;
            var skytapTargetTemplateIdParam = user.TargetTemplate;
            var configName = "Integration_API_TestConfig_" + DateTime.Now.ToString("yy-MM-dd_hh.mm.ss");
            var credentials = new Credentials(user.Username, user.Key);

            // Get NetworkID of the TFS Configuration which is running in Skytap
            var tfsConfigNetworkId = SkytapApi.GetNetworkIdInConfiguration(credentials, tfsConfigIdParam);
            Assert.IsFalse(string.IsNullOrEmpty(tfsConfigNetworkId));

            // CreateConfiguration (returns ConfigID of the instantiated template)
            var newTargetConfig = SkytapApi.CreateConfiguration(credentials, skytapTargetTemplateIdParam, configName);
            Assert.IsNotNull(newTargetConfig);

            Retry.Execute(() => SkytapApi.CheckConfigurationForDesiredState(credentials, newTargetConfig.ConfigurationUrl,
                                                                                new List<string> {ConfigurationStates.Suspended, ConfigurationStates.Stopped}),
                                                                                numPollsForDesiredState, timeBetweenPolls);

            // CreateIcnrConnection (between the TFSConfigNetwork and the newly instantiated config. Note that it
            // is important that the source network ID be the new configuration and the target network ID be
            // the (existing) TFS configuration. If the two are reversed, some unexplainable 409 (conflict)
            // errors occur. Following up and will update this if a good explanation is received.
            var icnrConnectionId = SkytapApi.CreateIcnrConnection(credentials, newTargetConfig.ConfigurationNetworkId, tfsConfigNetworkId);
            Assert.IsFalse(string.IsNullOrEmpty(icnrConnectionId));
            Retry.Execute(() => SkytapApi.CheckConfigurationForDesiredState(credentials, newTargetConfig.ConfigurationUrl,
                                                                                ConfigurationStates.Suspended),
                                                                                numPollsForDesiredState, timeBetweenPolls);

            SkytapApi.SetConfigurationState(credentials, newTargetConfig.ConfigurationUrl, ConfigurationStates.Running);
            Retry.Execute(() => SkytapApi.CheckConfigurationForDesiredState(credentials, newTargetConfig.ConfigurationUrl,
                                                                                ConfigurationStates.Running),
                                                                                numPollsForDesiredState, timeBetweenPolls);

            SkytapApi.SaveAsSkytapTemplate(credentials, newTargetConfig.ConfigurationUrl);
            Retry.Execute(() => SkytapApi.CheckConfigurationForDesiredState(credentials, newTargetConfig.ConfigurationUrl,
                                                                                ConfigurationStates.Suspended),
                                                                                numPollsForDesiredState, timeBetweenPolls);

            SkytapApi.DeleteIcnrConnection(credentials, icnrConnectionId);
            Retry.Execute(() => SkytapApi.CheckConfigurationForDesiredState(credentials, newTargetConfig.ConfigurationUrl,
                                                                                ConfigurationStates.Suspended),
                                                                                numPollsForDesiredState, timeBetweenPolls);

            SkytapApi.ShutDownConfiguration(credentials, newTargetConfig.ConfigurationUrl);
        }
        public void Integration_Program_StartupAndShutdown_MultipleRuns()
        {
            var user = new SkytapUser();

            for (var i = 0; i < 4; i++)
            {
                var configName = "Integration_Program_TestConfig_" + DateTime.Now.ToString("yy-MM-dd_hh.mm.ss");

                var startupCommandLineArgs =
                    string.Format("/action tfsstartup /username {0} /password {1} /configid {2} /vpnid /templateid {3} /configname {4}",
                    user.Username, user.Key, user.ConfigRunningTfs, user.TargetTemplate, configName);

                var shutdownCommandLineArgs =
                    string.Format("/action tfsshutdown /username {0} /password {1} /savetemplate false /configname {2}",
                    user.Username, user.Key, configName);

                var tfsStartupResult = Program.Main(startupCommandLineArgs.Split(' '));
                var tfsShutdownResult = Program.Main(shutdownCommandLineArgs.Split(' '));

                Assert.AreEqual(0, tfsStartupResult);
                Assert.AreEqual(0, tfsShutdownResult);
            }
        }
        public void Integration_Commands_CreateConfigToShutdownConfig()
        {
            var args = new Dictionary<string, string>();
            var user = new SkytapUser();

            args[Arguments.Username] = user.Username;
            args[Arguments.Password] = user.Key;
            args[Arguments.ConfigId] = user.ConfigRunningTfs;
            args[Arguments.TemplateId] = user.TargetTemplate;
            args[Arguments.ConfigName] = "Integration_Commands_TestConfig_" + DateTime.Now.ToString("yy-MM-dd_hh.mm.ss");

            var tfsStartupCommand = new TfsStartup();
            var tfsStartupCommandValidation = tfsStartupCommand.ValidateArgs(args);
            var tfsStartupResult = tfsStartupCommand.Invoke(args);

            // INSERT AN ARTIFICIAL DELAY to simulate a set of tests being run to make this reflect the build
            // process a little more closely. This is an optional delay and not required for the test.
            Thread.Sleep(5000 /* ms */);

            var tfsShutdownCommand = new TfsShutdown();
            var tfsShutdownCommandValidation = tfsShutdownCommand.ValidateArgs(args);
            var tfsShutdownResult = tfsShutdownCommand.Invoke(args);

            Assert.IsTrue(tfsStartupCommandValidation);
            Assert.AreEqual(0, tfsStartupResult);
            Assert.IsTrue(tfsShutdownCommandValidation);
            Assert.AreEqual(0, tfsShutdownResult);
        }