Example #1
0
        public void SyncToSettings_ForEachProjectIdentifier_GetsProjectCollectionFromCache()
        {
            var projectSettingses = new[]
            {
                new MonitoredProjectSettings {
                    VstsAccount = "1st server a/c", Id = Guid.NewGuid()
                },
                new MonitoredProjectSettings {
                    VstsAccount = "2nd server a/c", Id = Guid.NewGuid()
                },
                new MonitoredProjectSettings {
                    VstsAccount = "3rd server a/c", Id = Guid.NewGuid()
                },
            };

            _monitorSettings.Projects.Returns(projectSettingses);
            var tfsServer = Substitute.For <ITfProjectCollection>();

            tfsServer.GetProject(Arg.Any <Guid>()).Returns(Substitute.For <ITfProject>());
            _tfProjectCollectionCache.GetProjectCollection(Arg.Any <string>()).Returns(tfsServer);
            var systemUnderTest = new Monitor(_monitorSettings, _tfProjectCollectionCache, _nameRegexpRepositoryFilterFactory, _logger);

            systemUnderTest.SyncMonitoredProjects(projectSettingses);

            foreach (var projectIdentifier in projectSettingses)
            {
                _tfProjectCollectionCache.Received().GetProjectCollection(projectIdentifier.VstsAccount);
            }
        }
Example #2
0
        public void SyncToSettings_ForEachProjectIdentifierWithNonEmptyRepoNameRegexp_CreatesNameRegexpRepoFilter()
        {
            var projectSettingses = new[]
            {
                new MonitoredProjectSettings {
                    VstsAccount = "1st server url", Id = Guid.NewGuid()
                },
                new MonitoredProjectSettings {
                    VstsAccount = "2nd server url", Id = Guid.NewGuid(), RepoNameRegexp = "*"
                },
                new MonitoredProjectSettings {
                    VstsAccount = "3rd server url", Id = Guid.NewGuid(), RepoNameRegexp = "lasdf"
                },
            };

            _monitorSettings.Projects.Returns(projectSettingses);
            var tfsServer = Substitute.For <ITfProjectCollection>();

            tfsServer.GetProject(Arg.Any <Guid>()).Returns(Substitute.For <ITfProject>());
            _tfProjectCollectionCache.GetProjectCollection(Arg.Any <string>()).Returns(tfsServer);
            _nameRegexpRepositoryFilterFactory.Create(Arg.Any <string>()).Returns(new NameRegexpRepositoryFilter("*"));
            var systemUnderTest = new Monitor(_monitorSettings, _tfProjectCollectionCache, _nameRegexpRepositoryFilterFactory, _logger);

            systemUnderTest.SyncMonitoredProjects(projectSettingses);

            Assert.That(_nameRegexpRepositoryFilterFactory.ReceivedCalls().Count(),
                        Is.EqualTo(projectSettingses.Count(pi => !string.IsNullOrEmpty(pi.RepoNameRegexp))));
            foreach (var projectIdentifier in projectSettingses.Where(pi => !string.IsNullOrEmpty(pi.RepoNameRegexp)))
            {
                _nameRegexpRepositoryFilterFactory.Received().Create(projectIdentifier.RepoNameRegexp);
            }
        }
Example #3
0
        public void SyncToSettings_RemovesRemovedProjects()
        {
            var projectSettingses = new[] { _aMonitoredProjectSettings };

            _monitorSettings.Projects.Returns(projectSettingses);
            var tfProject = Substitute.For <ITfProject>();
            var tfsServer = Substitute.For <ITfProjectCollection>();

            tfsServer.GetProject(_aMonitoredProjectSettings.Id).Returns(tfProject);
            _tfProjectCollectionCache.GetProjectCollection(Arg.Any <string>()).Returns(tfsServer);
            var systemUnderTest = new Monitor(_monitorSettings, _tfProjectCollectionCache, _nameRegexpRepositoryFilterFactory, _logger);

            systemUnderTest.SyncMonitoredProjects(projectSettingses);
            Assert.That(systemUnderTest.Projects, Contains.Item(tfProject));

            systemUnderTest.SyncMonitoredProjects(Enumerable.Empty <MonitoredProjectSettings>());

            Assert.That(systemUnderTest.Projects, Does.Not.Contains(tfProject));
        }
Example #4
0
        public void Projects_WhenSettingsHasOneProject_HasOneProject()
        {
            var monitoredProjectSettingses = new[] { _aMonitoredProjectSettings };

            _monitorSettings.Projects.Returns(monitoredProjectSettingses);
            var monitor = new Monitor(_monitorSettings, _tfProjectCollectionCache, _nameRegexpRepositoryFilterFactory, _logger);

            monitor.SyncMonitoredProjects(monitoredProjectSettingses);

            Assert.That(monitor.Projects.Count(), Is.EqualTo(1));
        }
Example #5
0
        public void ApprovedPullRequestCount_ReturnsNumberOfApprovedPullRequests(int pullRequestCount)
        {
            var projectSettingses = new[] { _aMonitoredProjectSettings };

            _monitorSettings.Projects.Returns(projectSettingses);
            var tfProject = Substitute.For <ITfProject>();

            tfProject.ApprovedPullRequestCount.Returns(pullRequestCount);
            var tfsServer = Substitute.For <ITfProjectCollection>();

            tfsServer.GetProject(_aMonitoredProjectSettings.Id).Returns(tfProject);
            _tfProjectCollectionCache.GetProjectCollection(Arg.Any <string>()).Returns(tfsServer);
            var systemUnderTest = new Monitor(_monitorSettings, _tfProjectCollectionCache, _nameRegexpRepositoryFilterFactory, _logger);

            systemUnderTest.SyncMonitoredProjects(projectSettingses);

            Assert.That(systemUnderTest.ApprovedPullRequestCount, Is.EqualTo(pullRequestCount));
        }