public async Task AddSameTags_VariousRepos_FlattenedProperly()
        {
            //arrange
            var db = new StatisticsDatabase(Settings);
            StatisticsService service = new StatisticsService(db, new Mapper(MappingConfigurationFactory.Create()));

            var parameter1 = new RepositoryQueryParameter(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            await service.Update(parameter1, new [] { "FirstTag", "SecondTag", "Third" }).ConfigureAwait(false);

            await service.Update(parameter1, new[] { "FIRSTTAG", "", "Fourth" }).ConfigureAwait(false);

            await service.Update(parameter1, new[] { "FIRSTTAG", "SecondTag", "Fourth" }).ConfigureAwait(false);


            parameter1 = new RepositoryQueryParameter(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            await service.Update(parameter1, new[] { "FirstTag", "SecondTag", "Fourth" }).ConfigureAwait(false);

            await service.Update(parameter1, new[] { "Fifth", "Sixth" }).ConfigureAwait(false);

            //act
            List <SearchKeywordData> result = (await service.GetFlattened().ConfigureAwait(false)).ToList();


            //assert
            result.Count.Should().Be(6);
            result.Single(x => x.Keyword == "FirstTag").SearchCount.Should().Be(4);
            result.Single(x => x.Keyword == "SecondTag").SearchCount.Should().Be(3);
            result.Single(x => x.Keyword == "Third").SearchCount.Should().Be(1);
            result.Single(x => x.Keyword == "Fourth").SearchCount.Should().Be(3);
            result.Single(x => x.Keyword == "Fifth").SearchCount.Should().Be(1);
            result.Single(x => x.Keyword == "Sixth").SearchCount.Should().Be(1);
        }
Пример #2
0
        private static void ConfigureAutoMapper(IServiceCollection services)
        {
            var     mappingConfig = MappingConfigurationFactory.Create();
            IMapper mapper        = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);
        }
        public async Task AddSameTags_ValuesIncrementedProperly()
        {
            var db = new StatisticsDatabase(Settings);
            StatisticsService service         = new StatisticsService(db, new Mapper(MappingConfigurationFactory.Create()));
            string            organizationOne = Guid.NewGuid().ToString();
            string            repoOne         = Guid.NewGuid().ToString();

            var parameter = new RepositoryQueryParameter(organizationOne, repoOne);

            string[]         words  = new[] { "FirstTag", "SecondTag", "Third" };
            SearchStatistics stats1 = await service.Update(parameter, words).ConfigureAwait(false);

            SearchStatistics stats2 = await service.Update(parameter, words).ConfigureAwait(false);

            stats1.RepositoryName.Should().Be(stats2.RepositoryName);
            stats1.SearchKeywordData.Count.Should().Be(3);
            foreach (SearchKeywordData searchKeywordData in stats1.SearchKeywordData)
            {
                Assert.AreEqual(1, searchKeywordData.SearchCount);
            }
            stats2.SearchKeywordData.Count.Should().Be(3);
            foreach (SearchKeywordData searchKeywordData in stats2.SearchKeywordData)
            {
                Assert.AreEqual(2, searchKeywordData.SearchCount);
            }
        }
Пример #4
0
        public async Task TestGet_NoWildcards_ReturnsOnlySpecifiedOrgs()
        {
            //arrange
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()),
                                                          TelemetryMock.InitializeMockTelemetryClient());
            var parameters = new[]
            {
                new RepositoryQueryParameter(this.orgOne_RepoOne),
                new RepositoryQueryParameter(this.orgTwo_RepoOne),
                new RepositoryQueryParameter(this.orgThree_RepoOne),
            };
            var repos = (await service.GetRepositories(parameters)).ToList();

            //act
            ManifestQueryResult result = await service.GetCurrentProjects(repos, "FindMe", false);

            //assert
            Assert.AreEqual(3, result.Projects.Count);
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgOne_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgOne_RepoTwo.Id));
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgTwo_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgTwo_RepoTwo.Id));
            Assert.AreEqual(1, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoOne.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoTwo.Id));
            Assert.AreEqual(0, result.Projects.Count(x => x.RepositoryInfo.Id == this.orgThree_RepoThree.Id));
        }
