Пример #1
0
        public TeamValidatorTests()
        {
            #region *** Mocks ***

            var tenantContextMock = TestMocks.GetTenantContextMock();
            var appDbMock         = TestMocks.GetAppDbMock();

            var teamRepoMock = TestMocks.GetRepo <TeamRepository>();
            teamRepoMock
            .Setup(rep => rep.TeamNameExistsAsync(It.IsAny <TeamEntity>(), It.IsAny <CancellationToken>()))
            .Callback(() => { }).Returns((TeamEntity teamEntity, CancellationToken cancellationToken) =>
            {
                return(Task.FromResult(teamEntity.Id < 10 ? teamEntity.Name : null));
            });
            appDbMock.Setup(a => a.TeamRepository).Returns(teamRepoMock.Object);

            var dbContextMock = TestMocks.GetDbContextMock();
            dbContextMock.SetupAppDb(appDbMock);

            tenantContextMock.SetupDbContext(dbContextMock);

            _tenantContext = tenantContextMock.Object;

            _appDb = appDbMock.Object;

            #endregion
        }
Пример #2
0
        public void RetrieveProjectManager_when_project_status_has_valid_webUrl_projectManager_should_use_it()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            List <JenkinsJob> allJobs = new List <JenkinsJob>();

            mocks.MockApi
            .Setup(x => x.GetAllJobs())
            .Returns(allJobs);

            Dictionary <string, ProjectStatus> projectsAndCurrentStatus = new Dictionary <string, ProjectStatus>();

            projectsAndCurrentStatus.Add("Test Project", null);

            mocks.MockJenkinsServerManager
            .Setup(x => x.ProjectsAndCurrentStatus)
            .Returns(projectsAndCurrentStatus);

            mocks.MockJenkinsServerManager
            .Setup(x => x.GetCruiseServerSnapshotEx())
            .Callback(() =>
            {
                // Simulate the project status being updated as per normal
                projectsAndCurrentStatus["Test Project"]        = new ProjectStatus();
                projectsAndCurrentStatus["Test Project"].WebURL = @"http://SomeTestServer5.com";
            });

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            ((JenkinsProjectManager)projectManager).WebURL.Should().Be(@"http://SomeTestServer5.com");
        }
Пример #3
0
        public void RetrieveProjectManager_when_server_unavailable_should_display_dialog()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            List <JenkinsJob> allJobs = new List <JenkinsJob>();

            mocks.MockApi
            .Setup(x => x.GetAllJobs())
            .Returns(allJobs);

            Dictionary <string, ProjectStatus> projectsAndCurrentStatus = new Dictionary <string, ProjectStatus>();

            mocks.MockJenkinsServerManager
            .Setup(x => x.ProjectsAndCurrentStatus)
            .Returns(projectsAndCurrentStatus);

            mocks.MockJenkinsServerManager
            .Setup(x => x.GetCruiseServerSnapshotEx())
            .Throws(new WebException("Test WebException Message"));

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            mocks.MockDialogService
            .Verify(x => x.Show("Test WebException Message"));
        }
Пример #4
0
        public void RetrieveServerManager_should_access_factory_singleton_instance()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            List <JenkinsJob> allJobs = new List <JenkinsJob>();

            mocks.MockApi
            .Setup(x => x.GetAllJobs())
            .Returns(allJobs);

            Dictionary <string, ProjectStatus> projectsAndCurrentStatus = new Dictionary <string, ProjectStatus>();

            mocks.MockJenkinsServerManager
            .Setup(x => x.ProjectsAndCurrentStatus)
            .Returns(projectsAndCurrentStatus);

            // Act
            target.RetrieveServerManager();

            // Assert
            mocks.MockJenkinsServerManagerFactory
            .Verify(x => x.GetInstance(),
                    Times.AtLeastOnce);
        }
Пример #5
0
        public void RetrieveServerManager_when_configure_window_has_been_shown_should_set_isInitialized_to_false()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            Mock <IForm> mockConfigurationForm = new Mock <IForm>();

            mockConfigurationForm
            .Setup(x => x.ShowDialog(It.IsAny <IWin32Window>()))
            .Returns(DialogResult.OK);

            mockConfigurationForm
            .Setup(x => x.GetServer())
            .Returns(@"https://SeomServer.com");

            mocks.MockConfigurationFormFactory
            .Setup(x => x.Create())
            .Returns(mockConfigurationForm.Object);

            // Act
            target.Configure(null);

            // Assert
            mocks.MockJenkinsServerManagerFactory
            .VerifySet(x => x.IsServerManagerInitialized = false);
        }
