コード例 #1
0
        public void FromMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new NotificationRaisedConverter(serializers.Object);

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new NotificationRaisedMessage(
                new EndpointId("a"),
                new Interaction.NotificationRaisedData(id, new EventArgs()));
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationRaisedData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationRaisedData)data).NotificationId);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().FullName,
                ((NotificationRaisedData)data).EventArgumentsType.FullName);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().Assembly.GetName().Name,
                ((NotificationRaisedData)data).EventArgumentsType.AssemblyName);
            Assert.AreSame(msg.Notification.EventArgs, ((NotificationRaisedData)data).EventArguments);
        }
コード例 #2
0
        public void FromMessageWithNonMatchingMessageType()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            var translator  = new NotificationRaisedConverter(serializers.Object);

            var msg  = new SuccessMessage(new EndpointId("a"), new MessageId());
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(UnknownMessageTypeData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
        }