コード例 #1
0
        public void TestRegisterInvalidType()
        {
            Messenger.Reset();
            var recipient1 = new OldTestRecipient();

            Messenger.Default.Register(recipient1, typeof(OldMessengerTest));
        }
コード例 #2
0
        public void TestMultipleRecipients()
        {
            var messenger  = new Messenger();
            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();
            var recipient3 = new OldTestRecipient();

            messenger.Register(recipient1, typeof(OldTestMessage));
            messenger.Register(recipient2, typeof(OldTestMessage));
            messenger.Register(recipient3, typeof(OldTestMessage));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient3.Content);
            Assert.IsNull(recipient3.Sender);

            const string TestString = "Hello world";
            var          message    = new OldTestMessage(this, TestString);

            messenger.Broadcast(message);

            Assert.AreEqual(TestString, recipient1.Content);
            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(TestString, recipient2.Content);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(TestString, recipient3.Content);
            Assert.AreEqual(this, recipient3.Sender);
        }
コード例 #3
0
        public void TestMultipleRecipientsWithObjects()
        {
            var messenger  = new Messenger();
            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();
            var recipient3 = new OldTestRecipient();

            messenger.Register(recipient1, typeof(GenericMessage <InvalidOperationException>));
            messenger.Register(recipient2, typeof(GenericMessage <InvalidOperationException>));
            messenger.Register(recipient3, typeof(GenericMessage <InvalidOperationException>));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient3.Content);
            Assert.IsNull(recipient3.Sender);

            var testContent = new InvalidOperationException();
            var message     = new GenericMessage <InvalidOperationException>(this, testContent);

            messenger.Broadcast(message);

            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(testContent, recipient1.ObjectContent1);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(testContent, recipient2.ObjectContent1);
            Assert.AreEqual(this, recipient3.Sender);
            Assert.AreEqual(testContent, recipient3.ObjectContent1);
        }
コード例 #4
0
        public void TestUnregisterForOneType()
        {
            Messenger.Reset();

            const string TestString1 = "Hello world";
            const string TestString2 = "Another message";
            var          now         = DateTime.Now;
            var          later       = DateTime.Now + TimeSpan.FromDays(1);

            var recipient = new OldTestRecipient();

            Messenger.Default.Register(recipient, typeof(GenericMessage <string>), false);
            Messenger.Default.Register(recipient, typeof(CommandMessage <DateTime>), false);

            var recipient2 = new OldTestRecipient();

            Messenger.Default.Register(recipient2, typeof(GenericMessage <string>), false);
            Messenger.Default.Register(recipient2, typeof(CommandMessage <DateTime>), false);

            var message1 = new GenericMessage <string>(this, TestString1);

            Messenger.Default.Broadcast(message1);

            var message2 = new CommandMessage <DateTime>(this, now, OldTestCommandHost.SaveCommand);

            Messenger.Default.Broadcast(message2);

            Assert.AreEqual(TestString1, recipient.Content);
            Assert.AreEqual(TestString1, recipient2.Content);
            Assert.AreEqual(now, recipient.DateTimeContent);
            Assert.AreEqual(now, recipient2.DateTimeContent);

            Messenger.Default.Unregister(recipient, typeof(GenericMessage <string>));

            var message3 = new GenericMessage <string>(this, TestString2);

            Messenger.Default.Broadcast(message3);

            var message4 = new CommandMessage <DateTime>(this, later, OldTestCommandHost.SaveCommand);

            Messenger.Default.Broadcast(message4);

            Assert.AreEqual(TestString1, recipient.Content);
            Assert.AreEqual(TestString2, recipient2.Content);
            Assert.AreEqual(later, recipient.DateTimeContent);
            Assert.AreEqual(later, recipient2.DateTimeContent);
        }
