Exemplo n.º 1
0
        public void Should_aggregate_to_parent()
        {
            var logger              = Substitute.For <ILogEvents>();
            var settings            = TestHelpers.LoadConfigFromResourceFile("Rollup.policies", logger);
            var alternateRepository = new WorkItemRepositoryMock();

            var context = Substitute.For <IRequestContext>();

            context.GetProjectCollectionUri().Returns(
                new System.Uri("http://*****:*****@"C:\Should_aggregate_to_parent", settings, context, logger, (c, i, r) => alternateRepository);

            var grandParent = new WorkItemMock(alternateRepository, runtime);

            grandParent.Id               = 1;
            grandParent.TypeName         = "Feature";
            grandParent["Dev Estimate"]  = 0.0D;
            grandParent["Test Estimate"] = 0.0D;

            var parent = new WorkItemMock(alternateRepository, runtime);

            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, runtime);

            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 });

            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(3.0D, parent["Total Work Remaining"]);
                Assert.AreEqual(30.0D, parent["Total Estimate"]);
                Assert.AreEqual(EventNotificationStatus.ActionPermitted, result.NotificationStatus);
            }
        }