public void ThrowAlreadyTriggeredBuildException_WhenBuildIsAlreadyTriggered()
        {
            IBuildAdapter buildAdapter = Mock.Create <IBuildAdapter>();

            Mock.Arrange(() => buildAdapter.GetSpecificBuildStatusXml(Arg.IsAny <string>())).Throws <WebException>();

            var jenkinsBuild = new BuildService(buildAdapter);

            jenkinsBuild.TriggerBuild(string.Empty, "35");
        }
        public void WaitUntilBuildStarts()
        {
            IBuildAdapter buildAdapter = Mock.Create <IBuildAdapter>();

            Mock.Arrange(() => buildAdapter.GetSpecificBuildStatusXml(Arg.IsAny <string>())).Returns(string.Empty);

            var jenkinsBuild = new BuildService(buildAdapter);

            jenkinsBuild.WaitUntilBuildStarts("32");
        }
        public void ThrowException_When30SecondsWebExceptionsAreThrown()
        {
            IBuildAdapter buildAdapter = Mock.Create <IBuildAdapter>();

            Mock.Arrange(() => buildAdapter.GetSpecificBuildStatusXml(Arg.IsAny <string>())).Throws <WebException>("The remote server returned an error: (404) Not Found.");
            DateTime startTime    = DateTime.Now;
            var      jenkinsBuild = new BuildService(buildAdapter);

            jenkinsBuild.WaitUntilBuildStarts("32");
            DateTime endTime = DateTime.Now;
            double   seconds = (endTime - startTime).TotalSeconds;

            Assert.IsTrue(seconds > 30 && seconds < 31, "The wait time in case of web exceptions was incorrect.");
        }
        public void GetBuildStatus()
        {
            IBuildAdapter buildAdapter = Mock.Create <IBuildAdapter>();

            Mock.Arrange(() => buildAdapter.GetSpecificBuildStatusXml(Arg.IsAny <string>())).Returns(string.Empty);
            Mock.Arrange(() => buildAdapter.GetBuildResult(Arg.IsAny <string>())).Returns("SUCCESS");

            var    jenkinsBuild = new BuildService(buildAdapter);
            string response     = jenkinsBuild.GetBuildStatus("35");

            Assert.AreEqual <string>(
                "SUCCESS",
                response,
                "The build was not triggered successfully.");
        }
        public void TriggerBuild()
        {
            IBuildAdapter buildAdapter = Mock.Create <IBuildAdapter>();

            Mock.Arrange(() => buildAdapter.GetSpecificBuildStatusXml(Arg.IsAny <string>())).Throws <WebException>("The remote server returned an error: (404) Not Found.");
            Mock.Arrange(() => buildAdapter.TriggerBuild(Arg.IsAny <string>())).Returns("SUCCESS");

            var    jenkinsBuild = new BuildService(buildAdapter);
            string response     = jenkinsBuild.TriggerBuild(string.Empty, "35");

            Assert.AreEqual <string>(
                "SUCCESS",
                response,
                "The build was not triggered successfully.");
        }