コード例 #5
0
        public void TestPropertyChangedMessage()
        {
            Messenger.Reset();

            var recipient1 = new OldTestRecipient();

            Messenger.Default.Register(recipient1, typeof(PropertyChangedMessage <DateTime>));
            Assert.AreEqual(DateTime.MinValue, recipient1.DateTimeContent);

            var testVm = new OldTestViewModel();
            var now    = DateTime.Now;

            testVm.LastChanged2 = now;

            Assert.AreEqual(testVm, recipient1.Sender);
            Assert.AreEqual(now, recipient1.DateTimeContent);
        }
コード例 #6
0
        public void TestRegisterForSubclasses7()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses  = new OldTestRecipient();

            Messenger.Default.Register(recipientForSubclasses, typeof(GenericMessage <object>), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(GenericMessage <object>));

            var message = new GenericMessage <string>(this, "Test string");

            Messenger.Default.Broadcast(message);

            Assert.AreEqual(null, recipientForSubclasses.Sender);
            Assert.AreEqual(null, recipientForSubclasses.ObjectContent1);
            Assert.AreEqual(null, recipientNoSubclasses.Sender);
            Assert.AreEqual(null, recipientNoSubclasses.ObjectContent1);
        }
コード例 #7
0
        public void TestRegisterForSubclasses3()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses  = new OldTestRecipient();

            Messenger.Default.Register(recipientForSubclasses, typeof(MessageBase), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(MessageBase), true);

            var message = new MessageBase(this);

            Messenger.Default.Broadcast(message);

            Assert.AreEqual(this, recipientForSubclasses.Sender);
            Assert.AreEqual(message, recipientForSubclasses.Message);
            Assert.AreEqual(this, recipientNoSubclasses.Sender);
            Assert.AreEqual(message, recipientNoSubclasses.Message);
        }
コード例 #8
0
        public void TestRegisterForSubclasses4()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses  = new OldTestRecipient();

            Messenger.Default.Register(recipientForSubclasses, typeof(OldTestMessage), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(OldTestMessage));

            var ex1     = new InvalidOperationException();
            var message = new GenericMessage <InvalidOperationException>(this, ex1);

            Messenger.Default.Broadcast(message);

            Assert.AreEqual(null, recipientForSubclasses.Sender);
            Assert.AreEqual(null, recipientForSubclasses.ObjectContent1);
            Assert.AreEqual(null, recipientNoSubclasses.Sender);
            Assert.AreEqual(null, recipientNoSubclasses.ObjectContent1);
        }
コード例 #9
0
ファイル: ViewModelBaseTest.cs プロジェクト: ssickles/archive
        public void PropertyChangedTestBroadcast()
        {
            Messenger.Reset();
            _receivedDateTime = DateTime.MinValue;

            var recipient = new OldTestRecipient();
            Messenger.Default.Register(recipient, typeof(PropertyChangedMessage<DateTime>));

            var vm = new OldTestViewModel();
            vm.PropertyChanged += VMPropertyChanged;

            Assert.AreEqual(_receivedDateTime, DateTime.MinValue);

            var now = DateTime.Now;
            vm.LastChanged2 = now;
            Assert.AreEqual(now, vm.LastChanged2);
            Assert.AreEqual(_receivedDateTime, vm.LastChanged2);
            Assert.AreEqual(now, recipient.DateTimeContent);
        }
コード例 #10
0
        public void TestSendToTargetByType()
        {
            Messenger.Reset();

            const string TestString = "Hello world";

            var recipient = new OldTestRecipient();

            Messenger.Default.Register(recipient, typeof(GenericMessage <string>), false);

            var recipient2 = new OldTestRecipient2();

            Messenger.Default.Register(recipient2, typeof(GenericMessage <string>), false);

            var message = new GenericMessage <string>(this, recipient.GetType(), TestString);

            Messenger.Default.Broadcast(message);

            Assert.AreEqual(TestString, recipient.Content);
            Assert.IsNull(recipient2.Content);
        }