Пример #6
0
        public void RetrieveServerManager_should_initialize_serverManager()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            List <JenkinsJob> allJobs = new List <JenkinsJob>();

            mocks.MockApi
            .Setup(x => x.GetAllJobs())
            .Returns(allJobs);

            Dictionary <string, ProjectStatus> projectsAndCurrentStatus = new Dictionary <string, ProjectStatus>();

            mocks.MockJenkinsServerManager
            .Setup(x => x.ProjectsAndCurrentStatus)
            .Returns(projectsAndCurrentStatus);

            // Act
            target.RetrieveServerManager();

            // Assert
            mocks.MockJenkinsServerManager
            .Verify(x => x.Initialize(It.IsAny <BuildServer>(),
                                      It.IsAny <string>(), It.IsAny <string>()),
                    Times.Once);
        }
Пример #7
0
        public async Task Process_RespondsWithExtensionKeywords()
        {
            TestMocks mocks = new TestMocks();
            Mock <IExtensionProcessor> mockExtensionProcessor1 = new Mock <IExtensionProcessor>();

            mockExtensionProcessor1.Setup(ep => ep.GetEHLOKeywords()).ReturnsAsync(new[] { "EXTN1" });
            Mock <IExtensionProcessor> mockExtensionProcessor2 = new Mock <IExtensionProcessor>();

            mockExtensionProcessor2.Setup(ep => ep.GetEHLOKeywords()).ReturnsAsync(new[] { "EXTN2A", "EXTN2B" });

            mocks.Connection.SetupGet(c => c.ExtensionProcessors).Returns(new[]
            {
                mockExtensionProcessor1.Object,
                mockExtensionProcessor2.Object
            });

            EhloVerb ehloVerb = new EhloVerb();
            await ehloVerb.Process(mocks.Connection.Object, new SmtpCommand("EHLO foobar")).ConfigureAwait(false);

            mocks.Connection.Verify(c => c.WriteResponse(It.Is <SmtpResponse>(r =>

                                                                              r.Message.Contains("EXTN1") &&
                                                                              r.Message.Contains("EXTN2A") &&
                                                                              r.Message.Contains("EXTN2B")
                                                                              )));
        }
Пример #8
0
        /// <summary>
        /// The Process_AddressAsync
        /// </summary>
        /// <param name="address">The address<see cref="string"/></param>
        /// <param name="expectedParsedAddress">The expectedParsedAddress<see cref="string"/></param>
        /// <param name="expectedResponse">The expectedResponse<see cref="StandardSmtpResponseCode"/></param>
        /// <returns>A <see cref="Task{T}"/> representing the async operation</returns>
        private async Task Process_AddressAsync(string address, string expectedParsedAddress, StandardSmtpResponseCode expectedResponse, bool asException = false, bool eightBitMessage = false)
        {
            TestMocks mocks = new TestMocks();
            Mock <IMessageBuilder> message = new Mock <IMessageBuilder>();

            message.SetupGet(m => m.EightBitTransport).Returns(eightBitMessage);
            IMessageBuilder currentMessage = null;

            mocks.Connection.Setup(c => c.NewMessage()).ReturnsAsync(() =>
            {
                currentMessage = message.Object;
                return(currentMessage);
            });
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(() => currentMessage);

            MailFromVerb mailFromVerb = new MailFromVerb();

            if (!asException)
            {
                await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM " + address)).ConfigureAwait(false);

                mocks.VerifyWriteResponse(expectedResponse);
            }
            else
            {
                SmtpServerException e = await Assert.ThrowsAsync <SmtpServerException>(() => mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM " + address)));

                Assert.Equal((int)expectedResponse, e.SmtpResponse.Code);
            }

            if (expectedParsedAddress != null)
            {
                message.VerifySet(m => m.From = expectedParsedAddress);
            }
        }
Пример #9
0
        public void RetrieveProjectManager_when_projectName_already_has_current_status_should_not_get_server_snapshot()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            List <JenkinsJob> allJobs = new List <JenkinsJob>();

            mocks.MockApi
            .Setup(x => x.GetAllJobs())
            .Returns(allJobs);

            Dictionary <string, ProjectStatus> projectsAndCurrentStatus = new Dictionary <string, ProjectStatus>();

            projectsAndCurrentStatus.Add("Test Project", new ProjectStatus());

            mocks.MockJenkinsServerManager
            .Setup(x => x.ProjectsAndCurrentStatus)
            .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            mocks.MockJenkinsServerManager
            .Verify(x => x.GetCruiseServerSnapshot(),
                    Times.Never);
        }
