public void InitialiseLoadsNumberOfRequestsAllowed()
        {
            var extension = new IntegrationRequestThrottleExtension();
            var serverMock = this.mocks.StrictMock<ICruiseServer>();
            var config = new ExtensionConfiguration();
            config.Items = new[] 
                {
                    GenerateElement("limit", "10")
                };
            Expect.Call(() => serverMock.IntegrationCompleted += null).IgnoreArguments();
            Expect.Call(() => serverMock.IntegrationStarted += null).IgnoreArguments();

            this.mocks.ReplayAll();
            extension.Initialise(serverMock, config);

            this.mocks.VerifyAll();
            Assert.AreEqual(10, extension.NumberOfRequestsAllowed);
        }
        public void IntegrationStartIsAllowedWhenWithinLimit()
        {
            var extension = new IntegrationRequestThrottleExtension();
            var serverMock = this.mocks.StrictMock<ICruiseServer>();
            var config = new ExtensionConfiguration();
            Expect.Call(() => serverMock.IntegrationCompleted += null).IgnoreArguments();
            var startRaiser = Expect
                .Call(() => serverMock.IntegrationStarted += null)
                .IgnoreArguments()
                .GetEventRaiser();
            var eventArgs = new IntegrationStartedEventArgs(null, "TestProject");

            this.mocks.ReplayAll();
            extension.Initialise(serverMock, config);
            startRaiser.Raise(serverMock, eventArgs);

            this.mocks.VerifyAll();
            Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Continue, eventArgs.Result);
        }
        public void IntegrationStartAllowedAtTopOfQueue()
        {
            var extension = new IntegrationRequestThrottleExtension();
            var serverMock = this.mocks.StrictMock<ICruiseServer>();
            var config = new ExtensionConfiguration();
            var completeRaiser = Expect
                .Call(() => serverMock.IntegrationCompleted += null)
                .IgnoreArguments()
                .GetEventRaiser();
            var startRaiser = Expect
                .Call(() => serverMock.IntegrationStarted += null)
                .IgnoreArguments()
                .GetEventRaiser();
            var eventArgs = new IntegrationStartedEventArgs(null, "TestProject");

            this.mocks.ReplayAll();
            extension.Initialise(serverMock, config);
            extension.NumberOfRequestsAllowed = 1;
            startRaiser.Raise(serverMock, new IntegrationStartedEventArgs(null, "First"));
            startRaiser.Raise(serverMock, eventArgs);
            startRaiser.Raise(serverMock, new IntegrationStartedEventArgs(null, "Third"));
            completeRaiser.Raise(
                serverMock,
                new IntegrationCompletedEventArgs(null, "First", IntegrationStatus.Success));
            startRaiser.Raise(serverMock, eventArgs);

            this.mocks.VerifyAll();
            Assert.AreEqual(IntegrationStartedEventArgs.EventResult.Continue, eventArgs.Result);
        }
        public void StartAndAbortDoesNothing()
        {
            var extension = new IntegrationRequestThrottleExtension();
            var serverMock = this.mocks.StrictMock<ICruiseServer>();
            var config = new ExtensionConfiguration();
            Expect.Call(() => serverMock.IntegrationCompleted += null).IgnoreArguments();
            Expect.Call(() => serverMock.IntegrationStarted += null).IgnoreArguments();

            this.mocks.ReplayAll();
            extension.Initialise(serverMock, config);
            extension.Start();
            extension.Abort();

            this.mocks.VerifyAll();
        }