コード例 #11
0
        public void TestMultipleMessageTypes()
        {
            var messenger = new Messenger();
            var recipient = new OldTestRecipient();

            messenger.Register(recipient, typeof(OldTestMessage));
            messenger.Register(recipient, typeof(GenericMessage <InvalidOperationException>));
            messenger.Register(recipient, typeof(GenericMessage <MissingMethodException>));

            Assert.IsNull(recipient.Content);
            Assert.IsNull(recipient.ObjectContent1);
            Assert.IsNull(recipient.ObjectContent2);

            var testObject1    = new InvalidOperationException();
            var genericMessage = new GenericMessage <InvalidOperationException>(this, testObject1);

            messenger.Broadcast(genericMessage);
            Assert.AreEqual(this, recipient.Sender);
            Assert.IsNull(recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.IsNull(recipient.ObjectContent2);

            var testObject2     = new MissingMethodException();
            var genericMessage2 = new GenericMessage <MissingMethodException>(this, testObject2);

            messenger.Broadcast(genericMessage2);
            Assert.AreEqual(this, recipient.Sender);
            Assert.IsNull(recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.AreEqual(testObject2, recipient.ObjectContent2);

            const string TestString = "Hello world";
            var          message    = new OldTestMessage(this, TestString);

            messenger.Broadcast(message);
            Assert.AreEqual(this, recipient.Sender);
            Assert.AreEqual(TestString, recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.AreEqual(testObject2, recipient.ObjectContent2);
        }
コード例 #12
0
ファイル: ViewModelBaseTest.cs プロジェクト: ssickles/archive
        public void PropertyChangedTestBroadcastApplicationMessenger()
        {
            _receivedDateTime = DateTime.MinValue;

            var messenger = new Messenger();

            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();
            messenger.Register(recipient1, typeof(PropertyChangedMessage<DateTime>));
            Messenger.Default.Register(recipient2, typeof(PropertyChangedMessage<DateTime>));

            var vm = new OldTestViewModel(messenger);
            vm.PropertyChanged += VMPropertyChanged;

            Assert.AreEqual(_receivedDateTime, DateTime.MinValue);

            var now = DateTime.Now;
            vm.LastChanged2 = now;
            Assert.AreEqual(now, vm.LastChanged2);
            Assert.AreEqual(_receivedDateTime, vm.LastChanged2);
            Assert.AreEqual(now, recipient1.DateTimeContent);
            Assert.AreEqual(DateTime.MinValue, recipient2.DateTimeContent);
        }
コード例 #13
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestMultipleMessageTypes()
        {
            var messenger = new Messenger();
            var recipient = new OldTestRecipient();

            messenger.Register(recipient, typeof(OldTestMessage));
            messenger.Register(recipient, typeof(GenericMessage<InvalidOperationException>));
            messenger.Register(recipient, typeof(GenericMessage<MissingMethodException>));

            Assert.IsNull(recipient.Content);
            Assert.IsNull(recipient.ObjectContent1);
            Assert.IsNull(recipient.ObjectContent2);

            var testObject1 = new InvalidOperationException();
            var genericMessage = new GenericMessage<InvalidOperationException>(this, testObject1);
            messenger.Broadcast(genericMessage);
            Assert.AreEqual(this, recipient.Sender);
            Assert.IsNull(recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.IsNull(recipient.ObjectContent2);

            var testObject2 = new MissingMethodException();
            var genericMessage2 = new GenericMessage<MissingMethodException>(this, testObject2);
            messenger.Broadcast(genericMessage2);
            Assert.AreEqual(this, recipient.Sender);
            Assert.IsNull(recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.AreEqual(testObject2, recipient.ObjectContent2);

            const string TestString = "Hello world";
            var message = new OldTestMessage(this, TestString);
            messenger.Broadcast(message);
            Assert.AreEqual(this, recipient.Sender);
            Assert.AreEqual(TestString, recipient.Content);
            Assert.AreEqual(testObject1, recipient.ObjectContent1);
            Assert.AreEqual(testObject2, recipient.ObjectContent2);
        }
コード例 #14
0
        public void TestStaticMessenger()
        {
            Messenger.Reset();

            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();

            Messenger.Default.Register(recipient1, typeof(OldTestMessage));
            Messenger.Default.Register(recipient2, typeof(OldTestMessage));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);

            const string TestString = "Hello world";

            Messenger.Default.Broadcast(new OldTestMessage(this, TestString));

            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(TestString, recipient1.Content);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(TestString, recipient2.Content);
        }
コード例 #15
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestMultipleRecipients()
        {
            var messenger = new Messenger();
            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();
            var recipient3 = new OldTestRecipient();

            messenger.Register(recipient1, typeof(OldTestMessage));
            messenger.Register(recipient2, typeof(OldTestMessage));
            messenger.Register(recipient3, typeof(OldTestMessage));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient3.Content);
            Assert.IsNull(recipient3.Sender);

            const string TestString = "Hello world";
            var message = new OldTestMessage(this, TestString);
            messenger.Broadcast(message);

            Assert.AreEqual(TestString, recipient1.Content);
            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(TestString, recipient2.Content);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(TestString, recipient3.Content);
            Assert.AreEqual(this, recipient3.Sender);
        }
コード例 #16
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestUnregisterForOneType()
        {
            Messenger.Reset();

            const string TestString1 = "Hello world";
            const string TestString2 = "Another message";
            var now = DateTime.Now;
            var later = DateTime.Now + TimeSpan.FromDays(1);

            var recipient = new OldTestRecipient();
            Messenger.Default.Register(recipient, typeof(GenericMessage<string>), false);
            Messenger.Default.Register(recipient, typeof(CommandMessage<DateTime>), false);

            var recipient2 = new OldTestRecipient();
            Messenger.Default.Register(recipient2, typeof(GenericMessage<string>), false);
            Messenger.Default.Register(recipient2, typeof(CommandMessage<DateTime>), false);

            var message1 = new GenericMessage<string>(this, TestString1);
            Messenger.Default.Broadcast(message1);

            var message2 = new CommandMessage<DateTime>(this, now, OldTestCommandHost.SaveCommand);
            Messenger.Default.Broadcast(message2);

            Assert.AreEqual(TestString1, recipient.Content);
            Assert.AreEqual(TestString1, recipient2.Content);
            Assert.AreEqual(now, recipient.DateTimeContent);
            Assert.AreEqual(now, recipient2.DateTimeContent);

            Messenger.Default.Unregister(recipient, typeof(GenericMessage<string>));

            var message3 = new GenericMessage<string>(this, TestString2);
            Messenger.Default.Broadcast(message3);

            var message4 = new CommandMessage<DateTime>(this, later, OldTestCommandHost.SaveCommand);
            Messenger.Default.Broadcast(message4);

            Assert.AreEqual(TestString1, recipient.Content);
            Assert.AreEqual(TestString2, recipient2.Content);
            Assert.AreEqual(later, recipient.DateTimeContent);
            Assert.AreEqual(later, recipient2.DateTimeContent);
        }
コード例 #17
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestStaticMessenger()
        {
            Messenger.Reset();

            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();

            Messenger.Default.Register(recipient1, typeof(OldTestMessage));
            Messenger.Default.Register(recipient2, typeof(OldTestMessage));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);

            const string TestString = "Hello world";
            Messenger.Default.Broadcast(new OldTestMessage(this, TestString));

            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(TestString, recipient1.Content);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(TestString, recipient2.Content);
        }
コード例 #18
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestSendToTargetByType()
        {
            Messenger.Reset();

            const string TestString = "Hello world";

            var recipient = new OldTestRecipient();
            Messenger.Default.Register(recipient, typeof(GenericMessage<string>), false);

            var recipient2 = new OldTestRecipient2();
            Messenger.Default.Register(recipient2, typeof(GenericMessage<string>), false);

            var message = new GenericMessage<string>(this, recipient.GetType(), TestString);
            Messenger.Default.Broadcast(message);

            Assert.AreEqual(TestString, recipient.Content);
            Assert.IsNull(recipient2.Content);
        }
コード例 #19
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
 public void TestRegisterInvalidType()
 {
     Messenger.Reset();
     var recipient1 = new OldTestRecipient();
     Messenger.Default.Register(recipient1, typeof(OldMessengerTest));
 }
コード例 #20
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestRegisterForSubclasses7()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses = new OldTestRecipient();
            Messenger.Default.Register(recipientForSubclasses, typeof(GenericMessage<object>), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(GenericMessage<object>));

            var message = new GenericMessage<string>(this, "Test string");
            Messenger.Default.Broadcast(message);

            Assert.AreEqual(null, recipientForSubclasses.Sender);
            Assert.AreEqual(null, recipientForSubclasses.ObjectContent1);
            Assert.AreEqual(null, recipientNoSubclasses.Sender);
            Assert.AreEqual(null, recipientNoSubclasses.ObjectContent1);
        }
コード例 #21
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestRegisterForSubclasses4()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses = new OldTestRecipient();
            Messenger.Default.Register(recipientForSubclasses, typeof(OldTestMessage), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(OldTestMessage));

            var ex1 = new InvalidOperationException();
            var message = new GenericMessage<InvalidOperationException>(this, ex1);
            Messenger.Default.Broadcast(message);

            Assert.AreEqual(null, recipientForSubclasses.Sender);
            Assert.AreEqual(null, recipientForSubclasses.ObjectContent1);
            Assert.AreEqual(null, recipientNoSubclasses.Sender);
            Assert.AreEqual(null, recipientNoSubclasses.ObjectContent1);
        }
