private static void SetNugetPackageDependencyExpectations(ITeamCityApi api, PackageBuildMappingCache cache, BuildTemplate template, IExternalIssueResolver issueResolver)
        {
            var initial = template.StartBuildPackages.Select(p => new TeamCityApi.PackageDetails {Id = p.Key, Version = p.Value}).ToList();
            var final = template.FinishBuildPackages.Select(p => new TeamCityApi.PackageDetails { Id = p.Key, Version = p.Value }).ToList();

            if (initial.Any())
            {
                A.CallTo(() => api.GetNuGetDependenciesByBuildTypeAndBuildId(template.BuildId, template.StartBuildNumber.ToString()))
                .Returns(initial);
            }

            if (initial.Any())
            {
                A.CallTo(() => api.GetNuGetDependenciesByBuildTypeAndBuildId(template.BuildId, template.FinishBuildNumber.ToString()))
                .Returns(final);
            }

            if (template.CreateNuGetPackageChangeManifests && initial.Any() && final.Any())
            {
                var packageDiffs = new PackageChangeComparator().GetPackageChanges(initial, final);
                foreach (var diff in packageDiffs.Where(d => d.Type == NuGetPackageChangeType.Modified))
                {
                    if (!cache.PackageBuildMappings.Any(c => c.PackageId.Equals(diff.PackageId) && c.BuildConfigurationId.Equals(diff.PackageId)))
                    {
                        cache.PackageBuildMappings.Add(new PackageBuildMapping
                        {
                            BuildConfigurationId = diff.PackageId,
                            BuildConfigurationName = diff.PackageId,
                            PackageId = diff.PackageId,
                            Project = diff.PackageId,
                            ServerUrl = api.Url
                        });
                    }

                    SetExpectations(new BuildTemplate
                        {
                            BuildId = diff.PackageId,
                            BuildCount = 15,
                            BuildName = diff.PackageId,
                            BuildNumberPattern = "1.{0}",
                            CreateNuGetPackageChangeManifests = false,
                            StartBuildNumber = Convert.ToInt16(diff.OldVersion.Split('.')[1]),
                            FinishBuildNumber = Convert.ToInt16(diff.NewVersion.Split('.')[1]),
                            IssueCount = 1,
                            NestedIssueChance = 100,
                            NestedIssueDepth = 1,
                        },
                        api,
                        issueResolver,
                        cache);
                }
            }
        }
예제 #2
0
        private static void SetExpectations(BuildTemplate template, ITeamCityApi api, IExternalIssueResolver issueResolver, PackageBuildMappingCache packageCache)
        {
            var startBuild  = string.Format(template.BuildNumberPattern, template.StartBuildNumber);
            var finishBuild = string.Format(template.BuildNumberPattern, template.FinishBuildNumber);

            //BuildType/Builds/ChangeDetails
            A.CallTo(() => api.GetBuildTypeDetailsById(template.BuildId))
            .Returns(new BuildTypeDetails
            {
                Id          = template.BuildId,
                Name        = template.BuildName,
                Description = template.BuildName,
            });

            var changeDetails = SetupBuildTypeAndBuilds(api, template);

            A.CallTo(() => api.GetChangeDetailsByBuildTypeAndBuildNumber(template.BuildId, startBuild, finishBuild, A <IEnumerable <Build> > .Ignored))
            .Returns(changeDetails.Where(c => Convert.ToInt16(c.Id) > template.StartBuildNumber && Convert.ToInt16(c.Id) <= template.FinishBuildNumber).ToList());

            //Issues
            if (template.IssueCount > 0)
            {
                var issues = Enumerable.Range(1, template.IssueCount).Select(i => new Issue {
                    Id = RandomNumber.Next(2000).ToString()
                }).ToList();

                A.CallTo(() => api.GetIssuesByBuildTypeAndBuildRange(template.BuildId, startBuild, finishBuild, A <IEnumerable <Build> > .Ignored))
                .Returns(issues);

                A.CallTo(issueResolver).WithReturnType <IEnumerable <ExternalIssueDetails> >()
                .Returns(CreateExternalIssueDetails(issues, template));
            }

            //NuGetPackages
            SetNugetPackageDependencyExpectations(api, packageCache, template, issueResolver);
            SetNugetPackageDependencyExpectations(api, packageCache, template, issueResolver);
        }
        private static void SetExpectations(BuildTemplate template, ITeamCityApi api, IExternalIssueResolver issueResolver, PackageBuildMappingCache packageCache)
        {
            var startBuild = string.Format(template.BuildNumberPattern, template.StartBuildNumber);
            var finishBuild = string.Format(template.BuildNumberPattern, template.FinishBuildNumber);

            //BuildType/Builds/ChangeDetails
            A.CallTo(() => api.GetBuildTypeDetailsById(template.BuildId))
             .Returns(new BuildTypeDetails
                 {
                     Id = template.BuildId,
                     Name = template.BuildName,
                     Description = template.BuildName,
                 });

            var changeDetails = SetupBuildTypeAndBuilds(api, template);
            A.CallTo(() =>api.GetChangeDetailsByBuildTypeAndBuildNumber(template.BuildId, startBuild, finishBuild, A<IEnumerable<Build>>.Ignored))
             .Returns(changeDetails.Where(c => Convert.ToInt16(c.Id) > template.StartBuildNumber && Convert.ToInt16(c.Id) <= template.FinishBuildNumber).ToList());

            //Issues
            if (template.IssueCount > 0)
            {
                var issues = Enumerable.Range(1, template.IssueCount).Select(i => new Issue {Id = RandomNumber.Next(2000).ToString()}).ToList();

                A.CallTo(() => api.GetIssuesByBuildTypeAndBuildRange(template.BuildId, startBuild, finishBuild, A<IEnumerable<Build>>.Ignored))
                 .Returns(issues);

                A.CallTo(issueResolver).WithReturnType<IEnumerable<ExternalIssueDetails>>()
                 .Returns(CreateExternalIssueDetails(issues, template));
            }

            //NuGetPackages
            SetNugetPackageDependencyExpectations(api, packageCache, template, issueResolver);
            SetNugetPackageDependencyExpectations(api, packageCache, template, issueResolver);
        }
