public void GlobalList_UserParameterReplaceExisting_Succeeded() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("UserParameters.policies", logger); var repository = new WorkItemRepositoryMock(); var workItem = new WorkItemMock(repository); workItem.Id = 1; workItem.TypeName = "Use Case"; workItem["Title"] = "The car shall have a maximum speed of {myParameter}(25) mph."; repository.SetWorkItems(new[] { workItem }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For <INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsTrue(workItem.InternalWasSaveCalled); Assert.AreEqual("The car shall have a maximum speed of {myParameter}(30) mph.", workItem.Fields["Title"].Value); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
public void WorkItemLink_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Use Case"; parent["Title"] = "UC"; var child = new WorkItemMock(repository); child.Id = 2; child.TypeName = "Task"; child["Title"] = "TSK"; repository.SetWorkItems(new[] { parent, child }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(2); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsTrue(child.InternalWasSaveCalled); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
public void WorkItemLink_addExisting_noop() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Use Case"; parent["Title"] = "UC"; var child = new WorkItemMock(repository); child.Id = 2; child.TypeName = "Task"; child["Title"] = "TSK"; child.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, repository)); repository.SetWorkItems(new[] { parent, child }); var context = Substitute.For<IRequestContext>(); var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger); using (var processor = new EventProcessor(repository, runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(2); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsFalse(child.InternalWasSaveCalled); Assert.IsFalse(parent.InternalWasSaveCalled); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
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); }
public void GlobalList_UserParameterReplaceExisting_Succeeded() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("UserParameters.policies", logger); var repository = new WorkItemRepositoryMock(); var workItem = new WorkItemMock(repository); workItem.Id = 1; workItem.TypeName = "Use Case"; workItem["Title"] = "The car shall have a maximum speed of {myParameter}(25) mph."; repository.SetWorkItems(new[] { workItem }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsTrue(workItem.InternalWasSaveCalled); Assert.AreEqual("The car shall have a maximum speed of {myParameter}(30) mph.", workItem.Fields["Title"].Value); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
public void WorkItem_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Bug"; parent[CoreFieldReferenceNames.Title] = "My bug #1"; parent[CoreFieldReferenceNames.TeamProject] = "MyTeamProject"; repository.SetWorkItems(new[] { parent }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For <INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.AreEqual(1, repository.LoadedWorkItems.Count); Assert.AreEqual(1, repository.CreatedWorkItems.Count); } }
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 WorkItem_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Bug"; parent["Title"] = "My bug #1"; repository.SetWorkItems(new[] { parent }); var context = Substitute.For <IRequestContext>(); var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger); using (var processor = new EventProcessor(repository, runtime)) { var notification = Substitute.For <INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.AreEqual(1, repository.LoadedWorkItems.Count); Assert.AreEqual(1, repository.CreatedWorkItems.Count); Assert.IsTrue(parent.InternalWasSaveCalled); Assert.IsTrue(parent.HasChildren()); } }
public void FluentNavigation_FollowingLinks_two_times() { string script = @" var requirements = self.FollowingLinks(""Microsoft.VSTS.Common.TestedBy-Reverse""); foreach(var req in requirements) { logger.Log(""Requirement #{0}"", req.Id); var testCases = req.FollowingLinks(""Microsoft.VSTS.Common.TestedBy-Forward""); double remaining = testCases.Sum(tc => tc.GetField(""Microsoft.VSTS.Scheduling.RemainingWork"", 0.0)); req[""Custom.RemainingWork""] = req.GetField(""Microsoft.VSTS.Scheduling.RemainingWork"", 0.0) + remaining; } "; IWorkItem startPoint; var repository = MakeRepository(out startPoint); var logger = new DebugEventLogger(); repository.Logger = logger; var tc2 = repository.GetWorkItem(22); var library = Substitute.For <IScriptLibrary>(); var engine = new CSharpScriptEngine(logger, true, library); engine.LoadAndRun("test", script, tc2, repository); Assert.AreEqual(42.0, startPoint["Custom.RemainingWork"]); }
public void TransitionStateCSharp_New_to_Done_succeeded_via_InProgress() { 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://*****:*****@" self.TransitionToState(""Done"", ""script test""); "; repository.Logger = logger; 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"); workItem.Fields[mockedField.Name] = mockedField; mockedField.OriginalValue = string.Empty; mockedField.Value = mockedField.OriginalValue; mockedField.Status = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField; repository.SetWorkItems(new[] { workItem }); var library = Substitute.For <IScriptLibrary>(); var engine = new CSharpScriptEngine(logger, false, library); engine.LoadAndRun("test", script, workItem, repository); Assert.AreEqual("Done", workItem.Fields["System.State"].Value); Assert.AreEqual(2, workItem.InternalSaveCount); }
public void WorkItemLink_addExisting_noop() { 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://*****:*****@"C:\WorkItemLink_addExisting_noop", settings, context, logger, (c) => repository, scriptLibraryBuilder); var parent = new WorkItemMock(repository, runtime); parent.Id = 1; parent.TypeName = "Use Case"; parent["Title"] = "UC"; var child = new WorkItemMock(repository, runtime); child.Id = 2; child.TypeName = "Task"; child["Title"] = "TSK"; child.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, repository)); repository.SetWorkItems(new[] { parent, child }); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For <INotification>(); notification.WorkItemId.Returns(2); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count); Assert.IsFalse(child.InternalWasSaveCalled); Assert.IsFalse(parent.InternalWasSaveCalled); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
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); }
public void WorkItemLink_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Use Case"; parent["Title"] = "UC"; var child = new WorkItemMock(repository); child.Id = 2; child.TypeName = "Task"; child["Title"] = "TSK"; repository.SetWorkItems(new[] { parent, child }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For <INotification>(); notification.WorkItemId.Returns(2); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsTrue(child.InternalWasSaveCalled); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
public void WorkItem_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Bug"; parent["Title"] = "My bug #1"; repository.SetWorkItems(new[] { parent }); var context = Substitute.For<IRequestContext>(); var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger); using (var processor = new EventProcessor(repository, runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.AreEqual(1, repository.LoadedWorkItems.Count); Assert.AreEqual(1, repository.CreatedWorkItems.Count); Assert.IsTrue(parent.InternalWasSaveCalled); Assert.IsTrue(parent.HasChildren()); } }
public void WorkItem_addNew_succeeds() { var logger = new DebugEventLogger(); var settings = TestHelpers.LoadConfigFromResourceFile("NewObjects.policies", logger); var repository = new WorkItemRepositoryMock(); var parent = new WorkItemMock(repository); parent.Id = 1; parent.TypeName = "Bug"; parent[CoreFieldReferenceNames.Title] = "My bug #1"; parent[CoreFieldReferenceNames.TeamProject] = "MyTeamProject"; repository.SetWorkItems(new[] { parent }); 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); using (var processor = new EventProcessor(runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(1); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.AreEqual(1, repository.LoadedWorkItems.Count); Assert.AreEqual(1, repository.CreatedWorkItems.Count); } }