public void FirePassesInLoginCredentialsAndHandlesFailure()
        {
            var credentials = new[]
            {
                new NameValuePair("user", "me")
            };
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = InitialiseClientMock(
                false,
                NewProjectStatus("project", IntegrationStatus.Success, now));

            Mock.Get(clientMock).Setup(_clientMock => _clientMock.Login(new List <NameValuePair>(credentials))).Returns(false).Verifiable();
            var factoryMock = this.InitialiseFactoryMock(clientMock);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project             = "project",
                InnerTrigger        = innerTriggerMock,
                TriggerFirstTime    = true,
                SecurityCredentials = credentials
            };

            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
            var expected = ModificationExistRequest();

            Assert.AreEqual(expected, actual);
        }
        public void FirePassesInLoginCredentialsAndLogsOut()
        {
            var credentials = new[]
            {
                new NameValuePair("user", "me")
            };
            var innerTriggerMock = this.InitialiseTriggerMock(1);
            var clientMock       = InitialiseClientMock(
                false,
                NewProjectStatus("project", IntegrationStatus.Success, now));

            Expect.Call(clientMock.Login(new List <NameValuePair>(credentials))).Return(true);
            Expect.Call(clientMock.SessionToken).Return("token");
            Expect.Call(() => clientMock.Logout());
            var factoryMock = this.InitialiseFactoryMock(clientMock);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project             = "project",
                InnerTrigger        = innerTriggerMock,
                TriggerFirstTime    = true,
                SecurityCredentials = credentials
            };

            this.mocks.ReplayAll();
            var actual = trigger.Fire();

            this.mocks.VerifyAll();
            var expected = ModificationExistRequest();

            Assert.AreEqual(expected, actual);
        }
        public void DoNotTriggerIfProjectHasNotBuiltSinceLastPoll()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMocks      = new[]
            {
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, now)),
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, now))
            };
            var factoryMock = this.InitialiseFactoryMock(clientMocks);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            trigger.Fire();
            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 2);
            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void DoNotTriggerWhenDependentProjectBuildFails()
        {
            var innerTriggerMock = this.InitialiseTriggerMock(2);
            var clientMocks      = new[]
            {
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, now)),
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Failure, later))
            };
            var factoryMock = this.InitialiseFactoryMock(clientMocks);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            this.mocks.ReplayAll();
            trigger.Fire();
            var actual = trigger.Fire();

            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void TriggerWhenDependentProjectBuildsSuccessfully()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMocks      = new[]
            {
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, now)),
                InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, later))
            };
            var factoryMock = this.InitialiseFactoryMock(clientMocks);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            trigger.Fire();
            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 2);
            this.mocks.VerifyAll();
            var expected = ModificationExistRequest();

            Assert.AreEqual(expected, actual);
        }
        public void HandleExceptionInProjectLocator()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = this.InitialiseClientMock(true, NewProjectStatus("wrong", IntegrationStatus.Failure, now));
            var factoryMock      = this.InitialiseFactoryMock(clientMock);
            var trigger          = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            Assert.Throws <NoSuchProjectException>(() => trigger.Fire());

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
        }
        public void ShouldNotTriggerOnFirstIntegration()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Success, now));
            var factoryMock      = this.InitialiseFactoryMock(clientMock);
            var trigger          = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void DoNotTriggerWhenInnerTriggerReturnsNoBuild()
        {
            var innerTriggerMock = this.mocks.Create <ITrigger>(MockBehavior.Strict).Object;

            Mock.Get(innerTriggerMock).Setup(_innerTrigger => _innerTrigger.Fire()).Returns(() => null).Verifiable();
            var factoryMock = this.mocks.Create <ICruiseServerClientFactory>(MockBehavior.Strict).Object;
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            var actual = trigger.Fire();

            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void ShouldNotTriggerOnFirstIntegrationIfDependentProjectBuildFailedAndTriggerFirstTimeIsSet()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = InitialiseClientMock(true, NewProjectStatus("project", IntegrationStatus.Failure, now));
            var factoryMock      = this.InitialiseFactoryMock(clientMock);
            var trigger          = new ProjectTrigger(factoryMock)
            {
                Project          = "project",
                InnerTrigger     = innerTriggerMock,
                TriggerFirstTime = true
            };

            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void DoNotTriggerWhenInnerTriggerReturnsNoBuild()
        {
            var innerTriggerMock = this.mocks.StrictMock <ITrigger>();

            Expect.Call(innerTriggerMock.Fire()).Return(null);
            var factoryMock = this.mocks.StrictMock <ICruiseServerClientFactory>();
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            this.mocks.ReplayAll();
            var actual = trigger.Fire();

            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void HandleSocketError()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = this.mocks.Create <CruiseServerClientBase>(MockBehavior.Strict).Object;
            var factoryMock      = this.InitialiseFactoryMock(clientMock);

            Mock.Get(clientMock).SetupSet(_clientMock => _clientMock.SessionToken = It.IsAny <string>()).Verifiable();
            Mock.Get(clientMock).Setup(_clientMock => _clientMock.GetProjectStatus())
            .Throws(new SocketException()).Verifiable();
            var trigger = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void HandleSocketError()
        {
            var innerTriggerMock = this.InitialiseTriggerMock(1);
            var clientMock       = this.mocks.StrictMock <CruiseServerClientBase>();
            var factoryMock      = this.InitialiseFactoryMock(clientMock);

            Expect.Call(clientMock.SessionToken).SetPropertyAndIgnoreArgument();
            Expect.Call(clientMock.GetProjectStatus())
            .Throw(new SocketException());
            var trigger = new ProjectTrigger(factoryMock)
            {
                Project      = "project",
                InnerTrigger = innerTriggerMock
            };

            this.mocks.ReplayAll();
            var actual = trigger.Fire();

            this.mocks.VerifyAll();
            Assert.IsNull(actual);
        }
        public void ShouldTriggerOnFirstIntegrationIfDependentProjectBuildSucceededAndTriggerFirstTimeIsSet()
        {
            var innerTriggerMock = this.InitialiseTriggerMock();
            var clientMock       = InitialiseClientMock(
                true,
                NewProjectStatus("project", IntegrationStatus.Success, now));
            var factoryMock = this.InitialiseFactoryMock(clientMock);
            var trigger     = new ProjectTrigger(factoryMock)
            {
                Project          = "project",
                InnerTrigger     = innerTriggerMock,
                TriggerFirstTime = true
            };

            var actual = trigger.Fire();

            this.InitialiseTriggerMockVerify(innerTriggerMock, 1);
            this.mocks.VerifyAll();
            var expected = ModificationExistRequest();

            Assert.AreEqual(expected, actual);
        }