Пример #10
0
        public async Task ProcessResponse_PasswordAcceptedAfterUserNameInInitialRequest()
        {
            TestMocks mocks = new TestMocks();

            mocks.ServerBehaviour.Setup(sb => sb.ValidateAuthenticationCredentials(It.IsAny <IConnection>(), It.IsAny <IAuthenticationCredentials>())).Returns(Task.FromResult(AuthenticationResult.Success));


            LoginMechanismProcessor      processor = this.Setup(mocks);
            AuthMechanismProcessorStatus result    = await processor.ProcessResponse(EncodeBase64("rob")).ConfigureAwait(false);

            Assert.Equal(AuthMechanismProcessorStatus.Continue, result);

            mocks.Connection.Verify(c =>
                                    c.WriteResponse(
                                        It.Is <SmtpResponse>(r =>
                                                             VerifyBase64Response(r.Message, "Password:"******"password")).ConfigureAwait(false);

            Assert.Equal(AuthMechanismProcessorStatus.Success, result);
        }
Пример #11
0
        public async Task Process_RecordsClientName()
        {
            TestMocks mocks    = new TestMocks();
            EhloVerb  ehloVerb = new EhloVerb();
            await ehloVerb.Process(mocks.Connection.Object, new SmtpCommand("EHLO foobar")).ConfigureAwait(false);

            mocks.Session.VerifySet(s => s.ClientName = "foobar");
        }
Пример #12
0
        public async Task Data_NoCurrentMessage_ReturnsError()
        {
            TestMocks mocks = new TestMocks();

            DataVerb verb = new DataVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.BadSequenceOfCommands);
        }
Пример #13
0
        public async Task Process_MissingAddress_ErrorResponse()
        {
            TestMocks mocks = new TestMocks();

            MailFromVerb mailFromVerb = new MailFromVerb();
            await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments);
        }
Пример #14
0
        public async Task Noop()
        {
            TestMocks mocks = new TestMocks();

            NoopVerb verb = new NoopVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("NOOP")).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
        }
Пример #15
0
        public async Task Quit_RespondsWithClosingChannel()
        {
            TestMocks mocks = new TestMocks();

            QuitVerb quitVerb = new QuitVerb();
            await quitVerb.Process(mocks.Connection.Object, new SmtpCommand("QUIT")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.ClosingTransmissionChannel);
        }
Пример #16
0
        public async Task ProcessAsync()
        {
            TestMocks mocks = new TestMocks();

            RsetVerb verb = new RsetVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("RSET")).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
            mocks.Connection.Verify(c => c.AbortMessage());
        }
Пример #17
0
        public async Task SayHelo_NoName()
        {
            TestMocks mocks = new TestMocks();

            HeloVerb verb = new HeloVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("HELO")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.OK);
            mocks.Session.VerifySet(s => s.ClientName = "");
        }
Пример #18
0
        public async Task Process_NoArguments_Accepted()
        {
            TestMocks mocks    = new TestMocks();
            EhloVerb  ehloVerb = new EhloVerb();
            await ehloVerb.Process(mocks.Connection.Object, new SmtpCommand("EHLO")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.OK);

            mocks.Session.VerifySet(s => s.ClientName = "");
        }