예제 #4
0
        private static void SetNugetPackageDependencyExpectations(ITeamCityApi api, PackageBuildMappingCache cache, BuildTemplate template, IExternalIssueResolver issueResolver)
        {
            var initial = template.StartBuildPackages.Select(p => new TeamCityApi.PackageDetails {
                Id = p.Key, Version = p.Value
            }).ToList();
            var final = template.FinishBuildPackages.Select(p => new TeamCityApi.PackageDetails {
                Id = p.Key, Version = p.Value
            }).ToList();

            if (initial.Any())
            {
                A.CallTo(() => api.GetNuGetDependenciesByBuildTypeAndBuildId(template.BuildId, template.StartBuildNumber.ToString()))
                .Returns(initial);
            }

            if (initial.Any())
            {
                A.CallTo(() => api.GetNuGetDependenciesByBuildTypeAndBuildId(template.BuildId, template.FinishBuildNumber.ToString()))
                .Returns(final);
            }

            if (template.CreateNuGetPackageChangeManifests && initial.Any() && final.Any())
            {
                var packageDiffs = new PackageChangeComparator().GetPackageChanges(initial, final);
                foreach (var diff in packageDiffs.Where(d => d.Type == NuGetPackageChangeType.Modified))
                {
                    if (!cache.PackageBuildMappings.Any(c => c.PackageId.Equals(diff.PackageId) && c.BuildConfigurationId.Equals(diff.PackageId)))
                    {
                        cache.PackageBuildMappings.Add(new PackageBuildMapping
                        {
                            BuildConfigurationId   = diff.PackageId,
                            BuildConfigurationName = diff.PackageId,
                            PackageId = diff.PackageId,
                            Project   = diff.PackageId,
                            ServerUrl = api.TeamCityServer
                        });
                    }

                    SetExpectations(new BuildTemplate
                    {
                        BuildId            = diff.PackageId,
                        BuildCount         = 15,
                        BuildName          = diff.PackageId,
                        BuildNumberPattern = "1.{0}",
                        CreateNuGetPackageChangeManifests = false,
                        StartBuildNumber  = Convert.ToInt16(diff.OldVersion.Split('.')[1]),
                        FinishBuildNumber = Convert.ToInt16(diff.NewVersion.Split('.')[1]),
                        IssueCount        = 1,
                        NestedIssueChance = 100,
                        NestedIssueDepth  = 1,
                    },
                                    api,
                                    issueResolver,
                                    cache);
                }
            }
        }