public void TestThatPreCompileExecutesSuccessfully()
        {
            var operation = new PreCompileOperation("MyWebApp", @"C:\temp\MyWebApp", @"C:\temp\MyWebAppCompiled", _buildManager.Object);

            var status = new StatusReporter();
            operation.Execute(status, _settingsDefault, _token);

            Assert.That(status.HasErrors, Is.False);
            _buildManager.Verify(manager => manager.PrecompileApplication(It.IsAny<PreCompileCallback>()));
        }
        public void TestThatRoundRobinLoadBalancingGoesOnlineOfflineInCorrectOrder()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };
            var server2 = new ServerConfig { Name = "jat-web02" };
            var server3 = new ServerConfig { Name = "jat-web03" };
            var server4 = new ServerConfig { Name = "jat-web04" };
            var server5 = new ServerConfig { Name = "jat-web05" };

            _settingsDefault.Config.Servers = new[] { server1, server2, server3, server4, server5 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.RoundRobin };

            var sequnceManager = new ExecutionSequenceManager(_settingsDefault.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsDefault, _token);
            sequnceManager.Execute(status, _settingsDefault, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(_settingsDefault.Config.Servers.Count * 2));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item1, Is.EqualTo("jat-web02"));
            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[2].Item1, Is.EqualTo("jat-web03"));
            Assert.That(loadBalancer.OnlineOfflineSequence[2].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[3].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[3].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[4].Item1, Is.EqualTo("jat-web02"));
            Assert.That(loadBalancer.OnlineOfflineSequence[4].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[5].Item1, Is.EqualTo("jat-web03"));
            Assert.That(loadBalancer.OnlineOfflineSequence[5].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[6].Item1, Is.EqualTo("jat-web04"));
            Assert.That(loadBalancer.OnlineOfflineSequence[6].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[7].Item1, Is.EqualTo("jat-web05"));
            Assert.That(loadBalancer.OnlineOfflineSequence[7].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[8].Item1, Is.EqualTo("jat-web04"));
            Assert.That(loadBalancer.OnlineOfflineSequence[8].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[9].Item1, Is.EqualTo("jat-web05"));
            Assert.That(loadBalancer.OnlineOfflineSequence[9].Item2, Is.EqualTo("online"));
        }
        public void TestThatStickyWithContinueAfterManualTestOnSpecificServerExecutesOnCorrectServers()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };
            var server2 = new ServerConfig { Name = "jat-web02" };
            var server3 = new ServerConfig { Name = "jat-web03", StopServer = true };
            var server4 = new ServerConfig { Name = "jat-web04" };
            var server5 = new ServerConfig { Name = "jat-web05" };

            _settingsContinueAfterMarkedServer.Config.Servers = new[] { server1, server2, server3, server4, server5 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.Sticky };

            var sequnceManager = new ExecutionSequenceManager(_settingsContinueAfterMarkedServer.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsContinueAfterMarkedServer, _token);
            sequnceManager.Execute(status, _settingsContinueAfterMarkedServer, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(((_settingsContinueAfterMarkedServer.Config.Servers.Count - 1) * 2) + 1));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web03"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[2].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[2].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[3].Item1, Is.EqualTo("jat-web02"));
            Assert.That(loadBalancer.OnlineOfflineSequence[3].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[4].Item1, Is.EqualTo("jat-web02"));
            Assert.That(loadBalancer.OnlineOfflineSequence[4].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[5].Item1, Is.EqualTo("jat-web04"));
            Assert.That(loadBalancer.OnlineOfflineSequence[5].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[6].Item1, Is.EqualTo("jat-web04"));
            Assert.That(loadBalancer.OnlineOfflineSequence[6].Item2, Is.EqualTo("online"));

            Assert.That(loadBalancer.OnlineOfflineSequence[7].Item1, Is.EqualTo("jat-web05"));
            Assert.That(loadBalancer.OnlineOfflineSequence[7].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[8].Item1, Is.EqualTo("jat-web05"));
            Assert.That(loadBalancer.OnlineOfflineSequence[8].Item2, Is.EqualTo("online"));
        }
        public void TestThatStickyWithContinueAfterManualTestExecutesOnCorrectServers()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };
            var server2 = new ServerConfig { Name = "jat-web02" };
            var server3 = new ServerConfig { Name = "jat-web03" };
            var server4 = new ServerConfig { Name = "jat-web04" };
            var server5 = new ServerConfig { Name = "jat-web05" };

            _settingsContinueAfterMarkedServer.Config.Servers = new[] { server1, server2, server3, server4, server5 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.Sticky };

            var sequnceManager = new ExecutionSequenceManager(_settingsContinueAfterMarkedServer.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsContinueAfterMarkedServer, _token);
            sequnceManager.Execute(status, _settingsContinueAfterMarkedServer, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(((_settingsContinueAfterMarkedServer.Config.Servers.Count - 1) * 2) + 1));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("online"));

            var serverNumber = 2;
            for (int i = 1; i < loadBalancer.OnlineOfflineSequence.Count; i += 2)
            {
                Assert.That(loadBalancer.OnlineOfflineSequence[i].Item1, Is.EqualTo("jat-web0" + serverNumber));
                Assert.That(loadBalancer.OnlineOfflineSequence[i].Item2, Is.EqualTo("offline"));

                Assert.That(loadBalancer.OnlineOfflineSequence[i + 1].Item1, Is.EqualTo("jat-web0" + serverNumber));
                Assert.That(loadBalancer.OnlineOfflineSequence[i + 1].Item2, Is.EqualTo("online"));
                serverNumber++;
            }
        }
        public void TestThatStickyLoadBlancingWithOneServerWorks()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };

            _settingsDefault.Config.Servers = new[] { server1 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.Sticky };

            var sequnceManager = new ExecutionSequenceManager(_settingsDefault.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsDefault, _token);
            sequnceManager.Execute(status, _settingsDefault, _token);
            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(_settingsDefault.Config.Servers.Count * 2));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("offline"));

            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[1].Item2, Is.EqualTo("online"));
        }
        public void TestThatStickyLoadBalancingGoesOnlineOfflineInCorrectOrder()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };
            var server2 = new ServerConfig { Name = "jat-web02" };
            var server3 = new ServerConfig { Name = "jat-web03" };
            var server4 = new ServerConfig { Name = "jat-web04" };
            var server5 = new ServerConfig { Name = "jat-web05" };

            _settingsDefault.Config.Servers = new[] { server1, server2, server3, server4, server5 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.Sticky };

            var sequnceManager = new ExecutionSequenceManager(_settingsDefault.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsDefault, _token);
            sequnceManager.Execute(status, _settingsDefault, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(_settingsDefault.Config.Servers.Count * 2));

            var serverNumber = 1;
            for (int i = 0; i < loadBalancer.OnlineOfflineSequence.Count; i += 2)
            {
                Assert.That(loadBalancer.OnlineOfflineSequence[i].Item1, Is.EqualTo("jat-web0" + serverNumber));
                Assert.That(loadBalancer.OnlineOfflineSequence[i].Item2, Is.EqualTo("offline"));

                Assert.That(loadBalancer.OnlineOfflineSequence[i + 1].Item1, Is.EqualTo("jat-web0" + serverNumber));
                Assert.That(loadBalancer.OnlineOfflineSequence[i + 1].Item2, Is.EqualTo("online"));
                serverNumber++;
            }
        }
        public void TestThatRoundRobinWithManualTestStopsAfterFirstServer()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };
            var server2 = new ServerConfig { Name = "jat-web02" };
            var server3 = new ServerConfig { Name = "jat-web03" };
            var server4 = new ServerConfig { Name = "jat-web04" };
            var server5 = new ServerConfig { Name = "jat-web05" };

            _settingsStopAfterMarkedServer.Config.Servers = new[] { server1, server2, server3, server4, server5 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.RoundRobin };

            var sequnceManager = new ExecutionSequenceManager(_settingsStopAfterMarkedServer.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            sequnceManager.Execute(status, _settingsStopAfterMarkedServer, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(1));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("offline"));
        }
        public void TestThatRoundRobinLoadBlancingWithOneServerAndManuelTestWorks()
        {
            var server1 = new ServerConfig { Name = "jat-web01" };

            _settingsStopAfterMarkedServer.Config.Servers = new[] { server1 };

            var loadBalancer = new MockLoadBalancer { Mode = LbMode.RoundRobin };

            var sequnceManager = new ExecutionSequenceManager(_settingsStopAfterMarkedServer.Config.Servers, loadBalancer);
            sequnceManager.NewRemoteSequence("Test");

            var status = new StatusReporter();
            //remoteSequence.Execute(status, _settingsStopAfterMarkedServer, _token);
            sequnceManager.Execute(status, _settingsStopAfterMarkedServer, _token);

            Assert.That(loadBalancer.OnlineOfflineSequence.Count, Is.EqualTo(1));

            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item1, Is.EqualTo("jat-web01"));
            Assert.That(loadBalancer.OnlineOfflineSequence[0].Item2, Is.EqualTo("offline"));
        }
        public void TestThatTransformConfigOperationCorrectlyTransformsConfigFile()
        {
            var source = WriteTextToTempFile(Consts.Source01);
            var transform = WriteTextToTempFile(Consts.Transform01);
            var destination = source;
            var expectedResultFile = WriteTextToTempFile(Consts.Result01);

            var trans = new TransformConfigOperation(Path.GetDirectoryName(source), Path.GetFileName(source), Path.GetFileName(transform));
            var webDepStatus = new StatusReporter();
            trans.Execute(webDepStatus, _settingsDefault, _token);

            //Assert.That(webDepStatus.HasErrors, Is.False);

            var actualResult = File.ReadAllText(destination);
            var expectedResult = File.ReadAllText(expectedResultFile);
            Assert.AreEqual(expectedResult.Trim(), actualResult.Trim());
        }