Пример #19
0
        public void Configuration_setter_should_update_configuration()
        {
            TestMocks mocks  = new TestMocks();
            var       target = CreateTestTarget(mocks);

            // Act
            target.Configuration = new BuildServer("https://some.othertest.server.com/");

            // Assert
            Assert.AreEqual(target.Configuration.Url, "https://some.othertest.server.com/");
        }
        public async Task ProcessResponse_Response_BadBase64()
        {
            await Assert.ThrowsAsync <BadBase64Exception>(async() =>
            {
                TestMocks mocks = new TestMocks();

                CramMd5MechanismProcessor cramMd5MechanismProcessor = this.Setup(mocks);
                await cramMd5MechanismProcessor.ProcessResponse(null).ConfigureAwait(false);
                await cramMd5MechanismProcessor.ProcessResponse("rob blah").ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
Пример #21
0
        public async Task SayHeloTwice_ReturnsError()
        {
            TestMocks mocks = new TestMocks();

            mocks.Session.SetupGet(s => s.ClientName).Returns("already.said.helo");

            HeloVerb verb = new HeloVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("HELO foo.blah")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.BadSequenceOfCommands);
        }
Пример #22
0
        public async Task Process_SaidHeloAlready_Allowed()
        {
            TestMocks mocks = new TestMocks();

            EhloVerb verb = new EhloVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("EHLO foo.blah")).ConfigureAwait(false);

            await verb.Process(mocks.Connection.Object, new SmtpCommand("EHLO foo.blah")).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
        }
        public void Configuration_setter_should_update_configuration()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            // Act
            target.Configuration = new BuildServer("https://some.othertest.server.com/");

            // Assert
            Assert.AreEqual(target.Configuration.Url, "https://some.othertest.server.com/");
        }
Пример #24
0
        public async Task NoCertificateAvailable_ReturnsErrorResponse()
        {
            TestMocks mocks = new TestMocks();

            mocks.ServerBehaviour.Setup(b => b.GetSSLCertificate(It.IsAny <IConnection>())).ReturnsAsync((X509Certificate)null);

            StartTlsVerb verb = new StartTlsVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("STARTTLS")).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.CommandNotImplemented);
        }
