Beispiel #1
0
        public async Task <bool> UpdateChangeFailureRate(TableStorageAuth tableStorageAuth,
                                                         string organization_owner, string project_repo, string buildName_workflowName,
                                                         int percentComplete, int numberOfDays)
        {
            //Gets a list of change failure rate builds
            AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
            string partitionKey = daTableStorage.CreateBuildWorkflowPartitionKey(organization_owner, project_repo, buildName_workflowName);

            Newtonsoft.Json.Linq.JArray   list          = daTableStorage.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableChangeFailureRate, partitionKey);
            List <ChangeFailureRateBuild> initialBuilds = JsonConvert.DeserializeObject <List <ChangeFailureRateBuild> >(list.ToString());

            //Get the list of items we are going to process, within the date/day range
            List <ChangeFailureRateBuild> builds = new List <ChangeFailureRateBuild>();

            foreach (ChangeFailureRateBuild item in initialBuilds)
            {
                if (item.StartTime > DateTime.Now.AddDays(-numberOfDays))
                {
                    builds.Add(item);
                }
            }

            //Using the percent, convert it to a fraction
            FractionConverter converter      = new FractionConverter();
            FractionModel     fracationModel = converter.ConvertToFraction(percentComplete);
            int numerator   = fracationModel.Numerator;
            int denominator = fracationModel.Denominator;

            //Get builds for positive (builds we will set DeploymentWasSuccessful=true) and negative (builds we will set to DeploymentWasSuccessful=false)
            Console.WriteLine($"numerator {numerator} / denominator {denominator}");
            //TODO: remember how this (x, numerator) syntax works so it can be documented. oooof.
            List <ChangeFailureRateBuild> postiveBuilds  = builds.Where((x, numerator) => numerator % denominator != 0).ToList();
            List <ChangeFailureRateBuild> negativeBuilds = builds.Where((x, numerator) => numerator % denominator == 0).ToList();

            //Make the updates
            TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableChangeFailureRate);

            foreach (ChangeFailureRateBuild item in postiveBuilds)
            {
                item.DeploymentWasSuccessful = true;
                await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true);
            }
            foreach (ChangeFailureRateBuild item in negativeBuilds)
            {
                item.DeploymentWasSuccessful = false;
                await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true);
            }

            return(true);
        }
        public void Fraction98PercentTest()
        {
            //Arrange
            FractionConverter fraction = new FractionConverter();
            int percent = 98;

            //Act
            FractionModel model = fraction.ConvertToFraction(percent);

            //Assert
            Assert.AreNotEqual(null, model);
            Assert.AreEqual(49, model.Numerator);
            Assert.AreEqual(50, model.Denominator);
        }