public void TransitionStateCSharp_New_to_Done_succeeded_via_InProgress() { string script = @" self.TransitionToState(""Done"", ""script test""); "; var repository = new WorkItemRepositoryMock(); var logger = Substitute.For<ILogEvents>(); repository.Logger = logger; 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)workItem.Fields["State"]).OriginalValue = string.Empty; workItem.Fields["State"].Value = workItem.Fields["State"].OriginalValue; ((FieldMock)workItem.Fields["State"]).Status = Microsoft.TeamFoundation.WorkItemTracking.Client.FieldStatus.InvalidValueNotInOtherField; repository.SetWorkItems(new[] { workItem }); var engine = new CSharpScriptEngine(repository, logger, false); engine.LoadAndRun("test", script, workItem); Assert.AreEqual("Done", 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); } }
private static WorkItemRepositoryMock MakeRepository(out IWorkItem startPoint) { var repository = new WorkItemRepositoryMock(); var grandParent = new WorkItemMock(repository); grandParent.Id = 1; grandParent.TypeName = "Feature"; var parent = new WorkItemMock(repository); parent.Id = 2; parent.TypeName = "Use Case"; var firstChild = new WorkItemMock(repository); firstChild.Id = 3; firstChild.TypeName = "Task"; var secondChild = new WorkItemMock(repository); secondChild.Id = 4; secondChild.TypeName = "Task"; firstChild.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, repository)); secondChild.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, repository)); parent.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, grandParent.Id, repository)); grandParent.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ChildRelationship, parent.Id, repository)); parent.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ChildRelationship, firstChild.Id, repository)); parent.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ChildRelationship, secondChild.Id, repository)); repository.SetWorkItems(new[] { grandParent, parent, firstChild, secondChild }); startPoint = grandParent; return repository; }
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 RulesAndPolicy_TypeFilter_OnePoliciesOneRulesApplies() { var logger = Substitute.For<ILogEvents>(); var settings = TestHelpers.LoadConfigFromResourceFile("RulesAndPolicy.policies", logger); var repository = new WorkItemRepositoryMock(); var workItem = new WorkItemMock(repository); workItem.Id = 1; workItem.TypeName = "Bug"; workItem["Title"] = "My bug"; repository.SetWorkItems(new[] { workItem }); var context = Substitute.For<IRequestContext>(); context.CollectionName.Returns("Collection2"); 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( Microsoft.TeamFoundation.Framework.Server.EventNotificationStatus.ActionPermitted, result.NotificationStatus); object expected = 42; logger.DidNotReceive().ResultsFromScriptRun("Noop1", expected); logger.DidNotReceive().ResultsFromScriptRun("Noop2", expected); logger.Received().ResultsFromScriptRun("Noop3", expected); } }
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 GlobalList_get_Succeeded() { var repository = new WorkItemRepositoryMock(); var gl = repository.GetGlobalList("Aggregator - UserParameters").ToArray(); Assert.IsNotNull(gl); Assert.AreEqual(1, gl.Length); Assert.AreEqual("myParameter=30", gl[0]); }
private WorkItemRepositoryMock MakeRepositoryMock() { 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 }); return repository; }
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); }
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 Can_run_a_Powershell_script_interacting_with_an_object_model() { string script = @" $self.Fields[""x""].Value = 33 return $self.Fields[""z""].Value "; var repository = new WorkItemRepositoryMock(); var workItem = new WorkItemMock(repository); workItem.Fields["z"].Value = 42; workItem.Fields["x"].Value = 0; workItem.Id = 1; repository.SetWorkItems(new[] { workItem }); var logger = Substitute.For<ILogEvents>(); Assert.IsNotNull(repository.GetWorkItem(1)); var engine = new PsScriptEngine(logger, Debugger.IsAttached); // sanity check Assert.AreEqual(42, workItem.Fields["z"].Value); engine.LoadAndRun("test", script, workItem, repository); var expected = new Collection<PSObject> { new PSObject(42) }; Assert.AreEqual(33, workItem.Fields["x"].Value); logger.Received().ResultsFromScriptRun( "test", Arg.Is<Collection<PSObject>>(x => x.Select(o => o.BaseObject).SequenceEqual(expected.Select(o => o.BaseObject)))); }
public void Can_run_a_Powershell_script_returning_a_value() { string script = @" return $self.Id "; var repository = new WorkItemRepositoryMock(); var workItem = new WorkItemMock(repository); workItem.Id = 1; repository.SetWorkItems(new[] { workItem }); var logger = Substitute.For<ILogEvents>(); Assert.IsNotNull(repository.GetWorkItem(1)); var engine = new PsScriptEngine(logger, Debugger.IsAttached); engine.LoadAndRun("test", script, workItem, repository); var expected = new Collection<PSObject> { new PSObject(1) }; logger.Received().ResultsFromScriptRun( "test", Arg.Is<Collection<PSObject>>(x => x.Select(o => o.BaseObject).SequenceEqual(expected.Select(o => o.BaseObject)))); }
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 Should_aggregate_to_parent() { var logger = Substitute.For<ILogEvents>(); var settings = TestHelpers.LoadConfigFromResourceFile("Rollup.policies", logger); var alternateRepository = new WorkItemRepositoryMock(); var grandParent = new WorkItemMock(alternateRepository); grandParent.Id = 1; grandParent.TypeName = "Feature"; grandParent["Dev Estimate"] = 0.0D; grandParent["Test Estimate"] = 0.0D; var parent = new WorkItemMock(alternateRepository); parent.Id = 2; parent.TypeName = "Use Case"; parent.WorkItemLinks.Add(new WorkItemLinkMock("Parent", 1, alternateRepository)); grandParent.WorkItemLinks.Add(new WorkItemLinkMock("Child", 2, alternateRepository)); parent["Total Work Remaining"] = 3.0D; parent["Total Estimate"] = 4.0D; var child = new WorkItemMock(alternateRepository); child.Id = 3; child.TypeName = "Task"; child.WorkItemLinks.Add(new WorkItemLinkMock("Parent", 2, alternateRepository)); parent.WorkItemLinks.Add(new WorkItemLinkMock("Child", 3, alternateRepository)); child["Estimated Dev Work"] = 10.0D; child["Estimated Test Work"] = 20.0D; child["Remaining Dev Work"] = 1.0D; child["Remaining Test Work"] = 2.0D; child["Finish Date"] = new DateTime(2015, 1, 1); child.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, alternateRepository)); parent.WorkItemLinks.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, grandParent.Id, alternateRepository)); alternateRepository.SetWorkItems(new[] { grandParent, parent, child }); var context = Substitute.For<IRequestContext>(); var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger); using (var processor = new EventProcessor(alternateRepository, runtime)) { var notification = Substitute.For<INotification>(); notification.WorkItemId.Returns(3); var result = processor.ProcessEvent(context, notification); Assert.AreEqual(0, result.ExceptionProperties.Count()); Assert.IsFalse(child.InternalWasSaveCalled); Assert.IsTrue(parent.InternalWasSaveCalled); Assert.IsFalse(grandParent.InternalWasSaveCalled); Assert.AreEqual(3.0D, parent["Total Work Remaining"]); Assert.AreEqual(30.0D, parent["Total Estimate"]); Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus); } }
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); }
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); }
public WorkItemMock(WorkItemRepositoryMock store) : base(store, store.Logger) { this.fields = new FieldCollectionMock(this); this.IsDirty = false; }