Пример #25
0
        public async Task Process_AlreadyGivenFrom_ErrorResponse()
        {
            TestMocks mocks = new TestMocks();

            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(new Mock <IMessageBuilder>().Object);

            MailFromVerb mailFromVerb = new MailFromVerb();
            await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM <*****@*****.**>")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.BadSequenceOfCommands);
        }
        public async Task ProcessRepsonse_ChallengeReponse_BadFormat()
        {
            await Assert.ThrowsAsync <SmtpServerException>(async() =>
            {
                TestMocks mocks = new TestMocks();

                string challenge = string.Format("{0}.{1}@{2}", FAKERANDOM, FAKEDATETIME, FAKEDOMAIN);

                CramMd5MechanismProcessor cramMd5MechanismProcessor = this.Setup(mocks, challenge);
                AuthMechanismProcessorStatus result = await cramMd5MechanismProcessor.ProcessResponse("BLAH").ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
Пример #27
0
        public async Task ProcessAsync_UnregisteredSubCommand_ErrorResponse()
        {
            TestMocks mocks = new TestMocks();

            Mock <VerbWithSubCommands> verbWithSubCommands = new Mock <VerbWithSubCommands>()
            {
                CallBase = true
            };

            await verbWithSubCommands.Object.Process(mocks.Connection.Object, new SmtpCommand("VERB SUBCOMMAND1")).ConfigureAwait(false);

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.CommandParameterNotImplemented);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mocks">The mocks<see cref="TestMocks"/></param>
        /// <param name="challenge">The challenge<see cref="string"/></param>
        /// <returns>The <see cref="CramMd5MechanismProcessor"/></returns>
        private CramMd5MechanismProcessor Setup(TestMocks mocks, string challenge = null)
        {
            Mock <IRandomIntegerGenerator> randomMock = new Mock <IRandomIntegerGenerator>();

            randomMock.Setup(r => r.GenerateRandomInteger(It.IsAny <int>(), It.IsAny <int>())).Returns(FAKERANDOM);

            Mock <ICurrentDateTimeProvider> dateMock = new Mock <ICurrentDateTimeProvider>();

            dateMock.Setup(d => d.GetCurrentDateTime()).Returns(new DateTime(FAKEDATETIME));

            mocks.ServerBehaviour.SetupGet(b => b.DomainName).Returns(FAKEDOMAIN);

            return(new CramMd5MechanismProcessor(mocks.Connection.Object, randomMock.Object, dateMock.Object, challenge));
        }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="address">The address<see cref="string"/></param>
        /// <param name="expectedAddress">The expectedAddress<see cref="string"/></param>
        /// <returns>A <see cref="Task{T}"/> representing the async operation</returns>
        private async Task TestGoodAddressAsync(string address, string expectedAddress, bool eightBit = false)
        {
            TestMocks            mocks          = new TestMocks();
            MemoryMessageBuilder messageBuilder = new MemoryMessageBuilder();

            messageBuilder.EightBitTransport = eightBit;
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            RcptToVerb verb = new RcptToVerb();
            await verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address)).ConfigureAwait(false);

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
            Assert.Equal(expectedAddress, messageBuilder.Recipients.First());
        }
Пример #30
0
        public static ITestEnvironment Create(Action <TestEnvironmentCreateContext> context)
        {
            var mocks = new TestMocks();

            var createContextObj = new TestEnvironmentCreateContext(mocks);

            context(createContextObj);

            mocks.DiscountsService.GetBundleStructure()
            .Returns(createContextObj.DiscountStructure.GetDiscountInfos());

            var environmentObject = new TestEnvironmentObject(createContextObj, mocks);

            return(environmentObject);
        }
Пример #31
0
        public async Task ProcessAsync_RegisteredSubCommand_Processed()
        {
            TestMocks mocks = new TestMocks();

            Mock <VerbWithSubCommands> verbWithSubCommands = new Mock <VerbWithSubCommands>()
            {
                CallBase = true
            };
            Mock <IVerb> verb = new Mock <IVerb>();

            verbWithSubCommands.Object.SubVerbMap.SetVerbProcessor("SUBCOMMAND1", verb.Object);

            await verbWithSubCommands.Object.Process(mocks.Connection.Object, new SmtpCommand("VERB SUBCOMMAND1")).ConfigureAwait(false);

            verb.Verify(v => v.Process(mocks.Connection.Object, new SmtpCommand("SUBCOMMAND1")));
        }
        public void RetrieveProjectManager_instance_should_be_initialized_with_current_configuration()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = (JenkinsProjectManager) target.RetrieveProjectManager("Test Project");

            // Assert
            target.Configuration.Should().Be(projectManager.Configuration);
        }
        public void RetrieveProjectManager_instance_AuthorizationInformation_should_not_be_null()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = (JenkinsProjectManager)target.RetrieveProjectManager("Test Project");

            // Assert
            projectManager.AuthorizationInformation.Should().NotBeNull();
        }
        public void RetrieveServerManager_should_initialize_serverManager()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            target.RetrieveServerManager();

            // Assert
            mocks.MockJenkinsServerManager
                .Verify(x => x.Initialize(It.IsAny<BuildServer>(),
                    It.IsAny<string>(), It.IsAny<string>()),
                    Times.Once);
        }
        public void RetrieveProjectManager_should_return_instance_of_JenkinsProjectManager()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            projectManager.Should().BeAssignableTo<JenkinsProjectManager>();
        }
        public void RetrieveProjectManager_when_projectName_does_not_exist_in_serverManager_should_be_added()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            mocks.JenkinsServerManager.ProjectsAndCurrentStatus.Should()
                .Contain(new KeyValuePair<string, ProjectStatus>("Test Project", null));
        }
        public void Settings_setter_should_update_settings()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            var settings = new Settings()
            {
                Project = "SomeProjectName",
                Username = "******",
                Password = "******",
                Server = "https://some.testserver.com/"
            };

            // Act
            target.Settings = settings.ToString();

            // Assert
            target.Settings.Should().Be(settings.ToString());
        }
        public void RetrieveProjectManager_when_project_status_has_valid_webUrl_projectManager_should_use_it()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            projectsAndCurrentStatus.Add("Test Project", null);

            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            mocks.MockJenkinsServerManager
                .Setup(x => x.GetCruiseServerSnapshotEx())
                .Callback(() =>
                {
                    // Simulate the project status being updated as per normal
                    projectsAndCurrentStatus["Test Project"] = new ProjectStatus();
                    projectsAndCurrentStatus["Test Project"].WebURL = @"http://SomeTestServer5.com";
                });

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            ((JenkinsProjectManager) projectManager).WebURL.Should().Be(@"http://SomeTestServer5.com");
        }
        public void RetrieveServerManager_should_access_factory_singleton_instance()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            target.RetrieveServerManager();

            // Assert
            mocks.MockJenkinsServerManagerFactory
                .Verify(x => x.GetInstance(),
                    Times.AtLeastOnce);
        }
        public void RetrieveServerManager_when_configure_window_has_been_shown_should_set_isInitialized_to_false()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            Mock<IForm> mockConfigurationForm = new Mock<IForm>();
            mockConfigurationForm
                .Setup(x => x.ShowDialog(It.IsAny<IWin32Window>()))
                .Returns(DialogResult.OK);

            mockConfigurationForm
                .Setup(x => x.GetServer())
                .Returns(@"https://SeomServer.com");

            mocks.MockConfigurationFormFactory
                .Setup(x => x.Create())
                .Returns(mockConfigurationForm.Object);

            // Act
            target.Configure(null);

            // Assert
            mocks.MockJenkinsServerManagerFactory
                .VerifySet(x => x.IsServerManagerInitialized = false);
        }
        public void RetrieveServerManager_when_server_has_already_been_configured_should_display_warning()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            Mock<IForm> mockConfigurationForm = new Mock<IForm>();
            mockConfigurationForm
                .Setup(x => x.ShowDialog(It.IsAny<IWin32Window>()))
                .Returns(DialogResult.OK);

            mockConfigurationForm
                .Setup(x => x.GetServer())
                .Returns(@"https://SeomServer.com");

            mocks.MockConfigurationFormFactory
                .Setup(x => x.Create())
                .Returns(mockConfigurationForm.Object);

            mocks.MockJenkinsServerManagerFactory
                .Setup(x => x.IsServerManagerInitialized)
                .Returns(true);

            // record the value from the dialog for assertion
            string displayedDialogText = String.Empty;
            mocks.MockDialogService
                .Setup(x => x.Show(It.IsAny<string>()))
                .Callback<string>((dialogText) => { displayedDialogText = dialogText; });

            // Act
            target.Configure(null);

            // Assert
            const string expectedDialogText = "Monitoring jobs from multiple jenkins servers is unsupported due to the CCTray interface.\n" +
                                              "If you have previously removed a jenkins server, restart CCTray first.";
            displayedDialogText.Should().Be(expectedDialogText);
        }
        private JenkinsTransportExtension CreateTestTarget(TestMocks mocks)
        {
            var Transport = new JenkinsTransportExtension();

            var settings = new Settings()
            {
                Project = String.Empty,
                Username = String.Empty,
                Password = String.Empty,
                Server = "https://builds.apache.org/"
            };

            Transport.JenkinsServerManagerFactory = mocks.JenkinsServerManagerFactory;
            Transport.WebRequestFactory = mocks.WebRequestFactory;
            Transport.JenkinsApiFactory = mocks.JenkinsApiFactory;
            Transport.ConfigurationFormFactory = mocks.ConfigurationFormFactory;
            Transport.DialogService = mocks.DialogService;

            Transport.Settings = settings.ToString();
            Transport.Configuration = new BuildServer(settings.Server);

            return Transport;
        }
        public void RetrieveProjectManager_when_server_unavailable_should_display_dialog()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            mocks.MockJenkinsServerManager
                .Setup(x => x.GetCruiseServerSnapshotEx())
                .Throws(new WebException("Test WebException Message"));

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            mocks.MockDialogService
                .Verify(x => x.Show("Test WebException Message"));
        }
        public void RetrieveProjectManager_when_projectName_does_not_have_current_status_should_get_server_snapshot()
        {
            TestMocks mocks = new TestMocks();
            var target = CreateTestTarget(mocks);

            List<JenkinsJob> allJobs = new List<JenkinsJob>();

            mocks.MockApi
                .Setup(x => x.GetAllJobs())
                .Returns(allJobs);

            Dictionary<string, ProjectStatus> projectsAndCurrentStatus = new Dictionary<string, ProjectStatus>();
            mocks.MockJenkinsServerManager
                .Setup(x => x.ProjectsAndCurrentStatus)
                .Returns(projectsAndCurrentStatus);

            // Act
            var projectManager = target.RetrieveProjectManager("Test Project");

            // Assert
            mocks.MockJenkinsServerManager
                .Verify(x => x.GetCruiseServerSnapshotEx(),
                Times.Once);
        }