Пример #5
0
        public async Task DefaultRepoProjects_NotCleanedUp()
        {
            //arrange
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), TelemetryMock.InitializeMockTelemetryClient());

            await SeedProjects(service, "Project1", this.defaultRepoOne, "1.0.0", "2.0.0", "3.0.0", "4.0.0");
            await SeedProjects(service, "Project2", this.defaultRepoOne, "1.0.0", "2.0.0", "3.0.0", "4.0.0");
            await SeedProjects(service, "Project3", this.defaultRepoOne, "1.0.0", "2.0.0", "3.0.0", "4.0.0");
            await SeedProjects(service, "Project4", this.defaultRepoOne, "1.0.0", "2.0.0", "3.0.0", "4.0.0");

            SnapshotRepoCleaner cleaner = new SnapshotRepoCleaner(database);

            //assuming...
            Check.That(database.GetAllProjects().Result.Count()).Equals(4);

            //act
            SnapshotRepoCleanupResult result = await cleaner.PerformCleanupAsync(new SnapshotRepoCleanupSettings()
            {
            });

            //assert
            Check.That(result.RepositoryResults.Count).IsEqualTo(0);
            Check.That(database.GetAllProjects().Result.Count()).Equals(4);
        }
Пример #6
0
        public async Task SnapshotRepoProjects_SettingsChange_AffectsTheNumberOfProjectsLeft()
        {
            //arrange
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), TelemetryMock.InitializeMockTelemetryClient());

            await SeedProjects(service, "Project1", this.snapshotRepoOne, "1.0.0", "2.0.0", "3.0.0", "4.0.0");

            SnapshotRepoCleaner cleaner = new SnapshotRepoCleaner(database);

            //assuming...
            Check.That(database.GetAllProjects().Result.Count()).Equals(4);

            //act
            SnapshotRepoCleanupResult result = await cleaner.PerformCleanupAsync(new SnapshotRepoCleanupSettings()
            {
                NumberOfSnapshotsToKeep = 3
            });

            //assert
            Check.That(result.RepositoryResults.Single().Value).IsEqualTo(1);
            Check.That(database.GetAllProjects().Result.Count()).Equals(3);

            //now change settings and run again

            //act
            result = await cleaner.PerformCleanupAsync(new SnapshotRepoCleanupSettings()
            {
                NumberOfSnapshotsToKeep = 1
            });

            //assert
            Check.That(result.RepositoryResults.Single().Value).IsEqualTo(2);
            Check.That(database.GetAllProjects().Result.Count()).Equals(1);
        }
Пример #7
0
        public async Task SnapshotRepo_ShouldOnlyReturnLastProjects()
        {
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), this.telemetryClient);

            await SetSnapshotMode(database, this.testRepoOne).ConfigureAwait(false);

            var allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);

            allProjects.Projects.Count.Should().Be(0, "because there are no projects yet");

            ProjectInfo returnedPrj2 = await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            //now add just one with new stamp
            RepoCat.Transmission.Models.ProjectInfo prj2Again = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName    = "Project2",
                ProjectUri     = "SomeLocation",
                RepositoryInfo = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "2.0"
            };
            var returnedPrj2Again = await service.Upsert(prj2Again).ConfigureAwait(false);

            allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);


            allProjects.Projects.Count.Should().Be(1, "because recently only added 1 project");
            allProjects.Projects.Should().OnlyContain(x => x.ProjectInfo.RepositoryStamp == "2.0");

            returnedPrj2Again.Id.Should().NotBe(returnedPrj2.Id);
            returnedPrj2Again.ProjectUri.Should().Be(returnedPrj2.ProjectUri);
            returnedPrj2Again.ProjectName.Should().Be(returnedPrj2.ProjectName);
            returnedPrj2Again.RepositoryId.Should().Be(returnedPrj2.RepositoryId);
        }
Пример #8
0
        public async Task TestMultipleRepos_RelevantProjectsDeleted()
        {
            //arrange
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), TelemetryMock.InitializeMockTelemetryClient());

            await SeedProjects(service, "Project1", this.snapshotRepoOne, "1.0.0", "2.0.0", "3.0.0");
            await SeedProjects(service, "Project2", this.snapshotRepoOne, "1.0.0");
            await SeedProjects(service, "Project3", this.snapshotRepoTwo, "1.0.0", "2.0.0", "3.0.0", "4.0.0");
            await SeedProjects(service, "Project4", this.snapshotRepoTwo, "1.0.0", "4.0.0");
            await SeedProjects(service, "Project5", this.defaultRepoOne, "1.0.0", "5.0.0");

            SnapshotRepoCleaner cleaner = new SnapshotRepoCleaner(database);

            //assuming...
            Check.That(database.GetAllProjects().Result.Count()).Equals(11);

            //act
            SnapshotRepoCleanupResult result = await cleaner.PerformCleanupAsync(new SnapshotRepoCleanupSettings());

            //assert
            Check.That(result.RepositoryResults.Keys.Select(x => x.RepositoryName)).ContainsExactly(this.snapshotRepoOne.RepositoryName, this.snapshotRepoTwo.RepositoryName);
            Check.That(result.RepositoryResults.Single(x => x.Key.Id == this.snapshotRepoOne.Id).Value.Equals(2));
            Check.That(result.RepositoryResults.Single(x => x.Key.Id == this.snapshotRepoTwo.Id).Value.Equals(3));

            var allProjects = database.GetAllProjects().Result.ToList();

            Check.That(allProjects.Count()).Equals(6);

            Check.That(allProjects.Where(x => x.RepositoryId == this.snapshotRepoOne.Id).Select(x => x.ProjectName))
            .ContainsExactly("Project1", "Project1");

            Check.That(allProjects.Where(x => x.RepositoryId == this.snapshotRepoTwo.Id).Select(x => x.ProjectName))
            .ContainsExactly("Project3", "Project3", "Project4");

            Check.That(allProjects.Where(x => x.RepositoryId == this.defaultRepoOne.Id).Select(x => x.ProjectName))
            .ContainsExactly("Project5");
        }
