public void Sequential_Send_Success()
        {
            var expectedSequence = new List <object>();
            var resultSequence   = new List <object>();

            using (var synchronizationContext = new ThreadSynchronizationContext(ApartmentState.MTA))
            {
                for (var i = 0; i < 5; i++)
                {
                    expectedSequence.Add(i);

                    void SendOrPostCallback(object state)
                    {
                        lock (resultSequence)
                        {
                            resultSequence.Add(state);
                        }
                    }

                    synchronizationContext.Send(SendOrPostCallback, i);
                }
            }

            CollectionAssert.AreEqual(expectedSequence, resultSequence);
        }
        public void Sequential_PostSendInsert_Success()
        {
            var expectedSequence = new List <object>();
            var resultSequence   = new List <object>();

            using (var synchronizationContext = new ThreadSynchronizationContext(ApartmentState.MTA))
            {
                for (var i = 0; i < 5; i++)
                {
                    expectedSequence.Add(i);

                    void SendOrPostCallback(object state)
                    {
                        lock (resultSequence)
                        {
                            resultSequence.Add(state);
                        }

                        Thread.Sleep(100);
                    }

                    synchronizationContext.Post(SendOrPostCallback, i);
                }

                var finishEvent = new ManualResetEvent(false);
                synchronizationContext.Post(state => finishEvent.Set(), null);

                synchronizationContext.Send(state => CollectionAssert.AreNotEqual(expectedSequence, resultSequence), null);

                finishEvent.WaitOne();
            }

            CollectionAssert.AreEqual(expectedSequence, resultSequence);
        }