コード例 #1
0
        public void GetTaskScheduler_Should_Return_SynchronizationContext_Compatible_With_Proxy_Thread_SynchronizationContextFactory_Context()
        {
            //arrange
            var UIMessageLoop = new WPFThreadingHelper();

            UIMessageLoop.Start().Wait();

            var scf = UIMessageLoop.Dispatcher.Invoke(() => new SynchronizationContextFactory());

            _Proxified = new DummyClass();
            _Interface = scf.Build <IDummyInterface2>(_Proxified);

            //act
            var res  = _ActorContext.GetTaskScheduler(_Proxified);
            var uisc = UIMessageLoop.Dispatcher.Invoke(() => SynchronizationContext.Current);


            //assert
            res.Should().NotBeNull();
            res.Should().BeOfType <SynchronizationContextTaskScheduler>();
            var ressync = res as SynchronizationContextTaskScheduler;

            ressync.SynchronizationContext.Should().BeOfType(uisc.GetType());

            UIMessageLoop.Stop();
        }
コード例 #2
0
 public ActorContextTest()
 {
     _ActorContext = new ActorContext();
     var factory = new ActorFactory();
     _Proxified = new DummyClass();
     _Interface = factory.Build<IDummyInterface2>(_Proxified);
 }
コード例 #3
0
        public ActorContextTest()
        {
            _ActorContext = new ActorContext();
            var factory = new ActorFactory();

            _Proxified = new DummyClass();
            _Interface = factory.Build <IDummyInterface2>(_Proxified);
        }
コード例 #4
0
        public async Task BuildAsync_Should_Call_Constructor_On_Actor_Thread()
        {
            var              current = Thread.CurrentThread;
            DummyClass       target  = null;
            IDummyInterface2 intface = await _Factory.BuildAsync <IDummyInterface2>(() => { target = new DummyClass(); return(target); });

            await intface.DoAsync();

            target.Done.Should().BeTrue();
            target.CallingConstructorThread.Should().NotBe(current);
            target.CallingConstructorThread.Should().Be(target.CallingThread);
        }
コード例 #5
0
        public async Task DisposeAsync_On_Factory_Should_Kill_Thread()
        {
            //arrange
            var target1 = new DummyClass();

            _Actor1 = _Factory.Build <IDummyInterface2>(target1);

            //act
            await _Actor1.DoAsync();

            //assert
            await _Factory.DisposeAsync();

            Thread.Yield();
            target1.CallingThread.IsAlive.Should().BeFalse();
        }
コード例 #6
0
        public async Task All_Actors_Should_Run_On_Same_Thread()
        {
            //arrange
            var target1 = new DummyClass();
            var target2 = new DummyClass();

            _Actor1 = _Factory.Build <IDummyInterface2>(target1);
            _Actor2 = _Factory.Build <IDummyInterface2>(target2);

            //act
            await _Actor1.DoAsync();

            await _Actor2.DoAsync();

            //assert
            target1.CallingThread.Should().Be(target2.CallingThread);
        }
コード例 #7
0
        public async Task TaskFactory_Should_Return_TaskFactory_Compatible_With_Proxy_Thread_SynchronizationContextFactory_Context()
        {
            //arrange
            var UIMessageLoop = new WPFThreadingHelper();
            UIMessageLoop.Start().Wait();

            var scf = UIMessageLoop.Dispatcher.Invoke(() => new SynchronizationContextFactory());

            _Proxified = new DummyClass();
            _Interface = scf.Build<IDummyInterface2>(_Proxified);

            //act
            var res = _ActorContext.GetTaskFactory(_Proxified);
            Thread tfthread = await res.StartNew(() => Thread.CurrentThread);

            //assert
            tfthread.Should().Be(UIMessageLoop.UIThread);

            UIMessageLoop.Stop();
        }
コード例 #8
0
        public async Task TaskFactory_Should_Return_TaskFactory_Compatible_With_Proxy_Thread_SynchronizationContextFactory_Context()
        {
            //arrange
            var UIMessageLoop = new WPFThreadingHelper();

            UIMessageLoop.Start().Wait();

            var scf = UIMessageLoop.Dispatcher.Invoke(() => new SynchronizationContextFactory());

            _Proxified = new DummyClass();
            _Interface = scf.Build <IDummyInterface2>(_Proxified);

            //act
            var    res      = _ActorContext.GetTaskFactory(_Proxified);
            Thread tfthread = await res.StartNew(() => Thread.CurrentThread);

            //assert
            tfthread.Should().Be(UIMessageLoop.UIThread);

            UIMessageLoop.Stop();
        }
コード例 #9
0
        public void GetTaskScheduler_Should_Return_SynchronizationContext_Compatible_With_Proxy_Thread_SynchronizationContextFactory_Context()
        {
            //arrange
            var UIMessageLoop = new WPFThreadingHelper();
            UIMessageLoop.Start().Wait();

            var scf = UIMessageLoop.Dispatcher.Invoke(() => new SynchronizationContextFactory());

            _Proxified = new DummyClass();
            _Interface = scf.Build<IDummyInterface2>(_Proxified);

            //act
            var res = _ActorContext.GetTaskScheduler(_Proxified);
            var uisc = UIMessageLoop.Dispatcher.Invoke(()=>  SynchronizationContext.Current);
         

            //assert
            res.Should().NotBeNull();
            res.Should().BeOfType<SynchronizationContextTaskScheduler>();
            var ressync = res as SynchronizationContextTaskScheduler;
            ressync.SynchronizationContext.Should().BeOfType(uisc.GetType());

            UIMessageLoop.Stop();
        }
コード例 #10
0
 private void Start(IDummyInterface2 dummy)
 {
     Thread.Sleep(400);
     dummy.SlowDoAsync().Wait();
 }
コード例 #11
0
 private void Start(IDummyInterface2 dummy)
 {
     Thread.Sleep(400);
     dummy.SlowDoAsync().Wait();
 }