示例#1
0
        public void TestMessageHandler()
        {
            IDeviceManager mgr;

            using (mgr = Factory.CreateDeviceManager())
            {
                mgr.RefCount.Should().Be(1);
                mgr.IsDisposed.Should().BeFalse();
                mgr.MessageHandler.Should().BeNull();
                using (var handler = new DummyHandler())
                {
                    //
                    // Attaching...
                    //

                    mgr.MessageHandler = handler;
                    mgr.MessageHandler.Should().BeSameAs(handler);

                    handler.IsInstalled.Should().BeTrue();
                    handler.Impl.Should().NotBeNull();


                    //
                    // Attaching again
                    //

                    var impl = handler.Impl;
                    mgr.MessageHandler = handler;
                    mgr.MessageHandler.Should().BeSameAs(handler);
                    handler.Impl.Should().BeSameAs(impl);                     //< one to one relationship must be preserved

                    //
                    // Removing via method
                    //
                    handler.RemoveHandlerFromDevices();
                    handler.IsInstalled.Should().BeFalse();
                    handler.Impl.Should().BeNull();
                    mgr.MessageHandler.Should().BeNull();


                    //
                    // Removing via property
                    //

                    mgr.MessageHandler = handler;
                    handler.IsInstalled.Should().BeTrue();
                    handler.Impl.Should().NotBeNull();
                    impl = handler.Impl;

                    mgr.MessageHandler = null;
                    mgr.MessageHandler.Should().BeNull();
                    handler.IsInstalled.Should().BeFalse();
                    handler.Impl.Should().BeSameAs(impl);                     //< The thing is that the filter might be installed elsewhere: the impl can only be disposed of when the handler is removed from *all* devices or disposed of itself
                }

                // TOOD: Test throwing exceptions, filtering
            }
            mgr.RefCount.Should().Be(0);
            mgr.IsDisposed.Should().BeTrue();
        }
示例#2
0
		public void TestMessageHandler()
		{
			IDeviceManager mgr;
			using (mgr = Factory.CreateDeviceManager())
			{
				mgr.RefCount.Should().Be(1);
				mgr.IsDisposed.Should().BeFalse();
				mgr.MessageHandler.Should().BeNull();
				using (var handler = new DummyHandler())
				{
					//
					// Attaching...
					//

					mgr.MessageHandler = handler;
					mgr.MessageHandler.Should().BeSameAs(handler);

					handler.IsInstalled.Should().BeTrue();
					handler.Impl.Should().NotBeNull();


					//
					// Attaching again
					//

					var impl = handler.Impl;
					mgr.MessageHandler = handler;
					mgr.MessageHandler.Should().BeSameAs(handler);
					handler.Impl.Should().BeSameAs(impl); //< one to one relationship must be preserved

					//
					// Removing via method
					//
					handler.RemoveHandlerFromDevices();
					handler.IsInstalled.Should().BeFalse();
					handler.Impl.Should().BeNull();
					mgr.MessageHandler.Should().BeNull();


					//
					// Removing via property
					//

					mgr.MessageHandler = handler;
					handler.IsInstalled.Should().BeTrue();
					handler.Impl.Should().NotBeNull();
					impl = handler.Impl;

					mgr.MessageHandler = null;
					mgr.MessageHandler.Should().BeNull();
					handler.IsInstalled.Should().BeFalse();
					handler.Impl.Should().BeSameAs(impl); //< The thing is that the filter might be installed elsewhere: the impl can only be disposed of when the handler is removed from *all* devices or disposed of itself
				}

				// TOOD: Test throwing exceptions, filtering
			}
			mgr.RefCount.Should().Be(0);
			mgr.IsDisposed.Should().BeTrue();
		}