Ejemplo n.º 1
0
        public void ShouldPassAfter2RepeatsAndTimeoutIsResetEachTime()
        {
            // Rather than testing with sleeps, this tests that the execution will occur in the correct
            // order by checking which commands are run when. As the repeat command comes first, the
            // timeout will be reset each time it runs
            var            test    = TestBuilder.MakeTestFromMethod(typeof(HelperMethodForTimeoutsClass), nameof(HelperMethodForTimeoutsClass.ShouldPassAfter2RepeatsAndTimeoutIsResetEachTime));
            SimpleWorkItem work    = TestBuilder.CreateWorkItem(test) as SimpleWorkItem;
            var            method  = typeof(SimpleWorkItem).GetMethod("MakeTestCommand", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            TestCommand    command = (TestCommand)method.Invoke(work, null);

            Assert.That(command, Is.TypeOf(typeof(RepeatAttribute.RepeatedTestCommand)));
            RepeatAttribute.RepeatedTestCommand repeatedCommand = (RepeatAttribute.RepeatedTestCommand)command;

            command = GetInnerCommand(repeatedCommand);

            Assert.That(command, Is.TypeOf(typeof(TimeoutCommand)));
            TimeoutCommand timeoutCommand = (TimeoutCommand)command;

            command = GetInnerCommand(timeoutCommand);

            Assert.That(command, Is.TypeOf(typeof(ApplyChangesToContextCommand)));
            ApplyChangesToContextCommand applyChangesToContextCommand = (ApplyChangesToContextCommand)command;

            command = GetInnerCommand(applyChangesToContextCommand);

            Assert.That(command, Is.TypeOf(typeof(TestMethodCommand)));
        }
Ejemplo n.º 2
0
        public async Task UnsafeQueueUserWorkItem_IThreadPoolWorkItem_SameObjectReused_AllInvoked(bool preferLocal)
        {
            const int Iters     = 100;
            int       remaining = Iters;
            var       tcs       = new TaskCompletionSource <bool>();
            var       workItem  = new SimpleWorkItem(() =>
            {
                if (Interlocked.Decrement(ref remaining) == 0)
                {
                    tcs.TrySetResult(true);
                }
            });

            for (int i = 0; i < Iters; i++)
            {
                ThreadPool.UnsafeQueueUserWorkItem(workItem, preferLocal);
            }
            await tcs.Task;

            Assert.Equal(0, remaining);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage CreateItem([FromUri] string requestedCollectionUri, [FromUri] string requestedProject, [FromBody] SimpleWorkItem requestedWorkItem)
        {
            Uri collectionUri                      = new Uri(requestedCollectionUri);
            TfsTeamProjectCollection tpc           = new TfsTeamProjectCollection(collectionUri, new NetworkCredential(username, password, domain));
            WorkItemStore            workItemStore = tpc.GetService <WorkItemStore>();
            Project      teamProject               = workItemStore.Projects[requestedProject];
            WorkItemType workItemType              = teamProject.WorkItemTypes[Utils.GetTFSType(requestedWorkItem.Type)];

            // Create the work item.
            WorkItem newWorkItem = new WorkItem(workItemType)
            {
                // The title is generally the only required field that doesn’t have a default value.
                // You must set it, or you can’t save the work item. If you’re working with another
                // type of work item, there may be other fields that you’ll have to set.
                Title         = requestedWorkItem.Title,
                AreaPath      = requestedWorkItem.AreaPath,
                State         = requestedWorkItem.State,
                IterationPath = requestedWorkItem.IterationPath,
            };
            RelatedLink parent = new RelatedLink(workItemStore.WorkItemLinkTypes.LinkTypeEnds[requestedWorkItem.LinkType], requestedWorkItem.LinkId);

            newWorkItem.Links.Add(parent);
            newWorkItem.Save();
            requestedWorkItem.id = newWorkItem.Id;
            return(Request.CreateResponse <SimpleWorkItem>(HttpStatusCode.OK, requestedWorkItem));
        }