protected AmqpNmsObjectMessageFacade CreateReceivedObjectMessageFacade(global::Amqp.Message message) { AmqpNmsObjectMessageFacade facade = new AmqpNmsObjectMessageFacade(); facade.Initialize(CreateMockConsumer(), message); return(facade); }
protected AmqpNmsObjectMessageFacade CreateNewObjectMessageFacade(bool amqpTyped = false) { AmqpNmsObjectMessageFacade facade = new AmqpNmsObjectMessageFacade(); facade.Initialize(CreateMockAmqpConnection(amqpTyped)); return(facade); }
private AmqpNmsMessageFacade CreateMessageFacadeFromTypeId(sbyte msgType) { AmqpNmsMessageFacade message; switch (msgType) { case MessageSupport.JMS_TYPE_MSG: message = new AmqpNmsMessageFacade(); break; case MessageSupport.JMS_TYPE_BYTE: message = new AmqpNmsBytesMessageFacade(); break; case MessageSupport.JMS_TYPE_TXT: message = new AmqpNmsTextMessageFacade(); break; case MessageSupport.JMS_TYPE_OBJ: message = new AmqpNmsObjectMessageFacade(); break; case MessageSupport.JMS_TYPE_STRM: message = new AmqpNmsStreamMessageFacade(); break; case MessageSupport.JMS_TYPE_MAP: message = new AmqpNmsMapMessageFacade(); break; default: throw new ArgumentOutOfRangeException(nameof(msgType)); } message.Initialize(CreateMockAmqpConnection()); return message; }
public void TestNewMessageToSendDoesNotContainMessageTypeAnnotation() { AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(false); Assert.Null(amqpObjectMessageFacade.MessageAnnotations); Assert.AreEqual(MessageSupport.JMS_TYPE_OBJ, amqpObjectMessageFacade.JmsMsgType); }
public void TestNewMessageToSendDoesNotContainMessageTypeAnnotation() { AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(false); Assert.Null(amqpObjectMessageFacade.MessageAnnotations); Assert.IsNull(amqpObjectMessageFacade.JmsMsgType); }
public void TestMessageCopy() { String content = "myStringContent"; AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(); amqpObjectMessageFacade.Body = content; AmqpNmsObjectMessageFacade copy = amqpObjectMessageFacade.Copy() as AmqpNmsObjectMessageFacade; Assert.IsNotNull(copy); Assert.AreEqual(amqpObjectMessageFacade.Body, copy.Body); }
private void AssertDecodeObjectMessage(global::Amqp.Message message, bool setDotnetSerializedContentType) { NmsMessage nmsMessage = AmqpCodec.DecodeMessage(CreateMockConsumer(), message).AsMessage(); Assert.NotNull(nmsMessage); Assert.IsInstanceOf<NmsObjectMessage>(nmsMessage); AmqpNmsObjectMessageFacade facade = nmsMessage.Facade as AmqpNmsObjectMessageFacade; Assert.NotNull(facade); if (setDotnetSerializedContentType) Assert.IsInstanceOf<AmqpSerializedObjectDelegate>(facade.Delegate); else Assert.IsInstanceOf<AmqpTypedObjectDelegate>(facade.Delegate); }
public void TestSetObjectOnNewAmqpTypedMessage() { String content = "myStringContent"; AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(true); amqpObjectMessageFacade.Body = content; // retrieve the body from the underlying message, check it matches expectation RestrictedDescribed section = amqpObjectMessageFacade.Message.BodySection; Assert.NotNull(section); Assert.IsInstanceOf <AmqpValue>(section); Assert.AreEqual(content, ((AmqpValue)section).Value); }
public void TestCreateObjectMessageSerializable() { AmqpMessageFactory factory = new AmqpMessageFactory(CreateMockAmqpConnection()); NmsObjectMessage message = factory.CreateObjectMessage(new SerializableClass()); INmsMessageFacade facade = message.Facade; Assert.IsInstanceOf <NmsObjectMessage>(message); Assert.IsInstanceOf <AmqpNmsObjectMessageFacade>(facade); Assert.IsNull(facade.JmsMsgType); AmqpNmsObjectMessageFacade objectMessageFacade = (AmqpNmsObjectMessageFacade)facade; Assert.IsNotNull(objectMessageFacade.Body); Assert.IsInstanceOf <SerializableClass>(objectMessageFacade.Body); }
private void DoGetObjectUsingReceivedMessageWithNoBodySectionReturnsNullTestImpl(bool amqpTyped) { global::Amqp.Message message = new global::Amqp.Message(); if (!amqpTyped) { message.Properties = new Properties { ContentType = MessageSupport.SERIALIZED_DOTNET_OBJECT_CONTENT_TYPE }; } AmqpNmsObjectMessageFacade facade = CreateReceivedObjectMessageFacade(message); Assert.Null(facade.Body, "Expected null object"); }
private void DoNewMessageToSendHasBodySectionRepresentingNull(bool amqpTyped) { AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(amqpTyped); amqpObjectMessageFacade.OnSend(TimeSpan.Zero); Assert.NotNull(amqpObjectMessageFacade.Message.BodySection, "Message body should be presents"); if (amqpTyped) { Assert.AreSame(AmqpTypedObjectDelegate.NULL_OBJECT_BODY, amqpObjectMessageFacade.Message.BodySection, "Expected existing body section to be replaced"); } else { Assert.AreSame(AmqpSerializedObjectDelegate.NULL_OBJECT_BODY, amqpObjectMessageFacade.Message.BodySection, "Expected existing body section to be replaced"); } }
public void TestSetThenGetObjectOnSerializedReceivedMessageNoContentTypeReturnsSnapshot() { Dictionary <string, string> origMap = new Dictionary <string, string> { { "key1", "value1" } }; global::Amqp.Message message = new global::Amqp.Message() { Properties = new Properties { ContentType = MessageSupport.SERIALIZED_DOTNET_OBJECT_CONTENT_TYPE }, BodySection = new Data { Binary = GetSerializedBytes(origMap) } }; AmqpNmsObjectMessageFacade facade = CreateReceivedObjectMessageFacade(message); // verify we get a different-but-equal object back object body = facade.Body; Assert.IsInstanceOf <Dictionary <string, string> >(body); Dictionary <string, string> returnedObject1 = (Dictionary <string, string>)body; Assert.AreNotSame(origMap, returnedObject1, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(origMap, returnedObject1, "Expected equal objects, due to snapshot being taken"); // verify we get a different-but-equal object back when compared to the previously retrieved object object body2 = facade.Body; Assert.IsInstanceOf <Dictionary <string, string> >(body2); Dictionary <string, string> returnedObject2 = (Dictionary <string, string>)body2; Assert.AreNotSame(origMap, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(returnedObject1, returnedObject2); // mutate the original object origMap.Add("key2", "value2"); // verify the mutated map is a different and not equal object Assert.AreNotSame(returnedObject1, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreNotEqual(origMap, returnedObject2, "Expected objects to differ, due to snapshot being taken"); }
public void TestSetObjectOnNewMessage() { String content = "myStringContent"; AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(); amqpObjectMessageFacade.Body = content; var bytes = GetSerializedBytes(content); // retrieve the bytes from the underlying message, check they match expectation RestrictedDescribed messageBodySection = amqpObjectMessageFacade.Message.BodySection; Assert.NotNull(messageBodySection); Assert.IsInstanceOf <Data>(messageBodySection); CollectionAssert.AreEqual(bytes, ((Data)messageBodySection).Binary, "Underlying message data section did not contain the expected bytes"); }
public void TestGetObjectUsingReceivedMessageWithDataSectionContainingNothingReturnsNull() { global::Amqp.Message message = new global::Amqp.Message { Properties = new Properties { ContentType = MessageSupport.SERIALIZED_DOTNET_OBJECT_CONTENT_TYPE }, BodySection = new AmqpValue { Value = "nonBinarySectionContent" } }; AmqpNmsObjectMessageFacade facade = CreateReceivedObjectMessageFacade(message); Assert.Catch <IllegalStateException>(() => { object body = facade.Body; }); }
public void TestSetThenGetObjectOnSerializedReceivedMessageReturnsSnapshot() { Map origMap = new Map { { "key1", "value1" } }; global::Amqp.Message message = new global::Amqp.Message { BodySection = new AmqpValue { Value = origMap } }; AmqpNmsObjectMessageFacade facade = CreateReceivedObjectMessageFacade(message); // verify we get a different-but-equal object back object body = facade.Body; Assert.IsInstanceOf <Map>(body); Map returnedObject1 = (Map)body; Assert.AreNotSame(origMap, returnedObject1, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(origMap, returnedObject1, "Expected equal objects, due to snapshot being taken"); // verify we get a different-but-equal object back when compared to the previously retrieved object object body2 = facade.Body; Assert.IsInstanceOf <Map>(body2); Map returnedObject2 = (Map)body2; Assert.AreNotSame(origMap, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(returnedObject1, returnedObject2); // mutate the original object origMap.Add("key2", "value2"); // verify the mutated map is a different and not equal object Assert.AreNotSame(returnedObject1, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreNotEqual(origMap, returnedObject2, "Expected objects to differ, due to snapshot being taken"); }
public void TestSetObjectWithNullClearsExistingBodySection() { global::Amqp.Message message = new global::Amqp.Message { Properties = new Properties { ContentType = MessageSupport.SERIALIZED_DOTNET_OBJECT_CONTENT_TYPE }, BodySection = new Data { Binary = new byte[0] } }; AmqpNmsObjectMessageFacade facade = CreateReceivedObjectMessageFacade(message); Assert.NotNull(facade.Message.BodySection, "Expected existing body section to be found"); facade.Body = null; Assert.AreSame(AmqpSerializedObjectDelegate.NULL_OBJECT_BODY, facade.Message.BodySection, "Expected existing body section to be replaced"); Assert.Null(facade.Body); }
public void TestSetThenGetObjectOnSerializedMessageReturnsSnapshot() { Dictionary <string, string> origMap = new Dictionary <string, string> { { "key1", "value1" } }; AmqpNmsObjectMessageFacade facade = CreateNewObjectMessageFacade(false); facade.Body = origMap; Dictionary <string, string> d = new Dictionary <string, string>(); // verify we get a different-but-equal object back object body = facade.Body; Assert.IsInstanceOf <Dictionary <string, string> >(body); Dictionary <string, string> returnedObject1 = (Dictionary <string, string>)body; Assert.AreNotSame(origMap, returnedObject1, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(origMap, returnedObject1, "Expected equal objects, due to snapshot being taken"); // mutate the original object origMap.Add("key2", "value2"); // verify we get a different-but-equal object back when compared to the previously retrieved object object body2 = facade.Body; Assert.IsInstanceOf <Dictionary <string, string> >(body2); Dictionary <string, string> returnedObject2 = (Dictionary <string, string>)body2; Assert.AreNotSame(origMap, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreEqual(returnedObject1, returnedObject2); // verify the mutated map is a different and not equal object Assert.AreNotSame(returnedObject1, returnedObject2, "Expected different objects, due to snapshot being taken"); Assert.AreNotEqual(origMap, returnedObject2, "Expected objects to differ, due to snapshot being taken"); }
private void DoNewMessageToSendReturnsNullObjectTestImpl(bool amqpTyped) { AmqpNmsObjectMessageFacade amqpObjectMessageFacade = CreateNewObjectMessageFacade(amqpTyped); Assert.Null(amqpObjectMessageFacade.Body); }