public async Task ReceiveMessageTest() { // Arrange var deviceListener = new Mock <IDeviceListener>(); var connectionHandler = Mock.Of <IConnectionHandler>(c => c.GetDeviceListener() == Task.FromResult(deviceListener.Object) && c.GetAmqpAuthentication() == Task.FromResult(new AmqpAuthentication(true, Option.Some(Mock.Of <IClientCredentials>())))); var amqpConnection = Mock.Of <IAmqpConnection>(c => c.FindExtension <IConnectionHandler>() == connectionHandler); var amqpSession = Mock.Of <IAmqpSession>(s => s.Connection == amqpConnection); var receivingLink = Mock.Of <IReceivingAmqpLink>(l => l.Session == amqpSession && l.IsReceiver && l.Settings == new AmqpLinkSettings() && l.State == AmqpObjectState.Opened); var requestUri = new Uri("amqps://foo.bar/devices/d1"); var boundVariables = new Dictionary <string, string> { { "deviceid", "d1" } }; var messageConverter = new AmqpMessageConverter(); var body = new byte[] { 0, 1, 2, 3 }; AmqpMessage message = AmqpMessage.Create(new Data { Value = new ArraySegment <byte>(body) }); // Act var receivingLinkHandler = new TestReceivingLinkHandler(receivingLink, requestUri, boundVariables, messageConverter); await receivingLinkHandler.OpenAsync(Amqp.Constants.DefaultTimeout); await receivingLinkHandler.ProcessMessageAsync(message); // Assert await Task.Delay(TimeSpan.FromSeconds(3)); Assert.Equal(1, receivingLinkHandler.ReceivedMessages.Count); Assert.Equal(body, receivingLinkHandler.ReceivedMessages[0].GetPayloadBytes()); }
public async Task ReceiveMessageTest() { // Arrange var deviceListener = new Mock <IDeviceListener>(); var connectionHandler = Mock.Of <IConnectionHandler>(c => c.GetDeviceListener() == Task.FromResult(deviceListener.Object)); var amqpAuthenticator = new Mock <IAmqpAuthenticator>(); amqpAuthenticator.Setup(c => c.AuthenticateAsync("d1")).ReturnsAsync(true); Mock <ICbsNode> cbsNodeMock = amqpAuthenticator.As <ICbsNode>(); ICbsNode cbsNode = cbsNodeMock.Object; var amqpConnection = Mock.Of <IAmqpConnection>( c => c.FindExtension <IConnectionHandler>() == connectionHandler && c.FindExtension <ICbsNode>() == cbsNode); var amqpSession = Mock.Of <IAmqpSession>(s => s.Connection == amqpConnection); var receivingLink = Mock.Of <IReceivingAmqpLink>(l => l.Session == amqpSession && l.IsReceiver && l.Settings == new AmqpLinkSettings() && l.State == AmqpObjectState.Opened); var requestUri = new Uri("amqps://foo.bar/devices/d1"); var boundVariables = new Dictionary <string, string> { { "deviceid", "d1" } }; var messageConverter = new AmqpMessageConverter(); var body = new byte[] { 0, 1, 2, 3 }; AmqpMessage message = AmqpMessage.Create(new Data { Value = new ArraySegment <byte>(body) }); var identity = Mock.Of <IIdentity>(i => i.Id == "d1"); var productInfoStore = Mock.Of <IProductInfoStore>(); var modelIdStore = Mock.Of <IModelIdStore>(); // Act var receivingLinkHandler = new TestReceivingLinkHandler(identity, receivingLink, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore, modelIdStore); await receivingLinkHandler.OpenAsync(Constants.DefaultTimeout); await receivingLinkHandler.ProcessMessageAsync(message); // Assert await Task.Delay(TimeSpan.FromSeconds(3)); Assert.Equal(1, receivingLinkHandler.ReceivedMessages.Count); Assert.Equal(body, receivingLinkHandler.ReceivedMessages[0].GetPayloadBytes()); }