Exemplo n.º 1
0
    public void CreateCopy_ReturnsNewInstance()
    {
        var syncContext = new SingleThreadedSynchronizationContext();
        var other       = syncContext.CreateCopy();

        Assert.NotSame(syncContext, other);

        // Verify that posting to the copy effectively gets the work to run on the original thread.
        var frame            = new SingleThreadedSynchronizationContext.Frame();
        int?observedThreadId = null;

        Task.Run(() =>
        {
            other.Post(
                s =>
            {
                observedThreadId = Environment.CurrentManagedThreadId;
                frame.Continue   = false;
            },
                null);
        });

        syncContext.PushFrame(frame);
        Assert.Equal(Environment.CurrentManagedThreadId, observedThreadId.Value);
    }
Exemplo n.º 2
0
    public void CreateCopy_ReturnsInstanceOfCorrectType()
    {
        var syncContext = new SingleThreadedSynchronizationContext();

        Assert.IsType <SingleThreadedSynchronizationContext>(syncContext.CreateCopy());
    }