示例#1
0
        /// <summary>
        /// Parses the collected data and generates a report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            // Parse per project
            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    this.AddText($"# {collection.Name}/{project.Name}");
                    this.AddText("## Git repositories");
                    this.MakeGitReport(project);
                    this.AddText("## Executed builds");
                    this.MakeBuildReport(project);
                    this.AddText("## Executed releases");
                    this.MakeReleaseReport(project);
                    this.AddText("## Release definitions");
                    this.MakeReleaseDefinitionReport(project);
                }
            }

            return(this.GetReport());
        }
示例#2
0
        /// <summary>
        /// Parses the collected data and generates a CSV report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            this.CreateHeaders(
                "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]");

            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    foreach (var release in project.Releases)
                    {
                        foreach (var environment in release.Environments)
                        {
                            foreach (var preDeployApproval in environment.PreDeployApprovals)
                            {
                                this.AddLine(
                                    collection.Name,
                                    project.Name,
                                    release.Name,
                                    release.CreatedOn,
                                    release.Status,
                                    environment.Name,
                                    environment.Status,
                                    preDeployApproval.Attempt,
                                    preDeployApproval.CreatedOn,
                                    preDeployApproval.IsAutomated,
                                    preDeployApproval.IsAutomated ? string.Empty : $"{preDeployApproval.Approver?.DisplayName}",
                                    preDeployApproval.IsAutomated ? string.Empty : $"{preDeployApproval.ApprovedBy?.DisplayName}",
                                    this.DeploystepHasTask(environment.DeploySteps.Single(ds => ds.Attempt == preDeployApproval.Attempt), this.replaceTokenTaskId),
                                    release.Artifacts?.Count() ?? 0,
                                    string.Join(" & ", release.Artifacts?.Select(art => art.DefinitionReference)?.Select(def => $"'{def.Definition.Name} - {def.Version.Name} [{def.Branch.Name}]'")));
                            }
                        }
                    }
                }
            }

            return(this.GetReport());
        }
示例#3
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);
        }
示例#4
0
        private async Task ProcessReports(IEnumerable <IReport> reports, AzureDevOpsInstance azureDevOpsInstance, string reportFolder)
        {
            var reportTasks = new HashSet <Task>();

            foreach (var report in reports)
            {
                reportTasks.Add(WriteReportAsync(Path.Combine(reportFolder, report.Title), report.Generate(azureDevOpsInstance)));
            }

            await Task.WhenAll(reportTasks).ConfigureAwait(false);
        }
        public void AddLine_WhenWhitespaceChar_Removed(string testInput, string cleaned)
        {
            // Arrange
            var expected   = $"|{cleaned}|{Environment.NewLine}";
            var vsinstance = new AzureDevOpsInstance();

            vsinstance.Collections.Add(new AzureDevOpsCollection {
                Name = testInput
            });
            var systemUnderTest = new MDTestClass();

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

            // Assert
            actual.Should().Be(expected);
        }
        /// <summary>
        /// Parses the collected data and generates a CSV report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            this.CreateHeaders(
                "Collection",
                "Project",
                "Repistory",
                "Branch",
                "Build nr",
                "Build status",
                "Build result",
                "Artifact name",
                "Artifact type",
                "Artifact download");

            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    foreach (var build in project.Builds)
                    {
                        foreach (var artifact in build.Artifacts)
                        {
                            this.AddLine(
                                collection.Name,
                                project.Name,
                                build.Repository.Name,
                                build.SourceBranch,
                                build.BuildNumber,
                                build.Status,
                                build.Result,
                                artifact.Name,
                                artifact.Resource.Type,
                                artifact.Resource.DownloadUrl);
                        }
                    }
                }
            }

            return(this.GetReport());
        }
        public void AddLine_WhenUsingPipeChar_EscapingHappens()
        {
            // Arrange
            var expectedReport = $"|Test\\|Name|{Environment.NewLine}";
            var textString     = "Test|Name";
            var vsinstance     = new AzureDevOpsInstance();

            vsinstance.Collections.Add(new AzureDevOpsCollection {
                Name = textString
            });
            var systemUnderTest = new MDTestClass();

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

            // Assert
            actual.Should().Be(expectedReport);
        }
示例#8
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);
        }
