Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 1074c02

Browse files
author
Anton Vorontsov
committed
Added assert for the integration test.
1 parent a59c51c commit 1074c02

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tests/RabbitMQ.Client.Core.DependencyInjection.Tests/IntegrationTests/QueueServiceTests.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
using System;
12
using System.Collections.Generic;
3+
using System.Threading;
24
using System.Threading.Tasks;
35
using Microsoft.Extensions.DependencyInjection;
46
using Moq;
57
using RabbitMQ.Client.Core.DependencyInjection.Configuration;
68
using RabbitMQ.Client.Core.DependencyInjection.Services;
79
using RabbitMQ.Client.Core.DependencyInjection.Tests.Stubs;
10+
using RabbitMQ.Client.Events;
811
using Xunit;
912

1013
namespace RabbitMQ.Client.Core.DependencyInjection.Tests.IntegrationTests
1114
{
1215
public class QueueServiceTests
1316
{
17+
readonly TimeSpan _globalTestsTimeout = TimeSpan.FromSeconds(60);
18+
1419
[Fact]
1520
public async Task ShouldProperlyPublishAndConsumeMessages()
1621
{
@@ -36,20 +41,41 @@ public async Task ShouldProperlyPublishAndConsumeMessages()
3641
}
3742
}
3843
};
39-
var serviceCollection = new ServiceCollection();
44+
45+
var connectionFactoryMock = new Mock<RabbitMqConnectionFactory> { CallBase = true }
46+
.As<IRabbitMqConnectionFactory>();
47+
48+
AsyncEventingBasicConsumer consumer = null;
49+
connectionFactoryMock.Setup(x => x.CreateConsumer(It.IsAny<IModel>()))
50+
.Returns<IModel>(channel =>
51+
{
52+
consumer = new AsyncEventingBasicConsumer(channel);
53+
return consumer;
54+
});
4055

4156
var callerMock = new Mock<IStubCaller>();
42-
serviceCollection.AddRabbitMqClient(clientOptions)
57+
58+
var serviceCollection = new ServiceCollection();
59+
serviceCollection
60+
.AddSingleton(connectionFactoryMock.Object)
61+
.AddSingleton(callerMock.Object)
62+
.AddRabbitMqClient(clientOptions)
4363
.AddConsumptionExchange("exchange.name", exchangeOptions)
44-
.AddMessageHandlerTransient<StubMessageHandler>("routing.key")
45-
.AddSingleton(callerMock.Object);
64+
.AddMessageHandlerTransient<StubMessageHandler>("routing.key");
4665

4766
var serviceProvider = serviceCollection.BuildServiceProvider();
48-
4967
var queueService = serviceProvider.GetRequiredService<IQueueService>();
5068
queueService.StartConsuming();
69+
70+
var resetEvent = new AutoResetEvent(false);
71+
consumer.Received += async (sender, @event) =>
72+
{
73+
resetEvent.Set();
74+
};
5175

5276
await queueService.SendAsync("message", "exchange.name", "routing.key");
77+
resetEvent.WaitOne(_globalTestsTimeout);
78+
callerMock.Verify(x => x.Call(It.IsAny<string>()), Times.Once);
5379
}
5480
}
5581
}

0 commit comments

Comments
 (0)