Ejemplo n.º 1
0
        public void Should_Filter_By_Pipeline_Status_Failed()
        {
            var profile = new Profile
            {
                Statuses = new List<PipelineStatus> { PipelineStatus.Failed },

                PipelineGroups = {new GroupedPipeline{
                    Name = "Group",
                    ProfilePipelines = new List<ProfilePipeline>
                        {
                            new ProfilePipeline{HideBuildInfo = true, Name = "Pipeline1"},
                            new ProfilePipeline{HideBuildInfo = true, Name = "Pipeline2"}
                        },
                    }}

            };

            var pipelines = new List<DisplayablePipeline>
                                {
                                    new DisplayablePipeline("Pipeline1", "0000"){Stages = new List<IStage>{new PassedStage("","",DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline2", "0000"){Stages = new List<IStage>{new FailedStage("","",DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}}
                                };

            var pipelineFilter = new PipelineFilter(pipelines);

            var filteredPipelines = pipelineFilter.Filter(profile);

            Assert.That(filteredPipelines.Count(), Is.EqualTo(1));
            Assert.That(filteredPipelines[0].Pipelines.Count, Is.EqualTo(1));
            Assert.That(filteredPipelines[0].Pipelines[0].Name, Is.EqualTo("Pipeline2"));
        }
Ejemplo n.º 2
0
        public void Should_Filter_All_Pipelines_By_Status_If_No_Whitelist()
        {
            var profile = new Profile
            {
                Statuses = new List<PipelineStatus> { PipelineStatus.Failed }
            };

            var pipelines = new List<DisplayablePipeline>
                                {
                                    new DisplayablePipeline("Pipeline1", "passed"){Stages = new List<IStage>(){new PassedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline2", "failed"){Stages = new List<IStage>(){new FailedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline3", "passed"){Stages = new List<IStage>(){new PassedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}}
                                };

            var pipelineFilter = new PipelineFilter(pipelines);

            var filteredPipelines = pipelineFilter.Filter(profile);

            Assert.That(filteredPipelines.Count(), Is.EqualTo(1));
            Assert.That(filteredPipelines[0].Pipelines[0].Name, Is.EqualTo("Pipeline2"));
        }
Ejemplo n.º 3
0
        public IList<GroupedDisplayablePipeline> Filter(Profile profile)
        {
            IList<GroupedDisplayablePipeline> groupedDisplayablePipelines = new List<GroupedDisplayablePipeline>();
            if (profile.PipelineGroups.Count > 0)
            {
                foreach (var group in profile.PipelineGroups)
                {
                    var groupedDisplayablePipeline = new GroupedDisplayablePipeline();
                    foreach (var pipeline in group.ProfilePipelines)
                    {
                        var pipeline1 = pipeline;
                        var displayablePipeline = _displayablePipelines.FirstOrDefault(x => x.Name == pipeline1.Name);
                        groupedDisplayablePipeline.Name = group.Name;
                        groupedDisplayablePipeline.ShowName = group.ShowName;
                        if (displayablePipeline != null && profile.Statuses.Contains(displayablePipeline.ActualStatus))
                        {
                            displayablePipeline.HideBuildInfo = pipeline.HideBuildInfo;
                            displayablePipeline.Alias = pipeline.Alias;
                            groupedDisplayablePipeline.Pipelines.Add(displayablePipeline);
                        }
                    }
                    groupedDisplayablePipelines.Add(groupedDisplayablePipeline);
                }
            }
            else
            {
                var groupedDisplayablePipeline = new GroupedDisplayablePipeline { Name = "All", ShowName = false };
                foreach (var displayablePipeline in _displayablePipelines)
                {
                    if (displayablePipeline != null && profile.Statuses.Contains(displayablePipeline.ActualStatus))
                    {
                        groupedDisplayablePipeline.Pipelines.Add(displayablePipeline);
                    }
                }

                groupedDisplayablePipelines.Add(groupedDisplayablePipeline);
            }
            return groupedDisplayablePipelines;
        }
Ejemplo n.º 4
0
        public Profile Load(XElement profilesXml, List<PipelineStatus> pipelineStatuses)
        {
            var profile = new Profile();

            if (profilesXml == null)
            {
                return profile;
            }

            var xElement = profilesXml.Element("WhiteList");
            if (xElement != null)
            {
                var groupNodes = xElement.Elements("Group");

                var i = 0;
                foreach (var groupNode in groupNodes)
                {
                    var xAttribute = groupNode.Attribute("name");
                    var groupName = xAttribute != null ? xAttribute.Value : i++.ToString(CultureInfo.InvariantCulture);

                    xAttribute = groupNode.Attribute("showName");
                    var showName = true;
                    if (xAttribute != null)
                    {
                        bool.TryParse(xAttribute.Value, out showName);
                    }

                    var groupPipelineNodes = groupNode.Elements("Pipeline");

                    var profilePipelines = LoadProfilePipelines(groupPipelineNodes);

                    var groupedPipeline = new GroupedPipeline
                        {
                            Name = groupName,
                            ProfilePipelines = profilePipelines,
                            ShowName = showName
                        };
                    profile.PipelineGroups.Add(groupedPipeline);
                }
            }

            var statusList = new List<PipelineStatus>();

            if (pipelineStatuses.Any())
            {
                statusList = pipelineStatuses;
            }
            else
            {
                var statusXml = profilesXml.Element("Statuses");
                if (statusXml.HasElements)
                {
                    var statusElements = statusXml.Elements();
                    foreach (var statusElement in statusElements)
                    {
                        if (statusElement.Name == "Failed")
                            statusList.Add(PipelineStatus.Failed);
                        if (statusElement.Name == "Passed")
                            statusList.Add(PipelineStatus.Passed);
                        if (statusElement.Name == "Building")
                            statusList.Add(PipelineStatus.Building);
                    }
                }
            }

            profile.Statuses = statusList;

            bool showPassedCount;
            bool.TryParse(
                (profilesXml.Element("ShowPassedCount") ?? XElement.Parse("<ShowPassedCount>false</ShowPassedCount>"))
                    .Value, out showPassedCount);

            profile.ShowPassedCount = showPassedCount;

            return profile;
        }
Ejemplo n.º 5
0
        public void Should_WhiteList_By_Pipeline_Names()
        {
            var group = new GroupedPipeline
            {
                Name = "Name",
                ProfilePipelines = new List<ProfilePipeline>
                        {
                            new ProfilePipeline{HideBuildInfo = true, Name = "Pipeline1"},
                            new ProfilePipeline{HideBuildInfo = true, Name = "Pipeline2"}
                        }

            };
            var profile = new Profile
            {
                PipelineGroups = new List<GroupedPipeline> { group }
            };

            var pipelines = new List<DisplayablePipeline>
                                {
                                    new DisplayablePipeline("Pipeline1", "passed"){Stages = new List<IStage>(){new FailedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline2", "failed"){Stages = new List<IStage>(){new FailedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline3", "passed"){Stages = new List<IStage>(){new FailedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}},
                                    new DisplayablePipeline("Pipeline4", "passed"){Stages = new List<IStage>(){new FailedStage("", "", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"))}}
                                };

            var pipelineFilter = new PipelineFilter(pipelines);

            var filteredPipelines = pipelineFilter.Filter(profile);

            Assert.That(filteredPipelines[0].Pipelines.Count, Is.EqualTo(2));
            Assert.That(filteredPipelines[0].Pipelines[0].Name, Is.EqualTo("Pipeline1"));
            Assert.That(filteredPipelines[0].Pipelines[1].Name, Is.EqualTo("Pipeline2"));
        }