示例#9
0
        /// <summary>
        /// Parses the data from Azure DevOps and based on the requested reports produces files.
        /// </summary>
        /// <param name="reports">Reports to be created.</param>
        /// <param name="azureDevOpsInstance">Instance object holding the Azure DevOps scanned data.</param>
        /// <param name="reportFolder">Location to write the reports to.</param>
        /// <returns>Task object/ async function.</returns>
        public Task CreateReportsAsync(IEnumerable <IReport> reports, AzureDevOpsInstance azureDevOpsInstance, string reportFolder)
        {
            if (reports == null)
            {
                throw new ArgumentNullException(nameof(reports));
            }

            if (azureDevOpsInstance == null)
            {
                throw new ArgumentNullException(nameof(azureDevOpsInstance));
            }

            if (!Directory.Exists(reportFolder))
            {
                throw new DirectoryNotFoundException(reportFolder);
            }

            return(this.ProcessReports(reports, azureDevOpsInstance, reportFolder));
        }
示例#10
0
        /// <summary>
        /// Parses the collected data and generates a CSV report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            this.CreateHeaders(
                "Collection",
                "Project",
                "Repistory",
                "Branch",
                "Build nr",
                "Build status",
                "Build result",
                "Build queued",
                "Build start",
                "Build end");

            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    foreach (var build in project.Builds)
                    {
                        this.AddLine(
                            collection.Name,
                            project.Name,
                            build.Repository.Name,
                            build.SourceBranch,
                            build.BuildNumber,
                            build.Status,
                            build.Result,
                            build.QueueTime,
                            build.StartTime,
                            build.FinishTime);
                    }
                }
            }

            return(this.GetReport());
        }
示例#11
0
        /// <summary>
        /// Parses the collected data and generates a CSV report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            this.CreateHeaders("Collection", "Project", "Repository", "Branch", "Policy", "Enabled", "Enforced", "Minimum Approvers", "CreatorCounts", "Reset on push");

            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    foreach (var repository in project.Repositories)
                    {
                        foreach (var policy in repository.Policies)
                        {
                            foreach (var scope in policy.Settings.Scope)
                            {
                                this.AddLine(
                                    collection.Name,
                                    project.Name,
                                    repository.Name,
                                    scope.RefName,
                                    policy.PolicyType.DisplayName,
                                    policy.IsEnabled,
                                    policy.IsBlocking,
                                    this.SettingsValue(policy, PolicyType.MinimumNumberOfReviewers, policy.Settings.MinimumApproverCount),
                                    this.SettingsValue(policy, PolicyType.MinimumNumberOfReviewers, policy.Settings.CreatorVoteCounts),
                                    this.SettingsValue(policy, PolicyType.MinimumNumberOfReviewers, policy.Settings.ResetOnSourcePush));
                            }
                        }
                    }
                }
            }

            return(this.GetReport());
        }
示例#12
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);
        }
        /// <summary>
        /// Parses the collected data and generates a CSV report.
        /// </summary>
        /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
        /// <returns>CSV string.</returns>
        public string Generate(AzureDevOpsInstance instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            this.CreateHeaders(
                "Collection",
                "Project",
                "Name",
                "Environment",
                "Filter",
                "CD trigger",
                "Prev. Environment",
                "PreApproval",
                "PreApprover(s)",
                "PostApproval",
                "PostApprover(s)",
                "Test* tasks",
                "Link");

            foreach (var collection in instance.Collections)
            {
                foreach (var project in collection.Projects)
                {
                    foreach (var releaseDefinition in project.ReleaseDefinitions)
                    {
                        foreach (var environment in releaseDefinition.Environments)
                        {
                            var cdRelease         = releaseDefinition.Triggers.Any(tr => tr.TriggerType == AzureDevOpsTriggerType.ArtifactSource);
                            var environmentSource = environment.Conditions.Where(cond => cond.ConditionType == AzureDevOpsConditionType.EnvironmentState).Select(cond => cond.Name).ToArray();
                            var filter            = string.Join(", ", environment.Conditions.Where(cond => cond.ConditionType == AzureDevOpsConditionType.Artifact).Select(cond => cond.Value));
                            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.AddLine(
                                collection.Name,
                                project.Name,
                                releaseDefinition.Name,
                                environment.Name,
                                filter,
                                cdRelease,
                                string.Join(", ", environmentSource),
                                preApproval,
                                preApprovers,
                                postApproval,
                                postApprovers,
                                tests,
                                releaseDefinition.Links?.Web?.Href?.AbsoluteUri);
                        }
                    }
                }
            }

            return(this.GetReport());
        }
        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);
        }
            public string Generate(AzureDevOpsInstance instance)
            {
                this.AddRow(instance.Collections.FirstOrDefault().Name);

                return(this.GetReport());
            }
 /// <summary>
 /// Generates the report. Remains empty.
 /// </summary>
 /// <param name="instance">Instance object containing the data collected from Azure DevOps.</param>
 /// <returns>Nothing.</returns>
 public string Generate(AzureDevOpsInstance instance)
 {
     return(string.Empty);
 }