public void Calculate_Includes_All_Live_Deployments()
        {
            // Arrange
            var project = Datasetup.AddProject(_projects);
            var release = Datasetup.AddRelease(project);

            Datasetup.AddDeployment(release, environment: "Live", created: _dtNow);
            Datasetup.AddDeployment(release, environment: "Live", created: _dtWeekAgo);
            Datasetup.AddDeployment(release, environment: "Live", created: _dt11DaysAgo);

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            Assert.AreEqual(_dtNow.DayOfWeek, result);
        }
        public void Calculate_When_Tied_Returns_First_Day()
        {
            // Arrange
            var project = Datasetup.AddProject(_projects);
            var release = Datasetup.AddRelease(project);

            Datasetup.AddDeployment(release, environment: "Live", created: _dtNow);
            Datasetup.AddDeployment(release, environment: "Live", created: _dt11DaysAgo);

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            var expected = Math.Min((int)_dtNow.DayOfWeek, (int)_dt11DaysAgo.DayOfWeek);

            Assert.AreEqual(expected, (int)result);
        }
        public void Calculate_Returns_Correct_Count_By_Environment()
        {
            // Arrange
            var project  = Datasetup.AddProject(_projects);
            var release1 = Datasetup.AddRelease(project);
            var release2 = Datasetup.AddRelease(project);

            Datasetup.AddDeployment(release1, true, "env1");
            Datasetup.AddDeployment(release1, true, "env2");
            Datasetup.AddDeployment(release2, true, "env1");

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            Assert.AreEqual(2, result.Single(r => r.Environment == "env1").NoOfSuccessDeployments);
            Assert.AreEqual(1, result.Single(r => r.Environment == "env2").NoOfSuccessDeployments);
        }
        public void Calculate_Returns_Correct_Count_By_Year()
        {
            // Arrange
            var dtNow     = DateTime.Now;
            var dtYearAgo = DateTime.Now.AddYears(-1);
            var project   = Datasetup.AddProject(_projects);
            var release1  = Datasetup.AddRelease(project);
            var release2  = Datasetup.AddRelease(project);

            Datasetup.AddDeployment(release1, true, null, dtNow);
            Datasetup.AddDeployment(release1, true, null, dtYearAgo);
            Datasetup.AddDeployment(release2, true, null, dtNow);

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            Assert.AreEqual(2, result.Single(r => r.Year == dtNow.Year).NoOfSuccessDeployments);
            Assert.AreEqual(1, result.Single(r => r.Year == dtYearAgo.Year).NoOfSuccessDeployments);
        }
        public void Calculate_Includes_Correct_Successful_Releases_WithinGroup()
        {
            // Arrange
            var project1 = Datasetup.AddProject(_projects, group: "Group1");
            var project2 = Datasetup.AddProject(_projects, group: "Group1");

            Datasetup.AddReleaseWithSingleDeployment(project1, environment: "Test", isSuccess: true);
            Datasetup.AddReleaseWithSingleDeployment(project1, environment: "Live", version: "success1", isSuccess: true);
            var release2_1 = Datasetup.AddRelease(project2, version: "success2");

            Datasetup.AddDeployment(release2_1, isSuccess: false, environment: "Live");
            Datasetup.AddDeployment(release2_1, isSuccess: true, environment: "Live");

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            var project1Result = result.Single(p => p.ProjectGroup == "Group1");

            Assert.AreEqual(2, project1Result.Releases.Count(r => r.WasSuccessful));
            Assert.IsTrue(project1Result.Releases.Any(r => r.Version == "success1"));
            Assert.IsTrue(project1Result.Releases.Any(r => r.Version == "success1"));
        }
        public void Calculate_Returns_Correct_Count_By_Project_Group()
        {
            // Arrange
            var project1_1   = Datasetup.AddProject(_projects, null, "group1");
            var project1_2   = Datasetup.AddProject(_projects, null, "group1");
            var project2_1   = Datasetup.AddProject(_projects, null, "group2");
            var release1_1_1 = Datasetup.AddRelease(project1_1);
            var release1_1_2 = Datasetup.AddRelease(project1_1);
            var release1_2_1 = Datasetup.AddRelease(project1_2);
            var release2_1_1 = Datasetup.AddRelease(project2_1);

            Datasetup.AddDeployment(release1_1_1, true);            //group1
            Datasetup.AddDeployment(release1_1_1, true);            //group1
            Datasetup.AddDeployment(release1_1_2, true);            //group1
            Datasetup.AddDeployment(release1_2_1, true);            //group1
            Datasetup.AddDeployment(release2_1_1, true);            //group2

            // Act
            var result = _calculator.Calculate(_projects);

            // Assert
            Assert.AreEqual(4, result.Single(r => r.ProjectGroup == "group1").NoOfSuccessDeployments);
            Assert.AreEqual(1, result.Single(r => r.ProjectGroup == "group2").NoOfSuccessDeployments);
        }