示例#1
0
        public void TransitionState_to_non_existing()
        {
            var repository = new WorkItemRepositoryMock();

            repository.Logger = Substitute.For <ILogEvents>();
            var workItem     = new WorkItemMock(repository);
            var workItemType = new WorkItemTypeMock()
            {
                Name            = "Task",
                DocumentContent = TestHelpers.LoadTextFromEmbeddedResource("task.xml")
            };

            workItem.Id       = 42;
            workItem.Type     = workItemType;
            workItem.TypeName = workItemType.Name;
            workItem.Fields["State"].Value = string.Empty;
            ((FieldMock)workItem.Fields["State"]).OriginalValue = string.Empty;
            ((FieldMock)workItem.Fields["State"]).Status        = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField;
            repository.SetWorkItems(new[] { workItem });
            string targetState = "DoesNotExists";

            workItem.TransitionToState(targetState, "test");

            Assert.AreNotEqual(targetState, workItem.Fields["State"].Value);
            Assert.AreEqual(workItem.Fields["State"].OriginalValue, workItem.Fields["State"].Value);
            Assert.IsFalse(workItem.InternalWasSaveCalled);
        }
示例#2
0
        public void TransitionState_New_to_Done_succeeded_via_InProgress()
        {
            var logger     = new DebugEventLogger();
            var settings   = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger);
            var repository = new WorkItemRepositoryMock();
            var context    = Substitute.For <IRequestContext>();

            context.GetProjectCollectionUri().Returns(
                new System.Uri("http://localhost:8080/tfs/DefaultCollection"));
            var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger, (c, i, l) => repository);

            var workItem     = new WorkItemMock(repository, runtime);
            var workItemType = new WorkItemTypeMock()
            {
                Name            = "Task",
                DocumentContent = TestHelpers.LoadTextFromEmbeddedResource("task.xml")
            };

            workItem.Id   = 42;
            workItem.Type = workItemType;

            FieldMock mockedField = new FieldMock(workItem, "State");

            workItem.Fields[mockedField.Name] = mockedField;
            mockedField.OriginalValue         = string.Empty;
            workItem.Fields["State"].Value    = workItem.Fields["State"].OriginalValue;
            mockedField.Status = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField;
            repository.SetWorkItems(new[] { workItem });
            string targetState = "Done";

            workItem.TransitionToState(targetState, "test");

            Assert.AreEqual(targetState, workItem.Fields["State"].Value);
            Assert.AreEqual(2, workItem.InternalSaveCount);
        }
示例#3
0
        public void TransitionState_InProgress_to_Done_succeeded()
        {
            var logger     = new DebugEventLogger();
            var settings   = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger);
            var repository = new WorkItemRepositoryMock();
            var context    = Substitute.For <IRequestContext>();

            context.GetProjectCollectionUri().Returns(
                new System.Uri("http://localhost:8080/tfs/DefaultCollection"));
            var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger, (c, i, l) => repository);

            var workItem = new WorkItemMock(repository, runtime);

            workItem.Id       = 42;
            workItem.TypeName = "Task";
            workItem.Type     = new WorkItemTypeMock()
            {
                Name = "Task"
            };
            workItem.Fields["State"].Value = "In Progress";
            repository.SetWorkItems(new[] { workItem });
            string targetState = "Done";

            workItem.TransitionToState(targetState, "test");

            Assert.AreEqual(targetState, workItem.Fields["State"].Value);
            Assert.IsTrue(workItem.InternalWasSaveCalled);
        }
        public void TransitionState_New_to_Done_succeeded_via_InProgress()
        {
            var repository = new WorkItemRepositoryMock();

            repository.Logger = Substitute.For <ILogEvents>();
            var workItem     = new WorkItemMock(repository);
            var workItemType = new WorkItemTypeMock()
            {
                Name            = "Task",
                DocumentContent = TestHelpers.LoadTextFromEmbeddedResource("task.xml")
            };

            workItem.Id       = 42;
            workItem.Type     = workItemType;
            workItem.TypeName = workItemType.Name;
            FieldMock mockedField = new FieldMock(workItem, "State");

            workItem.Fields[mockedField.Name] = mockedField;
            mockedField.OriginalValue         = string.Empty;
            workItem.Fields["State"].Value    = workItem.Fields["State"].OriginalValue;
            mockedField.Status = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField;
            repository.SetWorkItems(new[] { workItem });
            string targetState = "Done";

            workItem.TransitionToState(targetState, "test");

            Assert.AreEqual(targetState, workItem.Fields["State"].Value);
            Assert.AreEqual(2, workItem.InternalSaveCount);
        }
示例#5
0
        public void TransitionState_InProgress_to_Done_succeeded()
        {
            var repository = new WorkItemRepositoryMock();

            repository.Logger = Substitute.For <ILogEvents>();
            var workItem = new WorkItemMock(repository);

            workItem.Id       = 42;
            workItem.TypeName = "Task";
            workItem.Fields["State"].Value = "In Progress";
            repository.SetWorkItems(new[] { workItem });
            string targetState = "Done";

            workItem.TransitionToState(targetState, "test");

            Assert.AreEqual(targetState, workItem.Fields["State"].Value);
            Assert.IsTrue(workItem.InternalWasSaveCalled);
        }
示例#6
0
        public void TransitionState_to_non_existing()
        {
            var logger     = new DebugEventLogger();
            var settings   = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger);
            var repository = new WorkItemRepositoryMock();

            System.Func <IRuntimeContext, IScriptLibrary> scriptLibraryBuilder = (x) => Substitute.For <IScriptLibrary>();
            var context = Substitute.For <IRequestContext>();

            context.GetProjectCollectionUri().Returns(
                new System.Uri("http://localhost:8080/tfs/DefaultCollection"));
            var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger, (c) => repository, scriptLibraryBuilder);

            var workItem     = new WorkItemMock(repository, runtime);
            var workItemType = new WorkItemTypeMock()
            {
                Name            = "Task",
                DocumentContent = TestHelpers.LoadTextFromEmbeddedResource("task.xml")
            };

            workItem.Id       = 42;
            workItem.Type     = workItemType;
            workItem.TypeName = workItemType.Name;

            FieldMock mockedField = new FieldMock(workItem, "System.State");

            mockedField.Value                 = string.Empty;
            mockedField.OriginalValue         = string.Empty;
            mockedField.Status                = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField;
            workItem.Fields[mockedField.Name] = mockedField;

            repository.SetWorkItems(new[] { workItem });
            string targetState = "DoesNotExists";

            workItem.TransitionToState(targetState, "test");

            Assert.AreNotEqual(targetState, workItem.Fields["System.State"].Value);
            Assert.AreEqual(workItem.Fields["System.State"].OriginalValue, workItem.Fields["System.State"].Value);
            Assert.IsFalse(workItem.InternalWasSaveCalled);
        }