public static void SetLightColorFromBuildState(Build buildFromSource, Light light)
 {
     switch (buildFromSource.State)
     {
         case Build.BuildState.Success:
             {
                 light.LightColor = Light.Color.Green;
                 light.TurnOn(buildFromSource.IsBuilding);
                 break;
             }
         case Build.BuildState.Unstable:
             {
                 light.LightColor = Light.Color.Yellow;
                 light.TurnOn(buildFromSource.IsBuilding);
                 break;
             }
         case Build.BuildState.Failure:
             {
                 light.LightColor = Light.Color.Red;
                 light.TurnOn(buildFromSource.IsBuilding);
                 break;
             }
         case Build.BuildState.Aborted:
         case Build.BuildState.Unknown:
             {
                 light.TurnOff();
                 break;
             }
         default:
             {
                 throw new UnknownBuildStateException(buildFromSource.State.ToString());
             }
     }
 }
        public void PausingServiceManagerShouldShowPausedState()
        {
            var buildToSimulate = new Build { BuildNumber = "1", IsBuilding = false, State = Build.BuildState.Failure };
            var buildServiceManagerToTest = SetupMockData(buildToSimulate);

            _threadTask = Task.Factory.StartNew(buildServiceManagerToTest.Run);

            buildServiceManagerToTest.Pause();

            Assert.AreEqual(BuildServiceManager.State.Paused, buildServiceManagerToTest.CurrentState);

            buildServiceManagerToTest.Stop();

            _threadTask.Wait();
        }
        public void GetCurrentBuildFindsLatestBuildState()
        {
            var lastCompletedBuild = new Build {BuildNumber = "1", Link = "lastCompletedBuildUrl"};

            SetupMockConnectionHelper(MockUrl, XDocument.Parse(
                String.Format("<root><lastBuild><number>{0}</number><url>{1}</url></lastBuild><build><number>{2}</number><url>{3}</url></build></root>", ExpectedResult.BuildNumber, ExpectedResult.Link, lastCompletedBuild.BuildNumber, lastCompletedBuild.Link)));

            SetupMockConnectionHelper(ExpectedResult.ApiLink, XDocument.Parse("<build><building>true</building></build>"));
            SetupMockConnectionHelper(lastCompletedBuild.ApiLink, XDocument.Parse("<build><result>Failure</result></build>"));

            _buildRepositoryToTest = new BuildRepository(_mockHelper.Object);

            var buildToTest = _buildRepositoryToTest.GetCurrentBuild(MockUrl);

            Assert.AreEqual(Build.BuildState.Failure, buildToTest.State);
        }
        public void ChangingSourceInBuildServiceManagerShouldShowNewSourceStatus()
        {
            var buildToSimulate = new Build {IsBuilding = false, State = Build.BuildState.Unknown};
            var newSourceBuildState = new Build {IsBuilding = true, State = Build.BuildState.Failure};

            var buildServiceManagerToTest = SetupMockData(buildToSimulate);

            _threadTask = Task.Factory.StartNew(buildServiceManagerToTest.Run);

            buildServiceManagerToTest.BuildSource = new User {Build = newSourceBuildState};

            Thread.Sleep(WaitTime);

            buildServiceManagerToTest.Stop();

            _threadTask.Wait();

            Assert.AreEqual(Light.Color.Red, buildServiceManagerToTest.Light.LightColor);
            Assert.AreNotEqual(0, _flashTurnOnCount);
        }
        public void ResetBuildServiceManagerShouldTurnOffAllLights()
        {
            var buildToSimulate = new Build { BuildNumber = "1", IsBuilding = false, State = Build.BuildState.Failure };
            var buildServiceManagerToTest = SetupMockData(buildToSimulate);

            _threadTask = Task.Factory.StartNew(buildServiceManagerToTest.Run);

            Thread.Sleep(WaitTime);

            //pause so we can reset the turn off count
            buildServiceManagerToTest.Pause();

            Thread.Sleep(WaitTime);

            _turnOffCount = 0;

            buildServiceManagerToTest.Reset();

            //verify that the all light colors have been turned off
            Assert.AreEqual(3, _turnOffCount);

            buildServiceManagerToTest.Stop();

            _threadTask.Wait();
        }
        private BuildServiceManager SetupMockData(Build buildToSimulate)
        {
            var source = new User
                    {
                        Build = buildToSimulate,
                        UpdateFrequency = 1
                    };

            return SetupMockData(source);
        }
        public void RunBuildServiceManagerWithUnstableBuild()
        {
            var buildToSimulate = new Build { BuildNumber = "1", IsBuilding = false, State = Build.BuildState.Unstable };
            var buildServiceManagerToTest = SetupMockData(buildToSimulate);

            _threadTask = Task.Factory.StartNew(buildServiceManagerToTest.Run);

            Thread.Sleep(WaitTime);

            buildServiceManagerToTest.Stop();

            _threadTask.Wait();

            //verify that the light has been set to yellow
            Assert.AreEqual(Light.Color.Yellow, buildServiceManagerToTest.Light.LightColor);
            Assert.AreEqual(0, _flashTurnOnCount);
        }
        public void RunBuildServiceManagerWithSuccessfulBuild()
        {
            var buildToSimulate = new Build {BuildNumber = "1", IsBuilding = true, State = Build.BuildState.Success};
            var buildServiceManagerToTest = SetupMockData(buildToSimulate);

            _threadTask = Task.Factory.StartNew(buildServiceManagerToTest.Run);

            Thread.Sleep(WaitTime);

            buildServiceManagerToTest.Stop();

            _threadTask.Wait();

            Assert.AreEqual(Light.Color.Green, buildServiceManagerToTest.Light.LightColor);
            Assert.AreNotEqual(0, _flashTurnOnCount);
        }
예제 #9
0
        private void GetBuildDetails(Build build)
        {
            if (build.ApiLink.Length <= 0) return;

            var lastBuildDetailsResponseXml = _connectionHelper.GetXmlResponse(build.ApiLink);

            var buildingElement = lastBuildDetailsResponseXml.Descendants("building").FirstOrDefault();

            if (buildingElement != null)
            {
                build.IsBuilding = Convert.ToBoolean(buildingElement.Value);
            }

            var resultElement = lastBuildDetailsResponseXml.Descendants("result").FirstOrDefault();

            if (resultElement == null) return;

            Build.BuildState buildValue;

            if (Enum.TryParse(resultElement.Value.ToLower(), true, out buildValue))
            {
                build.State = buildValue;
            }
            else
            {
                throw new UnknownBuildStateException(resultElement.Value);
            }
        }
예제 #10
0
        private void GetBuildStateForBuildInProgress(Build build, string rootUrl)
        {
            if (!build.IsBuilding) return;

            var pastBuilds = GetBuilds(rootUrl);

            foreach (var pastBuild in pastBuilds.Where(pastBuild => !pastBuild.BuildNumber.Equals(build.BuildNumber)))
            {
                GetBuildDetails(pastBuild);

                if (pastBuild.State.Equals(Build.BuildState.Unknown) || pastBuild.State.Equals(Build.BuildState.Aborted))
                {
                    continue;
                }

                build.State = pastBuild.State;

                break;
            }
        }