public void ChangeFailureRateEliteTest()
        {
            //Arrange
            ChangeFailureRate metrics = new ChangeFailureRate();
            int numberOfDays          = 1;
            List <KeyValuePair <DateTime, bool> > changeFailureRateList = new List <KeyValuePair <DateTime, bool> >
            {
                new KeyValuePair <DateTime, bool>(DateTime.Now, true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(1), true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(2), true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(3), true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(4), true)
            };

            //Act
            float result = metrics.ProcessChangeFailureRate(changeFailureRateList, numberOfDays);
            ChangeFailureRateModel model = new ChangeFailureRateModel
            {
                ChangeFailureRateMetric            = result,
                ChangeFailureRateMetricDescription = metrics.GetChangeFailureRateRating(result),
                IsProjectView = false
            };

            //Assert
            Assert.IsTrue(model != null);
            Assert.AreEqual(0f, model.ChangeFailureRateMetric);
            Assert.AreEqual("Elite", model.ChangeFailureRateMetricDescription);
            Assert.AreEqual(false, model.IsProjectView);
        }
        public void ChangeFailureRateNullTest()
        {
            //Arrange
            ChangeFailureRate metrics = new ChangeFailureRate();
            int numberOfDays          = 1;
            List <KeyValuePair <DateTime, bool> > changeFailureRateList = null;

            //Act
            float  result = metrics.ProcessChangeFailureRate(changeFailureRateList, numberOfDays);
            string rating = metrics.GetChangeFailureRateRating(result);

            //Assert
            Assert.AreEqual(-1, result);
            Assert.AreEqual("None", rating);
        }
        public void ChangeFailureRateLowTest()
        {
            //Arrange
            ChangeFailureRate metrics = new ChangeFailureRate();
            int numberOfDays          = 7;
            List <KeyValuePair <DateTime, bool> > changeFailureRateList = new List <KeyValuePair <DateTime, bool> >
            {
                new KeyValuePair <DateTime, bool>(DateTime.Now, true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(1), true),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(2), false),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(3), false),
                new KeyValuePair <DateTime, bool>(DateTime.Now.AddDays(4), false)
            };

            //Act
            float  result = metrics.ProcessChangeFailureRate(changeFailureRateList, numberOfDays);
            string rating = metrics.GetChangeFailureRateRating(result);

            //Assert
            Assert.AreEqual(0.6f, result);
            Assert.AreEqual("Low", rating);
        }
예제 #4
0
        public ChangeFailureRateModel GetChangeFailureRate(bool getSampleData, TableStorageAuth tableStorageAuth,
                                                           DevOpsPlatform targetDevOpsPlatform, string organization_owner, string project_repo, string branch, string buildName_workflowName,
                                                           int numberOfDays, int maxNumberOfItems)
        {
            ListUtility <ChangeFailureRateBuild> utility = new ListUtility <ChangeFailureRateBuild>();
            ChangeFailureRate changeFailureRate          = new ChangeFailureRate();

            if (getSampleData == false)
            {
                //Gets a list of change failure rate builds from Azure storage
                AzureTableStorageDA           daTableStorage = new AzureTableStorageDA();
                Newtonsoft.Json.Linq.JArray   list           = daTableStorage.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableChangeFailureRate, daTableStorage.CreateBuildWorkflowPartitionKey(organization_owner, project_repo, buildName_workflowName));
                List <ChangeFailureRateBuild> initialBuilds  = JsonConvert.DeserializeObject <List <ChangeFailureRateBuild> >(list.ToString());

                //Build the date list and then generate the change failure rate metric
                List <ChangeFailureRateBuild>         builds   = new List <ChangeFailureRateBuild>();
                List <KeyValuePair <DateTime, bool> > dateList = new List <KeyValuePair <DateTime, bool> >();
                float maxBuildDuration = 0f;
                foreach (ChangeFailureRateBuild item in initialBuilds)
                {
                    if (item.Branch == branch && item.StartTime > DateTime.Now.AddDays(-numberOfDays))
                    {
                        //Special branch for Azure DevOps to construct the Url to each build
                        if (targetDevOpsPlatform == DevOpsPlatform.AzureDevOps)
                        {
                            item.Url = $"https://dev.azure.com/{organization_owner}/{project_repo}/_build/results?buildId={item.Id}&view=results";
                        }
                        builds.Add(item);
                    }
                }

                //then build the calcuation
                foreach (ChangeFailureRateBuild item in builds)
                {
                    KeyValuePair <DateTime, bool> newItem = new KeyValuePair <DateTime, bool>(item.StartTime, item.DeploymentWasSuccessful);
                    dateList.Add(newItem);
                }
                //calculate the metric on all of the results
                float changeFailureRateMetric = changeFailureRate.ProcessChangeFailureRate(dateList, numberOfDays);

                //Filter the results to return the last n (maxNumberOfItems)
                List <ChangeFailureRateBuild> uiBuilds = utility.GetLastNItems(builds, maxNumberOfItems);
                foreach (ChangeFailureRateBuild item in uiBuilds)
                {
                    if (item.BuildDuration > maxBuildDuration)
                    {
                        maxBuildDuration = item.BuildDuration;
                    }
                }
                //We need to do some post processing and loop over the list a couple times to find the max build duration, construct a usable url, and calculate a build duration percentage
                foreach (ChangeFailureRateBuild item in uiBuilds)
                {
                    float interiumResult = ((item.BuildDuration / maxBuildDuration) * 100f);
                    item.BuildDurationPercent = Scaling.ScaleNumberToRange(interiumResult, 0, 100, 20, 100);
                }

                ChangeFailureRateModel model = new ChangeFailureRateModel
                {
                    TargetDevOpsPlatform               = targetDevOpsPlatform,
                    DeploymentName                     = buildName_workflowName,
                    ChangeFailureRateBuildList         = uiBuilds,
                    ChangeFailureRateMetric            = changeFailureRateMetric,
                    ChangeFailureRateMetricDescription = changeFailureRate.GetChangeFailureRateRating(changeFailureRateMetric),
                    NumberOfDays     = numberOfDays,
                    MaxNumberOfItems = uiBuilds.Count,
                    TotalItems       = builds.Count
                };
                return(model);
            }
            else
            {
                //Get sample data
                List <ChangeFailureRateBuild> sampleBuilds = utility.GetLastNItems(GetSampleBuilds(), maxNumberOfItems);
                ChangeFailureRateModel        model        = new ChangeFailureRateModel
                {
                    TargetDevOpsPlatform               = targetDevOpsPlatform,
                    DeploymentName                     = buildName_workflowName,
                    ChangeFailureRateBuildList         = sampleBuilds,
                    ChangeFailureRateMetric            = 2f / 10f,
                    ChangeFailureRateMetricDescription = changeFailureRate.GetChangeFailureRateRating(2f / 10f),
                    NumberOfDays     = numberOfDays,
                    MaxNumberOfItems = sampleBuilds.Count,
                    TotalItems       = sampleBuilds.Count
                };
                return(model);
            }
        }