Exemplo n.º 1
0
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var expected    = $"SEP=;{Environment.NewLine}Collection;Project;Repistory;Branch;Build nr;Build status;Build result;Artifact name;Artifact type;Artifact download;{Environment.NewLine}testValue;testValue;testValue;testValue;testValue;testValue;testValue;testValue;testValue;https://www.example.com/;{Environment.NewLine}";
            var testUri     = new Uri("https://www.example.com/");
            var testString  = "testValue";
            var testInt     = 1;
            var testProject = new AzureDevOpsProject
            {
                Name   = testString,
                Builds = new HashSet <AzureDevOpsBuild>
                {
                    new AzureDevOpsBuild
                    {
                        SourceBranch = testString,
                        BuildNumber  = testString,
                        Status       = testString,
                        Result       = testString,
                        Repository   = new AzureDevOpsSourceRepository
                        {
                            Name = testString,
                        },
                        Artifacts = new HashSet <AzureDevOpsBuildArtifact>
                        {
                            new AzureDevOpsBuildArtifact
                            {
                                Id       = testInt,
                                Name     = testString,
                                Resource = new AzureDevOpsArtifactResource
                                {
                                    Type        = testString,
                                    DownloadUrl = testUri,
                                },
                            },
                        },
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection {
                Name = testString
            };

            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();

            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new BuildReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
Exemplo n.º 2
0
        private void MakeGitReport(AzureDevOpsProject project)
        {
            this.CreateHeaders(
                "Name",
                "Protected master",
                ">1 approvers",
                "Reset on push",
                "Comment resolution",
                "Build check",
                "Remarks",
                "Link");

            foreach (var repository in project.Repositories)
            {
                var hasPolicy      = false;
                var minApprovers   = false;
                var pushReset      = false;
                var commentResolve = false;
                var buildRequired  = false;
                foreach (var policy in repository.Policies.Where(pol => pol.IsEnabled && pol.IsBlocking))
                {
                    hasPolicy = true;
                    foreach (var scope in policy.Settings.Scope.Where(scope => scope.RefName != null && scope.RefName.Contains("master", StringComparison.OrdinalIgnoreCase)))
                    {
                        if (policy.PolicyType.Id.ToString() == PolicyType.MinimumNumberOfReviewers)
                        {
                            minApprovers = policy.Settings.CreatorVoteCounts ? policy.Settings.MinimumApproverCount > 1 : policy.Settings.MinimumApproverCount > 0;
                            pushReset    = policy.Settings.ResetOnSourcePush;
                        }

                        if (policy.PolicyType.Id.ToString() == PolicyType.ActiveComments)
                        {
                            commentResolve = true;
                        }

                        if (policy.PolicyType.Id.ToString() == PolicyType.SuccessfulBuild)
                        {
                            buildRequired = true;
                        }
                    }
                }

                this.AddRow(
                    repository.Name,
                    hasPolicy ? "(/)" : "(x)",
                    minApprovers ? "(/)" : "(x)",
                    pushReset ? "(/)" : "(x)",
                    commentResolve ? "(/)" : "(x)",
                    buildRequired ? "(/)" : "(x)",
                    string.Empty,
                    repository.WebUrl);
            }
        }
Exemplo n.º 3
0
        private void MakeReleaseReport(AzureDevOpsProject project)
        {
            this.CreateHeaders(
                "Name",
                "CD",
                "Environment",
                "Attempt",
                "Approval",
                "Tests",
                "Remarks",
                "Link");

            foreach (var release in project.Releases)
            {
                foreach (var environment in release.Environments)
                {
                    foreach (var attempt in environment.DeploySteps.Select(deploystep => deploystep.Attempt))
                    {
                        var cdRelease   = false;
                        var hasApproval = false;
                        var hasTests    = false;
                        var remark      = string.Empty;

                        cdRelease   = environment.TriggerReason != "Manual";
                        hasApproval = environment.PreDeployApprovals.FirstOrDefault(pda => pda.Attempt == attempt)?.ApprovedBy != null;
                        var testTaskArray = environment.DeploySteps
                                            .FirstOrDefault(dep => dep.Attempt == attempt)?
                                            .ReleaseDeployPhases?
                                            .SelectMany(rdp => rdp.DeploymentJobs)?
                                            .SelectMany(dpj => dpj.Tasks)?
                                            .Where(task => task.Name.Contains("test", StringComparison.OrdinalIgnoreCase))?
                                            .Select(task => task.Name).ToArray();
                        hasTests = testTaskArray != null && testTaskArray.Length > 0;
                        remark   = hasTests ? $"Tests executed: {string.Join(';', testTaskArray)}" : string.Empty;

                        this.AddRow(
                            release.Name,
                            cdRelease ? "(/)" : "(x)",
                            environment.Name,
                            attempt,
                            hasApproval ? "(/)" : "(x)",
                            hasTests ? "(/)" : "(x)",
                            remark,
                            release.Links.Web.Href.AbsoluteUri);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void MakeReleaseDefinitionReport(AzureDevOpsProject project)
        {
            this.CreateHeaders(
                "Name",
                "Environment",
                "CD",
                "PreviousEnvironment",
                "PreApproval",
                "PreApprover(s)",
                "PostApproval",
                "PostApprover(s)",
                "Test* tasks",
                "Link");

            foreach (var releaseDefinition in project.ReleaseDefinitions)
            {
                foreach (var environment in releaseDefinition.Environments)
                {
                    var cdRelease           = environment.Conditions.Any(cond => cond.ConditionType == AzureDevOpsConditionType.Artifact || cond.ConditionType == AzureDevOpsConditionType.EnvironmentState);
                    var environmentTriggers = string.Join(", ", environment.Conditions.Where(cond => cond.ConditionType == AzureDevOpsConditionType.EnvironmentState).Select(cond => cond.Name));
                    var preApproval         = environment.PreDeployApprovals.Approvals.Any(app => !app.IsAutomated);
                    var preApprovers        = string.Join(", ", environment.PreDeployApprovals.Approvals.Where(app => !app.IsAutomated).Select(app => app.Approver.DisplayName));
                    var postApproval        = environment.PostDeployApprovals.Approvals.Any(app => !app.IsAutomated);
                    var postApprovers       = string.Join(", ", environment.PostDeployApprovals.Approvals.Where(app => !app.IsAutomated).Select(app => app.Approver.DisplayName));

                    var testTaskArray = environment
                                        .DeployPhases?
                                        .SelectMany(depPhase => depPhase.WorkflowTasks)?
                                        .Where(task => task.Name.Contains("test", StringComparison.OrdinalIgnoreCase))?
                                        .Select(task => task.Name).ToArray();
                    var hasTests = testTaskArray != null && testTaskArray.Length > 0;
                    var tests    = hasTests ? string.Join(", ", testTaskArray) : string.Empty;

                    this.AddRow(
                        releaseDefinition.Name,
                        environment.Name,
                        cdRelease ? "(/)" : "(x)",
                        environmentTriggers,
                        preApproval ? "(/)" : "(x)",
                        preApprovers,
                        postApproval ? "(/)" : "(x)",
                        postApprovers,
                        tests,
                        releaseDefinition.Links?.Web?.Href?.AbsoluteUri);
                }
            }
        }
Exemplo n.º 5
0
        private void MakeBuildReport(AzureDevOpsProject project)
        {
            this.CreateHeaders(
                "Name",
                "CI",
                "SonarQube",
                "Test",
                "Remarks",
                "Link");

            foreach (var build in project.Builds)
            {
                var hasSonarQube = false;
                var hasTests     = false;
                var remark       = string.Empty;
                var ciBuild      = CIReason.Contains(build.Reason);
                if (build.Timeline == null)
                {
                    remark = "No timeline found!";
                }
                else
                {
                    hasSonarQube = build.Timeline.Records.Any(rec => rec.Task != null &&
                                                              rec.Task.Name == "SonarQubePublish" &&
                                                              (rec.Result == AzureDevOpsTaskResult.Succeeded ||
                                                               rec.Result == AzureDevOpsTaskResult.SucceededWithIssues));
                    var testTaskArray = build.Timeline.Records
                                        .OrderBy(rec => rec.Order)
                                        .Where(rec => rec.Task != null &&
                                               rec.Name.Contains("test", StringComparison.OrdinalIgnoreCase) &&
                                               (rec.Result == AzureDevOpsTaskResult.Succeeded ||
                                                rec.Result == AzureDevOpsTaskResult.SucceededWithIssues))?
                                        .Select(rec => rec.Name).ToArray();

                    hasTests = testTaskArray != null && testTaskArray.Length > 0;
                    remark   = hasTests ? $"Tests executed: {string.Join(';', testTaskArray)}" : string.Empty;
                }

                this.AddRow(
                    build.BuildNumber,
                    ciBuild ? "(/)" : "(x)",
                    hasSonarQube ? "(/)" : "(x)",
                    hasTests ? "(/)" : "(x)",
                    remark,
                    build.Links.Web.Href.AbsoluteUri);
            }
        }
Exemplo n.º 6
0
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var expected    = $"SEP=;{Environment.NewLine}Collection;Project;Repistory;Branch;Build nr;Build status;Build result;Build queued;Build start;Build end;{Environment.NewLine}testValue;testValue;testValue;testValue;testValue;testValue;testValue;testValue;testValue;testValue;{Environment.NewLine}";
            var testString  = "testValue";
            var testProject = new AzureDevOpsProject
            {
                Name   = testString,
                Builds = new HashSet <AzureDevOpsBuild>
                {
                    new AzureDevOpsBuild
                    {
                        SourceBranch = testString,
                        BuildNumber  = testString,
                        Status       = testString,
                        Result       = testString,
                        Repository   = new AzureDevOpsSourceRepository
                        {
                            Name = testString,
                        },
                        QueueTime  = testString,
                        StartTime  = testString,
                        FinishTime = testString,
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection {
                Name = testString
            };

            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();

            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new BuildDurationReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
        private Dictionary <string, AzureDevOpsFeed> SetupFeeds(string account)
        {
            AzureDevOpsProject someProject = new AzureDevOpsProject("0", "someProject");
            var allFeeds = new Dictionary <string, AzureDevOpsFeed>();

            // This is the reference release feed.
            var releaseFeed = new AzureDevOpsFeed(account, "0", ReleaseFeedName, someProject)
            {
                Packages = new List <AzureDevOpsPackage>()
                {
                    new AzureDevOpsPackage("releasedPackage1", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false),
                            new AzureDevOpsPackageVersion("2.0", isDeleted: true),
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage2", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false),
                            new AzureDevOpsPackageVersion("2.0", isDeleted: false),
                        }
                    }
                }
            };

            allFeeds.Add(releaseFeed.Name, releaseFeed);

            var managedFeedWithUnreleasedPackages = new AzureDevOpsFeed(account, "1", FeedWithUnreleasedPackagesName, null)
            {
                Packages = new List <AzureDevOpsPackage>()
                {
                    new AzureDevOpsPackage("unreleasedPackage1", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false)
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage1", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false),
                        }
                    }
                }
            };

            allFeeds.Add(managedFeedWithUnreleasedPackages.Name, managedFeedWithUnreleasedPackages);

            var managedFeedWithEveryPackageReleased = new AzureDevOpsFeed(account, "2", FeedWithAllPackagesReleasedName, someProject)
            {
                Packages = new List <AzureDevOpsPackage>()
                {
                    new AzureDevOpsPackage("Newtonsoft.Json", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("12.0.2", isDeleted: false)
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage1", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false)
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage2", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false),
                            new AzureDevOpsPackageVersion("2.0", false)
                        }
                    }
                }
            };

            allFeeds.Add(managedFeedWithEveryPackageReleased.Name, managedFeedWithEveryPackageReleased);

            // add a feed with all released packages, but that doesn't match the name pattern. It shouldn't be touched by the cleaner.
            var nonManagedFeedWithEveryPackageReleased = new AzureDevOpsFeed(account, "3", UnmanagedFeedName, someProject)
            {
                Packages = new List <AzureDevOpsPackage>()
                {
                    new AzureDevOpsPackage("Newtonsoft.Json", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("12.0.2", isDeleted: false)
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage1", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false)
                        }
                    },
                    new AzureDevOpsPackage("releasedPackage2", "nuget")
                    {
                        Versions = new AzureDevOpsPackageVersion[]
                        {
                            new AzureDevOpsPackageVersion("1.0", isDeleted: false),
                            new AzureDevOpsPackageVersion("2.0", isDeleted: false)
                        }
                    }
                }
            };

            allFeeds.Add(nonManagedFeedWithEveryPackageReleased.Name, nonManagedFeedWithEveryPackageReleased);

            return(allFeeds);
        }
Exemplo n.º 8
0
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var expected    = $"SEP=;{Environment.NewLine}Collection;Project;Repository;Branch;Policy;Enabled;Enforced;Minimum Approvers;CreatorCounts;Reset on push;{Environment.NewLine}testValue;testValue;testValue;testValue;testValue;True;True;1;True;True;{Environment.NewLine}testValue;testValue;testValue;testValue;testValue;True;True;;;;{Environment.NewLine}";
            var testString  = "testValue";
            var testInt     = 1;
            var testBool    = true;
            var testProject = new AzureDevOpsProject
            {
                Name         = testString,
                Repositories = new HashSet <AzureDevOpsRepository>
                {
                    new AzureDevOpsRepository
                    {
                        Name     = testString,
                        Policies = new HashSet <AzureDevOpsPolicy>
                        {
                            new AzureDevOpsPolicy
                            {
                                IsBlocking = testBool,
                                IsEnabled  = testBool,
                                PolicyType = new AzureDevOpsPolicyType
                                {
                                    Id          = new Guid(PolicyType.MinimumNumberOfReviewers),
                                    DisplayName = testString,
                                },
                                Settings = new AzureDevOpsPolicySettings
                                {
                                    MinimumApproverCount = testInt,
                                    CreatorVoteCounts    = testBool,
                                    ResetOnSourcePush    = testBool,
                                    Scope = new HashSet <AzureDevOpsPolicyScope>
                                    {
                                        new AzureDevOpsPolicyScope
                                        {
                                            RefName = testString,
                                        },
                                    },
                                },
                            },
                            new AzureDevOpsPolicy
                            {
                                IsBlocking = testBool,
                                IsEnabled  = testBool,
                                PolicyType = new AzureDevOpsPolicyType
                                {
                                    Id          = new Guid(PolicyType.ActiveComments),
                                    DisplayName = testString,
                                },
                                Settings = new AzureDevOpsPolicySettings
                                {
                                    Scope = new HashSet <AzureDevOpsPolicyScope>
                                    {
                                        new AzureDevOpsPolicyScope
                                        {
                                            RefName = testString,
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection {
                Name = testString
            };

            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();

            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new GitRepositoryReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var expected = $"SEP=;{Environment.NewLine}Collection;Project;Name;Environment;Filter;CD trigger;Prev. Environment;PreApproval;PreApprover(s);PostApproval;PostApprover(s);Test* tasks;Link;{Environment.NewLine}testValue;testValue;testValue;testValue;;False;;False;;False;;;https://www.example.com/;{Environment.NewLine}testValue;testValue;testValue;testValue;{{\"\"sourceBranch\"\":\"\"master\"\"}};True;;True;testIdentity;True;testIdentity;testValue;https://www.example.com/;{Environment.NewLine}testValue;testValue;testValue;testValue;{{\"\"sourceBranch\"\":\"\"master\"\"}};True;testValue;True;testIdentity;True;testIdentity;testValue;https://www.example.com/;{Environment.NewLine}";
            var testString = "testValue";
            var testIdentity = new AzureDevOpsIdentity { DisplayName = "testIdentity" };
            var testUri = new Uri("https://www.example.com/");
            var testProject = new AzureDevOpsProject
            {
                Name = testString,
                ReleaseDefinitions = new HashSet<AzureDevOpsReleaseDefinition>
                {
                    new AzureDevOpsReleaseDefinition
                    {
                        Name = testString,
                        Environments = new HashSet<AzureDevOpsReleaseDefinitionEnvironment>
                        {
                            new AzureDevOpsReleaseDefinitionEnvironment
                            {
                                Name = testString,
                                Conditions = new HashSet<AzureDevOpsCondition>(),
                                PreDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>(),
                                },
                                PostDeployApprovals = new AzureDevOpsReleaseDefinitionApproval()
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = true,
                                        },
                                    },
                                },
                            },
                        },
                        Triggers = new HashSet<AzureDevOpsTrigger>(),
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                    new AzureDevOpsReleaseDefinition
                    {
                        Name = testString,
                        Environments = new HashSet<AzureDevOpsReleaseDefinitionEnvironment>
                        {
                            new AzureDevOpsReleaseDefinitionEnvironment
                            {
                                Name = testString,
                                Conditions = new HashSet<AzureDevOpsCondition>
                                {
                                    new AzureDevOpsCondition
                                    {
                                        ConditionType = AzureDevOpsConditionType.Artifact,
                                        Value = $"{{\"sourceBranch\":\"master\"}}",
                                    },
                                },
                                DeployPhases = new HashSet<AzureDevOpsDeployPhase>
                                {
                                    new AzureDevOpsDeployPhase
                                    {
                                        WorkflowTasks = new HashSet<AzureDevOpsWorkflowTask>
                                        {
                                            new AzureDevOpsWorkflowTask
                                            {
                                                Name = testString,
                                            },
                                        },
                                    },
                                },
                                PreDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver = testIdentity,
                                        },
                                    },
                                },
                                PostDeployApprovals = new AzureDevOpsReleaseDefinitionApproval()
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver = testIdentity,
                                        },
                                    },
                                },
                            },
                        },
                        Triggers = new HashSet<AzureDevOpsTrigger>
                        {
                            new AzureDevOpsTrigger
                            {
                                TriggerType = AzureDevOpsTriggerType.ArtifactSource,
                                TriggerConditions = new HashSet<AzureDevOpsTriggerCondition>
                                {
                                    new AzureDevOpsTriggerCondition
                                    {
                                        SourceBranch = testString,
                                    },
                                },
                            },
                        },
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                    new AzureDevOpsReleaseDefinition
                    {
                        Name = testString,
                        Environments = new HashSet<AzureDevOpsReleaseDefinitionEnvironment>
                        {
                            new AzureDevOpsReleaseDefinitionEnvironment
                            {
                                Name = testString,
                                Conditions = new HashSet<AzureDevOpsCondition>
                                {
                                    new AzureDevOpsCondition
                                    {
                                        ConditionType = AzureDevOpsConditionType.EnvironmentState,
                                        Name = testString,
                                    },
                                    new AzureDevOpsCondition
                                    {
                                        ConditionType = AzureDevOpsConditionType.Artifact,
                                        Value = $"{{\"sourceBranch\":\"master\"}}",
                                    },
                                },
                                DeployPhases = new HashSet<AzureDevOpsDeployPhase>
                                {
                                    new AzureDevOpsDeployPhase
                                    {
                                        WorkflowTasks = new HashSet<AzureDevOpsWorkflowTask>
                                        {
                                            new AzureDevOpsWorkflowTask
                                            {
                                                Name = testString,
                                            },
                                        },
                                    },
                                },
                                PreDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver = testIdentity,
                                        },
                                    },
                                },
                                PostDeployApprovals = new AzureDevOpsReleaseDefinitionApproval()
                                {
                                    Approvals = new HashSet<AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver = testIdentity,
                                        },
                                    },
                                },
                            },
                        },
                        Triggers = new HashSet<AzureDevOpsTrigger>
                        {
                            new AzureDevOpsTrigger
                            {
                                TriggerType = AzureDevOpsTriggerType.ArtifactSource,
                            },
                        },
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection { Name = testString };
            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();
            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new ReleaseDefinitionReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var expected    = this.GetExpectedReport();
            var testUri     = new Uri("https://www.example.com/");
            var testString  = "testValue";
            var testInt     = 1;
            var testGuid    = Guid.NewGuid();
            var testResult  = AzureDevOpsTaskResult.Succeeded;
            var testState   = AzureDevOpsTimelineRecordState.Completed;
            var testProject = new AzureDevOpsProject
            {
                Name   = testString,
                Builds = new HashSet <AzureDevOpsBuild>
                {
                    new AzureDevOpsBuild
                    {
                        Reason      = AzureDevOpsBuildReason.Manual,
                        BuildNumber = testString,
                        Links       = new AzureDevOpsBuildLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                    new AzureDevOpsBuild
                    {
                        Reason      = AzureDevOpsBuildReason.Schedule,
                        BuildNumber = testString,
                        Timeline    = new AzureDevOpsBuildTimeline
                        {
                            Records = new HashSet <AzureDevOpsTimelineRecord>
                            {
                                new AzureDevOpsTimelineRecord
                                {
                                    Name   = "nope",
                                    Order  = testInt,
                                    Result = testResult,
                                    State  = testState,
                                    Task   = new AzureDevOpsTask
                                    {
                                        Id      = testGuid,
                                        Name    = testString,
                                        Version = testString,
                                    },
                                    Type = testString,
                                },
                            },
                        },
                        Links = new AzureDevOpsBuildLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                    new AzureDevOpsBuild
                    {
                        Reason      = AzureDevOpsBuildReason.BatchedCI,
                        BuildNumber = testString,
                        Timeline    = new AzureDevOpsBuildTimeline
                        {
                            Records = new HashSet <AzureDevOpsTimelineRecord>
                            {
                                new AzureDevOpsTimelineRecord
                                {
                                    Name   = "Sonarstep",
                                    Order  = 1,
                                    Result = AzureDevOpsTaskResult.Succeeded,
                                    State  = AzureDevOpsTimelineRecordState.Completed,
                                    Task   = new AzureDevOpsTask
                                    {
                                        Id      = testGuid,
                                        Name    = "SonarQubePublish",
                                        Version = testString,
                                    },
                                    Type = testString,
                                },
                                new AzureDevOpsTimelineRecord
                                {
                                    Name   = "execTest",
                                    Order  = 2,
                                    Result = AzureDevOpsTaskResult.Succeeded,
                                    State  = AzureDevOpsTimelineRecordState.Completed,
                                    Task   = new AzureDevOpsTask
                                    {
                                        Id      = testGuid,
                                        Name    = testString,
                                        Version = testString,
                                    },
                                    Type = testString,
                                },
                            },
                        },
                        Links = new AzureDevOpsBuildLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                },
                Repositories = new HashSet <AzureDevOpsRepository>
                {
                    new AzureDevOpsRepository
                    {
                        Name     = testString,
                        WebUrl   = testUri,
                        Policies = new HashSet <AzureDevOpsPolicy>(),
                    },
                    new AzureDevOpsRepository
                    {
                        Name     = testString,
                        WebUrl   = testUri,
                        Policies = new HashSet <AzureDevOpsPolicy>
                        {
                            new AzureDevOpsPolicy
                            {
                                IsBlocking = true,
                                IsEnabled  = true,
                                PolicyType = new AzureDevOpsPolicyType
                                {
                                    Id = new Guid(PolicyType.MinimumNumberOfReviewers),
                                },
                                Settings = new AzureDevOpsPolicySettings
                                {
                                    MinimumApproverCount = 2,
                                    ResetOnSourcePush    = true,
                                    Scope = new HashSet <AzureDevOpsPolicyScope>
                                    {
                                        new AzureDevOpsPolicyScope
                                        {
                                            RefName = "refs/heads/master",
                                        },
                                    },
                                },
                            },
                            new AzureDevOpsPolicy
                            {
                                IsBlocking = true,
                                IsEnabled  = true,
                                PolicyType = new AzureDevOpsPolicyType
                                {
                                    Id = new Guid(PolicyType.ActiveComments),
                                },
                                Settings = new AzureDevOpsPolicySettings
                                {
                                    Scope = new HashSet <AzureDevOpsPolicyScope>
                                    {
                                        new AzureDevOpsPolicyScope
                                        {
                                            RefName = "refs/heads/master",
                                        },
                                    },
                                },
                            },
                            new AzureDevOpsPolicy
                            {
                                IsBlocking = true,
                                IsEnabled  = true,
                                PolicyType = new AzureDevOpsPolicyType
                                {
                                    Id = new Guid(PolicyType.SuccessfulBuild),
                                },
                                Settings = new AzureDevOpsPolicySettings
                                {
                                    Scope = new HashSet <AzureDevOpsPolicyScope>
                                    {
                                        new AzureDevOpsPolicyScope
                                        {
                                            RefName = "refs/heads/master",
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
                ReleaseDefinitions = new HashSet <AzureDevOpsReleaseDefinition>
                {
                    new AzureDevOpsReleaseDefinition
                    {
                        Name  = testString,
                        Url   = testUri,
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                        Triggers = new HashSet <AzureDevOpsTrigger>
                        {
                            new AzureDevOpsTrigger
                            {
                                TriggerType       = AzureDevOpsTriggerType.ArtifactSource,
                                TriggerConditions = new HashSet <AzureDevOpsTriggerCondition>
                                {
                                    new AzureDevOpsTriggerCondition
                                    {
                                        SourceBranch = testString,
                                    },
                                },
                            },
                        },
                        Environments = new HashSet <AzureDevOpsReleaseDefinitionEnvironment>
                        {
                            new AzureDevOpsReleaseDefinitionEnvironment
                            {
                                Name = testString,
                                PreDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet <AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = true,
                                        },
                                    },
                                },
                                PostDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet <AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = true,
                                        },
                                    },
                                },
                                Conditions = new HashSet <AzureDevOpsCondition>
                                {
                                    new AzureDevOpsCondition
                                    {
                                        ConditionType = AzureDevOpsConditionType.Event,
                                        Name          = testString,
                                        Value         = testString,
                                    },
                                },
                            },
                            new AzureDevOpsReleaseDefinitionEnvironment
                            {
                                Name = testString,
                                PreDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet <AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver    = new AzureDevOpsIdentity
                                            {
                                                DisplayName = testString,
                                            },
                                        },
                                    },
                                },
                                PostDeployApprovals = new AzureDevOpsReleaseDefinitionApproval
                                {
                                    Approvals = new HashSet <AzureDevOpsReleaseDefinitionApprovalStep>
                                    {
                                        new AzureDevOpsReleaseDefinitionApprovalStep
                                        {
                                            IsAutomated = false,
                                            Approver    = new AzureDevOpsIdentity
                                            {
                                                DisplayName = testString,
                                            },
                                        },
                                    },
                                },
                                Conditions = new HashSet <AzureDevOpsCondition>
                                {
                                    new AzureDevOpsCondition
                                    {
                                        ConditionType = AzureDevOpsConditionType.EnvironmentState,
                                        Name          = testString,
                                        Value         = testString,
                                    },
                                },
                                DeployPhases = new HashSet <AzureDevOpsDeployPhase>
                                {
                                    new AzureDevOpsDeployPhase
                                    {
                                        WorkflowTasks = new HashSet <AzureDevOpsWorkflowTask>
                                        {
                                            new AzureDevOpsWorkflowTask
                                            {
                                                Name = testString,
                                            },
                                            new AzureDevOpsWorkflowTask
                                            {
                                                Name = testString,
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
                Releases = new HashSet <AzureDevOpsRelease>
                {
                    new AzureDevOpsRelease
                    {
                        Name         = testString,
                        Environments = new HashSet <AzureDevOpsEnvironment>
                        {
                            new AzureDevOpsEnvironment
                            {
                                Name               = testString,
                                TriggerReason      = "Manual",
                                PreDeployApprovals = new HashSet <AzureDevOpsDeployApproval>
                                {
                                    new AzureDevOpsDeployApproval
                                    {
                                        Attempt     = testInt,
                                        IsAutomated = true,
                                    },
                                },
                                DeploySteps = new HashSet <AzureDevOpsDeployStep>
                                {
                                    new AzureDevOpsDeployStep
                                    {
                                        Attempt = testInt,
                                    },
                                },
                            },
                        },
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                    new AzureDevOpsRelease
                    {
                        Name         = testString,
                        Environments = new HashSet <AzureDevOpsEnvironment>
                        {
                            new AzureDevOpsEnvironment
                            {
                                Name               = testString,
                                TriggerReason      = testString,
                                PreDeployApprovals = new HashSet <AzureDevOpsDeployApproval>
                                {
                                    new AzureDevOpsDeployApproval
                                    {
                                        Attempt     = testInt,
                                        IsAutomated = false,
                                        ApprovedBy  = new AzureDevOpsIdentity(),
                                    },
                                },
                                DeploySteps = new HashSet <AzureDevOpsDeployStep>
                                {
                                    new AzureDevOpsDeployStep
                                    {
                                        Attempt             = testInt,
                                        ReleaseDeployPhases = new HashSet <AzureDevOpsReleaseDeployPhase>
                                        {
                                            new AzureDevOpsReleaseDeployPhase
                                            {
                                                DeploymentJobs = new HashSet <AzureDevOpsDeploymentJob>
                                                {
                                                    new AzureDevOpsDeploymentJob
                                                    {
                                                        Tasks = new HashSet <AzureDevOpsDeploymentTask>
                                                        {
                                                            new AzureDevOpsDeploymentTask
                                                            {
                                                                Name = "execTest",
                                                            },
                                                        },
                                                    },
                                                },
                                            },
                                        },
                                    },
                                },
                            },
                        },
                        Links = new AzureDevOpsReleaseLinks
                        {
                            Web = new AzureDevOpsLink
                            {
                                Href = testUri,
                            },
                        },
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection {
                Name = testString
            };

            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();

            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new CombinedComplianceReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
        public void Generate_WithInstance_GeneratesReport()
        {
            // Arrange
            var testDate           = DateTime.Now;
            var expected           = $"SEP=;{Environment.NewLine}Collection;Project;Release name;Release date;R. Status;Environment;E. Status;Attempt;Attempt date;Auto approve;Required approval;Approval given by;ReplacedToken?;Nr. of Artifacts;Artifact - version [branch];{Environment.NewLine}testValue;testValue;testValue;{testDate};testValue;testValue;testValue;1;{testDate};False;testIdentity;testIdentity;True;0;;{Environment.NewLine}testValue;testValue;testValue;{testDate};testValue;testValue;testValue;1;{testDate};True;;;False;1;'testValue - testValue [testValue]';{Environment.NewLine}";
            var testSearchedTaskId = new Guid("a8515ec8-7254-4ffd-912c-86772e2b5962");
            var testString         = "testValue";
            var testGuid           = Guid.NewGuid();
            var testInt            = 1;
            var testIdentity       = new AzureDevOpsIdentity {
                DisplayName = "testIdentity"
            };
            var testProject = new AzureDevOpsProject
            {
                Name     = testString,
                Releases = new HashSet <AzureDevOpsRelease>
                {
                    new AzureDevOpsRelease
                    {
                        Name         = testString,
                        CreatedOn    = testDate,
                        Status       = testString,
                        Environments = new HashSet <AzureDevOpsEnvironment>
                        {
                            new AzureDevOpsEnvironment
                            {
                                Name        = testString,
                                Status      = testString,
                                DeploySteps = new HashSet <AzureDevOpsDeployStep>
                                {
                                    new AzureDevOpsDeployStep
                                    {
                                        Attempt             = 1,
                                        ReleaseDeployPhases = new HashSet <AzureDevOpsReleaseDeployPhase>
                                        {
                                            new AzureDevOpsReleaseDeployPhase
                                            {
                                                DeploymentJobs = new HashSet <AzureDevOpsDeploymentJob>
                                                {
                                                    new AzureDevOpsDeploymentJob
                                                    {
                                                        Tasks = new HashSet <AzureDevOpsDeploymentTask>
                                                        {
                                                            new AzureDevOpsDeploymentTask
                                                            {
                                                                Task = new AzureDevOpsTask
                                                                {
                                                                    Id = testSearchedTaskId,
                                                                },
                                                            },
                                                        },
                                                    },
                                                },
                                            },
                                        },
                                    },
                                },
                                PreDeployApprovals = new HashSet <AzureDevOpsDeployApproval>
                                {
                                    new AzureDevOpsDeployApproval
                                    {
                                        Attempt     = testInt,
                                        CreatedOn   = testDate,
                                        IsAutomated = false,
                                        Approver    = testIdentity,
                                        ApprovedBy  = testIdentity,
                                    },
                                },
                            },
                        },
                        Artifacts = new HashSet <AzureDevOpsReleaseArtifact>(),
                    },
                    new AzureDevOpsRelease
                    {
                        Name         = testString,
                        CreatedOn    = testDate,
                        Status       = testString,
                        Environments = new HashSet <AzureDevOpsEnvironment>
                        {
                            new AzureDevOpsEnvironment
                            {
                                Name        = testString,
                                Status      = testString,
                                DeploySteps = new HashSet <AzureDevOpsDeployStep>
                                {
                                    new AzureDevOpsDeployStep
                                    {
                                        Attempt             = 1,
                                        ReleaseDeployPhases = new HashSet <AzureDevOpsReleaseDeployPhase>
                                        {
                                            new AzureDevOpsReleaseDeployPhase
                                            {
                                                DeploymentJobs = new HashSet <AzureDevOpsDeploymentJob>
                                                {
                                                    new AzureDevOpsDeploymentJob
                                                    {
                                                        Tasks = new HashSet <AzureDevOpsDeploymentTask>
                                                        {
                                                            new AzureDevOpsDeploymentTask
                                                            {
                                                                Task = new AzureDevOpsTask
                                                                {
                                                                    Id = testGuid,
                                                                },
                                                            },
                                                        },
                                                    },
                                                },
                                            },
                                        },
                                    },
                                },
                                PreDeployApprovals = new HashSet <AzureDevOpsDeployApproval>
                                {
                                    new AzureDevOpsDeployApproval
                                    {
                                        Attempt     = testInt,
                                        CreatedOn   = testDate,
                                        IsAutomated = true,
                                    },
                                },
                            },
                        },
                        Artifacts = new HashSet <AzureDevOpsReleaseArtifact>
                        {
                            new AzureDevOpsReleaseArtifact
                            {
                                DefinitionReference = new AzureDevOpsDefinitionReference
                                {
                                    Definition = new AzureDevOpsReferenceField
                                    {
                                        Name = testString,
                                    },
                                    Version = new AzureDevOpsReferenceField
                                    {
                                        Name = testString,
                                    },
                                    Branch = new AzureDevOpsReferenceField
                                    {
                                        Name = testString,
                                    },
                                },
                            },
                        },
                    },
                },
            };
            var testCollection = new AzureDevOpsCollection {
                Name = testString
            };

            testCollection.Projects.Add(testProject);
            var testAzureDevOpsInstance = new AzureDevOpsInstance();

            testAzureDevOpsInstance.Collections.Add(testCollection);

            var systemUnderTest = new ReleaseReport();

            // Act
            var actual = systemUnderTest.Generate(testAzureDevOpsInstance);

            // Assert
            actual.Should().NotBeNull();
            actual.Should().Be(expected);
        }
        private async Task <IEnumerable <AzureDevOpsRepository> > GetRepositoriesFromProject(Repository repository, AzureDevOpsProject project, AzureDevOpsMetadata metadata)
        {
            List <AzureDevOpsRepository> repositories = new List <AzureDevOpsRepository>();

            try
            {
                HttpClient client = GetAzureDevopsHttpClient(metadata);

                var responseBody = await client.GetStringAsync($"https://dev.azure.com/{repository.Name}/{project.name}/_apis/git/repositories?api-version=5.1").ConfigureAwait(false);

                var repositoriesResponse = JsonConvert.DeserializeObject <AzureDevOpsRepositoryResponse>(responseBody);
                foreach (var repo in repositoriesResponse.repositories)
                {
                    repositories.Add(repo);
                }
            }
            catch (Exception ex)
            {
                //TODO: handle exceptions
                Console.WriteLine(ex);
            }
            return(repositories);
        }