コード例 #22
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestRegisterForSubclasses3()
        {
            Messenger.Reset();
            var recipientForSubclasses = new OldTestRecipient();
            var recipientNoSubclasses = new OldTestRecipient();
            Messenger.Default.Register(recipientForSubclasses, typeof(MessageBase), true);
            Messenger.Default.Register(recipientNoSubclasses, typeof(MessageBase), true);

            var message = new MessageBase(this);
            Messenger.Default.Broadcast(message);

            Assert.AreEqual(this, recipientForSubclasses.Sender);
            Assert.AreEqual(message, recipientForSubclasses.Message);
            Assert.AreEqual(this, recipientNoSubclasses.Sender);
            Assert.AreEqual(message, recipientNoSubclasses.Message);
        }
コード例 #23
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestPropertyChangedMessage()
        {
            Messenger.Reset();

            var recipient1 = new OldTestRecipient();
            Messenger.Default.Register(recipient1, typeof(PropertyChangedMessage<DateTime>));
            Assert.AreEqual(DateTime.MinValue, recipient1.DateTimeContent);

            var testVm = new OldTestViewModel();
            var now = DateTime.Now;
            testVm.LastChanged2 = now;

            Assert.AreEqual(testVm, recipient1.Sender);
            Assert.AreEqual(now, recipient1.DateTimeContent);
        }