Пример #9
0
        public void AssertConfigIsValid()
        {
            var mappingConfig = MappingConfigurationFactory.Create();

            mappingConfig.AssertConfigurationIsValid();
        }
Пример #10
0
        public async Task DefaultRepo_ShouldReturnUpdatedProjects()
        {
            RepositoryDatabase database = new RepositoryDatabase(Settings);
            var service     = new RepositoryManagementService(database, new Mapper(MappingConfigurationFactory.Create()), this.telemetryClient);
            var allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);

            allProjects.Projects.Count.Should().Be(0, "because there are no projects yet");

            await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            ProjectInfo returnedPrj2 = await this.AddTwoProjectsWithSameRepoStamp(service).ConfigureAwait(false);

            //now add just one with new stamp and some changed properties (except for name and URI)
            RepoCat.Transmission.Models.ProjectInfo prj2Again = new RepoCat.Transmission.Models.ProjectInfo()
            {
                ProjectName        = "Project2",
                ProjectUri         = "SomeLocation",
                Owner              = "An Owner",
                ProjectDescription = "A description",
                RepositoryInfo     = new RepoCat.Transmission.Models.RepositoryInfo()
                {
                    RepositoryName   = this.testRepoOne.RepositoryName,
                    OrganizationName = this.testRepoOne.OrganizationName,
                },

                TargetExtension = "exe",
                RepositoryStamp = "2.0",
                AssemblyName    = "Project2AssName_NEW",
                Components      =
                {
                    new ComponentManifest(new List <string>()
                    {
                        "Three", "Four"
                    }, new PropertiesCollection()
                    {
                        { "KeyTwo", "ValueTwo" }
                    }
                                          )
                }
            };

            var returnedPrj2Again = await service.Upsert(prj2Again).ConfigureAwait(false);

            allProjects = await service.GetAllCurrentProjects(this.testRepoOne).ConfigureAwait(false);


            allProjects.Projects.Count.Should().Be(2, "because we don't return latest stamp only");
            allProjects.Projects.Should().Contain(x => x.ProjectInfo.RepositoryStamp == "2.0");
            allProjects.Projects.Should().Contain(x => x.ProjectInfo.RepositoryStamp == "1.0");

            returnedPrj2Again.Id.Should().Be(returnedPrj2.Id);
            returnedPrj2Again.ProjectUri.Should().Be(returnedPrj2.ProjectUri);
            returnedPrj2Again.ProjectName.Should().Be(returnedPrj2.ProjectName);
            returnedPrj2Again.RepositoryId.Should().Be(returnedPrj2.RepositoryId);

            var prj2ReturnedFromQuery = allProjects.Projects.Single(x => string.Equals(x.ProjectInfo.ProjectName, "Project2", StringComparison.Ordinal));

            prj2ReturnedFromQuery.ProjectInfo.Id.Should().Be(returnedPrj2Again.Id);
            prj2ReturnedFromQuery.ProjectInfo.RepositoryStamp.Should().Be("2.0");
            prj2ReturnedFromQuery.ProjectInfo.AssemblyName.Should().Be("Project2AssName_NEW");
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Tags.Count.Should().Be(2);
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Properties.Count.Should().Be(1);
            prj2ReturnedFromQuery.ProjectInfo.Components.Single().Properties["KeyTwo"].Should().Be("ValueTwo");
            prj2ReturnedFromQuery.ProjectInfo.Owner.Should().Be("An Owner");
            prj2ReturnedFromQuery.ProjectInfo.ProjectDescription.Should().Be("A description");
        }