-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathRabbitMQOptionsTests.cs
101 lines (89 loc) · 3.64 KB
/
RabbitMQOptionsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.WebJobs.Extensions.RabbitMQ;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
namespace WebJobs.Extensions.RabbitMQ.Tests
{
public class RabbitMQOptionsTests
{
private string GetFormattedOption(RabbitMQOptions option)
{
JObject options = new JObject
{
{ nameof(option.HostName), option.HostName },
{ nameof(option.QueueName), option.QueueName },
{ nameof(option.Port), option.Port },
{ nameof(option.PrefetchCount), option.PrefetchCount },
};
return options.ToString(Formatting.Indented);
}
[Fact]
public void TestDefaultOptions()
{
RabbitMQOptions options = new RabbitMQOptions();
Assert.Equal<ushort>(30, options.PrefetchCount);
Assert.Equal(0, options.Port);
Assert.Null(options.HostName);
Assert.Null(options.QueueName);
Assert.Null(options.UserName);
Assert.Null(options.Password);
Assert.Null(options.ConnectionString);
// Test formatted
Assert.Equal(GetFormattedOption(options), options.Format());
}
[Fact]
public void TestConfiguredRabbitMQOptions()
{
ushort expectedPrefetchCount = 100;
int expectedPort = 8080;
string expectedHostName = "someHostName";
string expectedQueueName = "someQueueName";
string expectedUserName = "someUserName";
string expectedPassword = "somePassword";
string expectedConnectionString = "someConnectionString";
RabbitMQOptions options = new RabbitMQOptions()
{
Port = expectedPort,
HostName = expectedHostName,
QueueName = expectedQueueName,
UserName = expectedUserName,
Password = expectedPassword,
ConnectionString = expectedConnectionString,
PrefetchCount = expectedPrefetchCount,
};
Assert.Equal(expectedPrefetchCount, options.PrefetchCount);
Assert.Equal(expectedPort, options.Port);
Assert.Equal(expectedHostName, options.HostName);
Assert.Equal(expectedQueueName, options.QueueName);
Assert.Equal(expectedUserName, options.UserName);
Assert.Equal(expectedPassword, options.Password);
Assert.Equal(expectedConnectionString, options.ConnectionString);
// Test formatted
Assert.Equal(GetFormattedOption(options), options.Format());
}
[Fact]
public void TestJobHostHasTheRightConfiguration()
{
ushort expectedPrefetchCount = 10;
var builder = new HostBuilder()
.UseEnvironment("Development")
.ConfigureWebJobs(webJobsBuilder =>
{
webJobsBuilder
.AddRabbitMQ(a => a.PrefetchCount = expectedPrefetchCount); // set to non-default prefetch count
})
.UseConsoleLifetime();
var host = builder.Build();
using (host)
{
var config = host.Services.GetService<IOptions<RabbitMQOptions>>();
Assert.Equal(config.Value.PrefetchCount, expectedPrefetchCount);
}
}
}
}