Exemplo n.º 1
0
        public void ToMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Callback <Type>(t => Assert.IsTrue(typeof(int).Equals(t)))
                .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 data = new NotificationRaisedData
            {
                Id                 = new MessageId(),
                InResponseTo       = new MessageId(),
                Sender             = new EndpointId("a"),
                NotificationId     = NotificationIdExtensions.Serialize(id),
                EventArgumentsType = new SerializedType
                {
                    FullName     = typeof(int).FullName,
                    AssemblyName = typeof(int).Assembly.GetName().Name,
                },
                EventArguments = new EventArgs(),
            };
            var msg = translator.ToMessage(data);

            Assert.IsInstanceOf(typeof(NotificationRaisedMessage), msg);
            Assert.AreSame(data.Id, msg.Id);
            Assert.AreSame(data.Sender, msg.Sender);
            Assert.AreEqual(id, ((NotificationRaisedMessage)msg).Notification.Notification);
            Assert.AreSame(data.EventArguments, ((NotificationRaisedMessage)msg).Notification.EventArgs);
        }
Exemplo n.º 2
0
        public void ToMessageWithNonMatchingDataType()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            var translator  = new NotificationRaisedConverter(serializers.Object);

            var data = new SuccessData
            {
                Id           = new MessageId(),
                InResponseTo = new MessageId(),
                Sender       = new EndpointId("a"),
            };
            var msg = translator.ToMessage(data);

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