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 DataTypeToTranslate()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            var translator  = new NotificationRaisedConverter(serializers.Object);

            Assert.AreEqual(typeof(NotificationRaisedData), translator.DataTypeToTranslate);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }