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.GetProjectCollectionUri().Returns( new System.Uri("http://localhost:8080/tfs/DefaultCollection")); context.CollectionName.Returns("Collection2"); 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( 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); } }
private WorkItemRepositoryMock MakeRepositoryMock() { var logger = Substitute.For <ILogEvents>(); 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 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.WorkItemLinksImpl.Add(new WorkItemLinkMock(WorkItemImplementationBase.ParentRelationship, parent.Id, repository)); repository.SetWorkItems(new[] { parent, child }); return(repository); }
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 Should_aggregate_to_parent_should_handle_null() { 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"] = null; grandParent["Test Estimate"] = null; 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"] = null; 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>(); context.GetProjectCollectionUri().Returns( new System.Uri("http://localhost:8080/tfs/DefaultCollection")); var runtime = RuntimeContext.MakeRuntimeContext("settingsPath", settings, context, logger, (c, i, l) => alternateRepository); using (var processor = new EventProcessor(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(2.0D, parent["Total Work Remaining"]); Assert.AreEqual(30.0D, parent["Total Estimate"]); 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 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 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(repository, logger, Debugger.IsAttached); engine.LoadAndRun("test", script, workItem); 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 Can_run_a_Powershell_script_returning_a_value() { string script = @" return $self.Id "; var logger = Substitute.For <ILogEvents>(); 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 = 1; repository.SetWorkItems(new[] { workItem }); 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 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 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 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_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 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 Can_run_a_Powershell_script_interacting_with_an_object_model() { string script = @" $self.Fields[""x""].Value = 33 return $self.Fields[""z""].Value "; var logger = Substitute.For <ILogEvents>(); 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); workItem.Fields["z"].Value = 42; workItem.Fields["x"].Value = 0; workItem.Id = 1; repository.SetWorkItems(new[] { workItem }); Assert.IsNotNull(repository.GetWorkItem(1)); var library = Substitute.For <IScriptLibrary>(); var engine = new PsScriptEngine(logger, Debugger.IsAttached, library); // 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 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 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); } }
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_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 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(repository, logger, Debugger.IsAttached); // sanity check Assert.AreEqual(42, workItem.Fields["z"].Value); engine.LoadAndRun("test", script, workItem); 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)))); }
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); }
private static WorkItemRepositoryMock MakeRepository(out IWorkItem startPoint) { var logger = Substitute.For <ILogEvents>(); 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 grandParent = new WorkItemMock(repository, runtime); grandParent.Id = 1; grandParent.TypeName = "Requirement"; grandParent["Microsoft.VSTS.Scheduling.RemainingWork"] = 2.0; var parent = new WorkItemMock(repository, runtime); parent.Id = 2; parent.TypeName = "Use Case"; var firstChild = new WorkItemMock(repository, runtime); firstChild.Id = 3; firstChild.TypeName = "Task"; var secondChild = new WorkItemMock(repository, runtime); secondChild.Id = 4; secondChild.TypeName = "Task"; var tc1 = new WorkItemMock(repository, runtime); tc1.Id = 21; tc1.TypeName = "Test Case"; tc1["Microsoft.VSTS.Scheduling.RemainingWork"] = 10.0; var tc2 = new WorkItemMock(repository, runtime); tc2.Id = 22; tc2.TypeName = "Test Case"; tc2["Microsoft.VSTS.Scheduling.RemainingWork"] = 30.0; 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)); // Tested By grandParent.WorkItemLinks.Add(new WorkItemLinkMock("Microsoft.VSTS.Common.TestedBy-Forward", tc1.Id, repository)); // Tests tc1.WorkItemLinks.Add(new WorkItemLinkMock("Microsoft.VSTS.Common.TestedBy-Reverse", grandParent.Id, repository)); // Tested By grandParent.WorkItemLinks.Add(new WorkItemLinkMock("Microsoft.VSTS.Common.TestedBy-Forward", tc2.Id, repository)); // Tests tc2.WorkItemLinks.Add(new WorkItemLinkMock("Microsoft.VSTS.Common.TestedBy-Reverse", grandParent.Id, repository)); repository.SetWorkItems(new[] { grandParent, parent, firstChild, secondChild, tc1, tc2 }); startPoint = grandParent; return(repository); }