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);
            }
        }
Exemplo n.º 4
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_If_OneWI_AssignedToSomeoneElse_And_OneWIAssignedToMe()
        {
            var policy = new OneWorkItemPolicy()
            {
                Config = new OneWorkItemPolicyConfig()
                {
                    WorkItemType = "Task", ExactlyOne = true
                }
            };

            using (var context = ShimsContext.Create())
            {
                var list = new List <ShimWorkItem>()
                {
                    FakeUtils.CreateWorkItem("Task", "Joe"),
                    FakeUtils.CreateWorkItem("Task", "Bob"),
                };
                var checkin = FakeUtils.CreatePendingCheckin(list);

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.AreEqual(1, failures.Length);
                Assert.IsTrue(failures[0].Message.StartsWith("Changeset is required to be associated with exactly one work item of type 'Task' that has been assigned to you."));
            }
        }
        public void TestPolicyFails_If_NoWorkItemTypes_Configured()
        {
            var policy = new OneWorkItemPolicy()
            {
                Config = new OneWorkItemPolicyConfig()
            };

            using (var context = ShimsContext.Create())
            {
                var checkin = FakeUtils.CreatePendingCheckin(FakeUtils.CreateWorkItem("Task", "Bob"));

                policy.Initialize(checkin);
                var failures = policy.Evaluate();
                Assert.AreEqual(1, failures.Length);
                Assert.AreEqual("No Work Item Type has been specified for the One Work Item Policy. Please contact your TFS administrator", failures[0].Message);
            }
        }
        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 TestPolicySucceeds_If_OneWorkItem_OfType_Associated()
        {
            var policy = new OneWorkItemPolicy()
            {
                Config = new OneWorkItemPolicyConfig()
                {
                    WorkItemType = "Task", ExactlyOne = true
                }
            };

            using (var context = ShimsContext.Create())
            {
                var list = new List <ShimWorkItem>()
                {
                    FakeUtils.CreateWorkItem("Task", "Bob")
                };
                var checkin = FakeUtils.CreatePendingCheckin(list);

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