コード例 #24
0
ファイル: OldMessengerTest.cs プロジェクト: ssickles/archive
        public void TestMultipleRecipientsWithObjects()
        {
            var messenger = new Messenger();
            var recipient1 = new OldTestRecipient();
            var recipient2 = new OldTestRecipient();
            var recipient3 = new OldTestRecipient();

            messenger.Register(recipient1, typeof(GenericMessage<InvalidOperationException>));
            messenger.Register(recipient2, typeof(GenericMessage<InvalidOperationException>));
            messenger.Register(recipient3, typeof(GenericMessage<InvalidOperationException>));

            Assert.IsNull(recipient1.Sender);
            Assert.IsNull(recipient1.Content);
            Assert.IsNull(recipient2.Content);
            Assert.IsNull(recipient2.Sender);
            Assert.IsNull(recipient3.Content);
            Assert.IsNull(recipient3.Sender);

            var testContent = new InvalidOperationException();
            var message = new GenericMessage<InvalidOperationException>(this, testContent);
            messenger.Broadcast(message);

            Assert.AreEqual(this, recipient1.Sender);
            Assert.AreEqual(testContent, recipient1.ObjectContent1);
            Assert.AreEqual(this, recipient2.Sender);
            Assert.AreEqual(testContent, recipient2.ObjectContent1);
            Assert.AreEqual(this, recipient3.Sender);
            Assert.AreEqual(testContent, recipient3.ObjectContent1);
        }