Ejemplo n.º 1
0
 public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
 {
     _workspace = workspace;
     _policyEvaluator = policyEvaluator;
     _contextVersion = contextVersion;
     _remote = remote;
     _checkinOptions = checkinOptions;
     _tfsHelper = tfsHelper;
     _localDirectory = localDirectory;
     _stdout = stdout;
 }
Ejemplo n.º 2
0
 public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
 {
     _workspace       = workspace;
     _policyEvaluator = policyEvaluator;
     _contextVersion  = contextVersion;
     _remote          = remote;
     _checkinOptions  = checkinOptions;
     _tfsHelper       = tfsHelper;
     _localDirectory  = localDirectory;
     _stdout          = stdout;
 }
Ejemplo n.º 3
0
        public TfsWorkspace(IWorkspace workspace, string localDirectory, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
        {
            _workspace       = workspace;
            _policyEvaluator = policyEvaluator;
            _contextVersion  = contextVersion;
            _checkinOptions  = checkinOptions;
            _tfsHelper       = tfsHelper;
            _localDirectory  = remote.Repository.IsBare ? Path.GetFullPath(localDirectory) : localDirectory;

            this.Remote = remote;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        public void Nothing_to_checkin()
        {
            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);

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

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

            Assert.Equal("Nothing to checkin!", ex.Message);
        }
Ejemplo n.º 6
0
        public void Policy_failed()
        {
            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.");

            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("No changes checked in.", ex.Message);
            Assert.Contains("[ERROR] Policy: No work items associated.", logger.ToString());
        }
Ejemplo n.º 7
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>();
            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());
        }