コード例 #1
0
        public void Nothing_to_checkin()
        {
            workspace.Setup(w => w.GetPendingChanges()).Returns((IPendingChange[])null);

            var ex = Assert.Throws <GitTfsException>(() =>
            {
                var result = tfsWorkspace.Checkin(checkinOptions);
            });

            Assert.Equal("Nothing to checkin!", ex.Message);
        }
コード例 #2
0
        public void Policy_failed_and_Force_without_an_OverrideReason()
        {
            var logger = new StringWriter();

            Trace.Listeners.Add(new TextWriterTraceListener(logger));
            IWorkspace       workspace      = MockRepository.GenerateStub <IWorkspace>();
            string           localDirectory = string.Empty;
            TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>();
            IGitTfsRemote    remote         = MockRepository.GenerateStub <IGitTfsRemote>();

            remote.Repository = MockRepository.GenerateStub <IGitRepository>();
            CheckinOptions         checkinOptions  = new CheckinOptions();
            ITfsHelper             tfsHelper       = MockRepository.GenerateStub <ITfsHelper>();
            CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator();

            TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator);

            IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>();

            IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange };
            workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges);

            ICheckinEvaluationResult checkinEvaluationResult =
                new StubbedCheckinEvaluationResult()
                .WithPoilicyFailure("No work items associated.");

            checkinOptions.Force = true;

            workspace.Stub(w => w.EvaluateCheckin(
                               Arg <TfsCheckinEvaluationOptions> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <ICheckinNote> .Is.Anything,
                               Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything))
            .Return(checkinEvaluationResult);

            workspace.Expect(w => w.Checkin(
                                 Arg <IPendingChange[]> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <ICheckinNote> .Is.Anything,
                                 Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything,
                                 Arg <TfsPolicyOverrideInfo> .Is.Anything,
                                 Arg <bool> .Is.Anything))
            .Return(0);

            var ex = Assert.Throws <GitTfsException>(() =>
            {
                var result = tfsWorkspace.Checkin(checkinOptions);
            });

            Assert.Equal("A reason must be supplied (-f REASON) to override the policy violations.", ex.Message);
            Assert.Contains("[ERROR] Policy: No work items associated.", logger.ToString());
        }
コード例 #3
0
        public void Policy_failed_and_Force_with_an_OverrideReason()
        {
            IWorkspace       workspace      = MockRepository.GenerateStub <IWorkspace>();
            string           localDirectory = string.Empty;
            TextWriter       writer         = new StringWriter();
            TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>();
            IGitTfsRemote    remote         = MockRepository.GenerateStub <IGitTfsRemote>();

            remote.Repository = MockRepository.GenerateStub <IGitRepository>();
            CheckinOptions         checkinOptions  = new CheckinOptions();
            ITfsHelper             tfsHelper       = MockRepository.GenerateStub <ITfsHelper>();
            CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator();

            TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator);

            IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>();

            IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange };
            workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges);

            ICheckinEvaluationResult checkinEvaluationResult =
                new StubbedCheckinEvaluationResult()
                .WithPoilicyFailure("No work items associated.");

            checkinOptions.Force          = true;
            checkinOptions.OverrideReason = "no work items";

            workspace.Stub(w => w.EvaluateCheckin(
                               Arg <TfsCheckinEvaluationOptions> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <ICheckinNote> .Is.Anything,
                               Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything))
            .Return(checkinEvaluationResult);

            workspace.Expect(w => w.Checkin(
                                 Arg <IPendingChange[]> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <ICheckinNote> .Is.Anything,
                                 Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything,
                                 Arg <TfsPolicyOverrideInfo> .Is.Anything,
                                 Arg <bool> .Is.Anything))
            .Return(1);

            var result = tfsWorkspace.Checkin(checkinOptions);

            Assert.Contains("[OVERRIDDEN] Policy: No work items associated.", writer.ToString());
        }
コード例 #4
0
        public void Checkin_failed()
        {
            IWorkspace       workspace      = MockRepository.GenerateStub <IWorkspace>();
            string           localDirectory = string.Empty;
            TextWriter       writer         = new StringWriter();
            TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>();
            IGitTfsRemote    remote         = MockRepository.GenerateStub <IGitTfsRemote>();

            remote.Repository = MockRepository.GenerateStub <IGitRepository>();
            CheckinOptions         checkinOptions  = new CheckinOptions();
            ITfsHelper             tfsHelper       = MockRepository.GenerateStub <ITfsHelper>();
            CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator();

            TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator);

            IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>();

            IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange };
            workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges);

            ICheckinEvaluationResult checkinEvaluationResult =
                new StubbedCheckinEvaluationResult();

            workspace.Stub(w => w.EvaluateCheckin(
                               Arg <TfsCheckinEvaluationOptions> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <IPendingChange[]> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <string> .Is.Anything,
                               Arg <ICheckinNote> .Is.Anything,
                               Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything))
            .Return(checkinEvaluationResult);

            workspace.Expect(w => w.Checkin(
                                 Arg <IPendingChange[]> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <string> .Is.Anything,
                                 Arg <ICheckinNote> .Is.Anything,
                                 Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything,
                                 Arg <TfsPolicyOverrideInfo> .Is.Anything,
                                 Arg <bool> .Is.Anything))
            .Return(0);

            var ex = Assert.Throws <GitTfsException>(() =>
            {
                var result = tfsWorkspace.Checkin(checkinOptions);
            });

            Assert.Equal("Checkin failed!", ex.Message);
        }
コード例 #5
0
        public void Nothing_to_checkin()
        {
            IWorkspace             workspace       = MockRepository.GenerateStub <IWorkspace>();
            string                 localDirectory  = string.Empty;
            TextWriter             writer          = new StringWriter();
            TfsChangesetInfo       contextVersion  = MockRepository.GenerateStub <TfsChangesetInfo>();
            IGitTfsRemote          remote          = MockRepository.GenerateStub <IGitTfsRemote>();
            CheckinOptions         checkinOptions  = new CheckinOptions();
            ITfsHelper             tfsHelper       = MockRepository.GenerateStub <ITfsHelper>();
            CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator();

            TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator);

            workspace.Stub(w => w.GetPendingChanges()).Return(null);

            var ex = Assert.Throws <GitTfsException>(() =>
            {
                var result = tfsWorkspace.Checkin(checkinOptions);
            });

            Assert.Equal("Nothing to checkin!", ex.Message);
        }