public void TestPolicyPasses_When_NoReview_NoFilesFound_InConfigPath()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed      = true,
                    FailIfAnyResponseIsNeedsWork = true,
                    MinPassLevel = PassLevel.LooksGood,
                    Paths        = new List <string>()
                    {
                        "$/Project/MAIN"
                    }
                }
            };

            using (var context = ShimsContext.Create())
            {
                var checkin = FakeUtils.CreatePendingCheckin(new List <ShimWorkItem>()
                {
                    null
                });

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length == 0);
            }
        }
        public void TestPolicyPassess_When_MinPassLeveIsWithComments_And_RequestHasDeclinedResponses()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed      = true,
                    FailIfAnyResponseIsNeedsWork = true,
                    MinPassLevel = PassLevel.WithComments
                }
            };

            using (var context = ShimsContext.Create())
            {
                var responses = new List <WorkItem>()
                {
                    FakeUtils.CreateCodeReviewResponse(2, "Closed", "Declined"),
                    FakeUtils.CreateCodeReviewResponse(3, "Closed", "With Comments")
                };
                var reviewWorkItem = FakeUtils.CreateCodeReviewRequest(1, "Closed", "Closed", responses);
                var checkin        = FakeUtils.CreatePendingCheckin(reviewWorkItem);

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length == 0);
            }
        }
        public void TestPolicySucceeds_When_PassLevelIsLooksGood_And_AllResponsesAreLooksGood()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed      = true,
                    FailIfAnyResponseIsNeedsWork = true,
                    MinPassLevel = PassLevel.LooksGood
                }
            };

            using (var context = ShimsContext.Create())
            {
                var responses = new List <WorkItem>()
                {
                    FakeUtils.CreateCodeReviewResponse(2, "Closed", "Looks Good"),
                    FakeUtils.CreateCodeReviewResponse(3, "Closed", "Looks Good")
                };
                var reviewWorkItem = FakeUtils.CreateCodeReviewRequest(1, "Closed", "Closed", responses);
                var checkin        = FakeUtils.CreatePendingCheckin(reviewWorkItem);

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length == 0);
            }
        }
        public void TestPolicyFails_When_AnyNeedsWorkFails_And_OneResponseIsNeedsWork()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed = true,
                    FailIfAnyResponseIsNeedsWork = true,
                    MinPassLevel = PassLevel.LooksGood
                }
            };

            using (var context = ShimsContext.Create())
            {
                var responses = new List<WorkItem>()
                {
                    FakeUtils.CreateCodeReviewResponse(2, "Closed", "Looks Good"),
                    FakeUtils.CreateCodeReviewResponse(3, "Closed", "Needs Work")
                };
                var reviewWorkItem = FakeUtils.CreateCodeReviewRequest(1, "Closed", "Closed", responses);
                var checkin = FakeUtils.CreatePendingCheckin(reviewWorkItem);

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length > 0);
            }
        }
Ejemplo n.º 5
0
        public void TestPolicyFails_When_Review_FilesFound_AtRootLevel_InConfigPath()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed      = true,
                    FailIfAnyResponseIsNeedsWork = true,
                    MinPassLevel = PassLevel.LooksGood,
                    Paths        = new List <string>()
                    {
                        "$/Project/Folder"
                    }
                }
            };

            using (var context = ShimsContext.Create())
            {
                var checkin = FakeUtils.CreatePendingCheckin(new List <ShimWorkItem>()
                {
                    null
                }, new List <PendingChange>()
                {
                    new ShimPendingChange()
                    {
                        ServerItemGet = () => "$/Project/Folder/Item1.cs"
                    }
                });

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length > 0);
            }
        }
		public void TestPolicyFails_When_NoReview()
		{
			var policy = new CodeReviewPolicy()
			{
				Config = new CodeReviewPolicyConfig()
				{
					RequireReviewToBeClosed = true,
					FailIfAnyResponseIsNeedsWork = true,
					MinPassLevel = PassLevel.LooksGood
				}
			};

			using (var context = ShimsContext.Create())
			{
				var checkin = FakeUtils.CreatePendingCheckin(new List<ShimWorkItem>() { null });

				policy.Initialize(checkin);
				var failures = policy.Evaluate();
				Assert.IsTrue(failures.Length > 0);
			}
		}
        public void TestPolicyFails_When_MinPassLeveIsNone_And_NoRequests()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed      = false,
                    FailIfAnyResponseIsNeedsWork = false,
                    MinPassLevel = PassLevel.None
                }
            };

            using (var context = ShimsContext.Create())
            {
                var checkin = FakeUtils.CreatePendingCheckin(new List <ShimWorkItem>());

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length > 0);
            }
        }
        public void TestPolicyPassess_When_MinPassLeveIsNone_And_RequestHasNoResponses()
        {
            var policy = new CodeReviewPolicy()
            {
                Config = new CodeReviewPolicyConfig()
                {
                    RequireReviewToBeClosed = false,
                    FailIfAnyResponseIsNeedsWork = false,
                    MinPassLevel = PassLevel.None
                }
            };

            using (var context = ShimsContext.Create())
            {
                var reviewWorkItem = FakeUtils.CreateCodeReviewRequest(1, "Requested", "", new List<WorkItem>());
                var checkin = FakeUtils.CreatePendingCheckin(reviewWorkItem);

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.IsTrue(failures.Length == 0);
            }
        }
		public void TestPolicyPassess_When_MinPassLeveIsWithComments_And_RequestHasDeclinedResponses()
		{
			var policy = new CodeReviewPolicy()
			{
				Config = new CodeReviewPolicyConfig()
				{
					RequireReviewToBeClosed = true,
					FailIfAnyResponseIsNeedsWork = true,
					MinPassLevel = PassLevel.WithComments
				}
			};

			using (var context = ShimsContext.Create())
			{
				var responses = new List<WorkItem>()
				{
					FakeUtils.CreateCodeReviewResponse(2, "Closed", "Declined"),
					FakeUtils.CreateCodeReviewResponse(3, "Closed", "With Comments")
				};
				var reviewWorkItem = FakeUtils.CreateCodeReviewRequest(1, "Closed", "Closed", responses);
				var checkin = FakeUtils.CreatePendingCheckin(reviewWorkItem);

				policy.Initialize(checkin);
				var failures = policy.Evaluate();
				Assert.IsTrue(failures.Length == 0);
			}
		}