Skip to content

Commit

Permalink
Remove Name property from *Info records (#317)
Browse files Browse the repository at this point in the history
Remove Name porperty from *Info records
  • Loading branch information
inikulshin authored Feb 8, 2024
1 parent 445cdd1 commit a3ddad4
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 199 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ public void Execute(GeneratorExecutionContext context)
fileScopedNamespaceDeclaration = fileScopedNamespaceDeclaration
.AddReplacementExtensionsClass(extensionsClassName, t, thisParameter,
("string vhostName", null, "exchange.Vhost"),
("string exchangeName", "Exchange exchange", "exchange.Name")
("string exchangeName", "ExchangeName exchange", "exchange.Name")
);
fileScopedNamespaceDeclaration = fileScopedNamespaceDeclaration
.AddReplacementExtensionsClass(extensionsClassName, t, thisParameter,
("string vhostName", null, "queue.Vhost"),
("string queueName", "Queue queue", "queue.Name")
("string queueName", "QueueName queue", "queue.Name")
);
fileScopedNamespaceDeclaration = fileScopedNamespaceDeclaration
.AddReplacementExtensionsClass(extensionsClassName, t, thisParameter,
("string vhostName", null, "exchange.Vhost"),
("string exchangeName", "Exchange exchange", "exchange.Name"),
("string queueName", "Queue queue", "queue.Name")
("string exchangeName", "ExchangeName exchange", "exchange.Name"),
("string queueName", "QueueName queue", "queue.Name")
);
fileScopedNamespaceDeclaration = fileScopedNamespaceDeclaration
.AddReplacementExtensionsClass(extensionsClassName, t, thisParameter,
("string vhostName", null, "sourceExchange.Vhost"),
("string sourceExchangeName", "Exchange sourceExchange", "sourceExchange.Name"),
("string destinationExchangeName", "Exchange destinationExchange", "destinationExchange.Name")
("string sourceExchangeName", "ExchangeName sourceExchange", "sourceExchange.Name"),
("string destinationExchangeName", "ExchangeName destinationExchange", "destinationExchange.Name")
);
fileScopedNamespaceDeclaration = fileScopedNamespaceDeclaration
.AddReplacementExtensionsClass(extensionsClassName, t, thisParameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ManagementClientTests(RabbitMqFixture fixture, ITestOutputHelper output)

private async Task<Exchange> CreateExchange(string exchangeName)
{
await fixture.ManagementClient.CreateExchangeAsync(Vhost, new ExchangeInfo(exchangeName, "direct"));
await fixture.ManagementClient.CreateExchangeAsync(Vhost, exchangeName, new ExchangeInfo("direct"));
return await fixture.ManagementClient.GetExchangeAsync(Vhost, exchangeName);
}

Expand All @@ -46,8 +46,8 @@ private async Task<Queue> CreateTestQueue(string queueName)

private async Task<Queue> CreateTestQueueInVhost(string queueName, Vhost vhost)
{
var queueInfo = new QueueInfo(queueName);
await fixture.ManagementClient.CreateQueueAsync(vhost, queueInfo);
var queueInfo = new QueueInfo();
await fixture.ManagementClient.CreateQueueAsync(vhost, queueName, queueInfo);
return await fixture.ManagementClient.GetQueueAsync(vhost, queueName);
}

Expand All @@ -62,8 +62,8 @@ private async Task<Exchange> EnsureExchangeExists(string exchangeName)
[Fact]
public async Task Should_be_able_to_change_the_password_of_a_user()
{
var userInfo = UserInfo.ByPassword(TestUser, "topSecret").AddTag(UserTags.Monitoring).AddTag(UserTags.Management);
await fixture.ManagementClient.CreateUserAsync(userInfo);
var userInfo = UserInfo.ByPassword("topSecret").AddTag(UserTags.Monitoring).AddTag(UserTags.Management);
await fixture.ManagementClient.CreateUserAsync(TestUser, userInfo);

var user = await fixture.ManagementClient.GetUserAsync(TestUser);

Expand Down Expand Up @@ -98,7 +98,7 @@ public async Task Should_be_able_to_configure_request()
[Fact]
public async Task Should_be_able_to_create_a_queue()
{
await fixture.ManagementClient.CreateQueueAsync(Vhost, new QueueInfo(TestQueue));
await fixture.ManagementClient.CreateQueueAsync(Vhost, TestQueue, new QueueInfo());
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, TestQueue);

queue.Name.Should().Be(TestQueue);
Expand All @@ -109,20 +109,21 @@ public async Task Should_be_able_to_create_a_queue_with_arguments()
{
const string exchangeName = "test-dead-letter-exchange";
const string argumentKey = "x-dead-letter-exchange";
var queueInfo = new QueueInfo(Name: $"{TestQueue}1", Arguments: new Dictionary<string, object?> { { argumentKey, exchangeName } });
var queueName = $"{TestQueue}1";
var queueInfo = new QueueInfo(Arguments: new Dictionary<string, object?> { { argumentKey, exchangeName } });

await fixture.ManagementClient.CreateQueueAsync(Vhost, queueInfo);
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, queueInfo.Name);
await fixture.ManagementClient.CreateQueueAsync(Vhost, queueName, queueInfo);
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, queueName);
queue.Arguments[argumentKey].Should().NotBeNull();
queue.Arguments[argumentKey].Should().Be(exchangeName);
}

[Fact]
public async Task Should_be_able_to_create_a_queue_with_plus_char_in_the_name()
{
var queueInfo = new QueueInfo(TestQueueWithPlusChar);
var queueInfo = new QueueInfo();

await fixture.ManagementClient.CreateQueueAsync(Vhost, queueInfo);
await fixture.ManagementClient.CreateQueueAsync(Vhost, TestQueueWithPlusChar, queueInfo);
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, TestQueueWithPlusChar);

queue.Name.Should().Be(TestQueueWithPlusChar);
Expand Down Expand Up @@ -165,9 +166,9 @@ public async Task Should_be_able_to_rebalance_queues()
[Fact]
public async Task Should_be_able_to_create_a_user()
{
var userInfo = UserInfo.ByPassword(TestUser, "topSecret").AddTag(UserTags.Administrator);
var userInfo = UserInfo.ByPassword("topSecret").AddTag(UserTags.Administrator);

await fixture.ManagementClient.CreateUserAsync(userInfo);
await fixture.ManagementClient.CreateUserAsync(TestUser, userInfo);
var user = await fixture.ManagementClient.GetUserAsync(TestUser);

user.Name.Should().Be(TestUser);
Expand All @@ -181,9 +182,9 @@ public async Task Should_be_able_to_create_a_user_with_password_hash()
// Hash calculated using RabbitMq hash computing algorithm using Sha256
// See https://www.rabbitmq.com/passwords.html
var passwordHash = "Qlp9Dgrqvx1S1VkuYsoWwgUD2XW2gZLuqQwreE+PAsPZETgo"; //"topSecret"
var userInfo = UserInfo.ByPasswordHash(testUser, passwordHash).AddTag(UserTags.Administrator);
var userInfo = UserInfo.ByPasswordHash(passwordHash).AddTag(UserTags.Administrator);

await fixture.ManagementClient.CreateUserAsync(userInfo);
await fixture.ManagementClient.CreateUserAsync(testUser, userInfo);
var user = await fixture.ManagementClient.GetUserAsync(testUser);

user.Name.Should().Be(testUser);
Expand All @@ -192,9 +193,9 @@ public async Task Should_be_able_to_create_a_user_with_password_hash()
[Fact]
public async Task Should_be_able_to_create_a_user_with_the_policymaker_tag()
{
var userInfo = UserInfo.ByPassword(TestUser, "topSecret").AddTag(UserTags.Policymaker);
var userInfo = UserInfo.ByPassword("topSecret").AddTag(UserTags.Policymaker);

await fixture.ManagementClient.CreateUserAsync(userInfo);
await fixture.ManagementClient.CreateUserAsync(TestUser, userInfo);
var user = await fixture.ManagementClient.GetUserAsync(TestUser);

user.Name.Should().Be(TestUser);
Expand All @@ -204,9 +205,9 @@ public async Task Should_be_able_to_create_a_user_with_the_policymaker_tag()
public async Task Should_be_able_to_create_a_user_without_password()
{
var testUser = "empty";
var userInfo = UserInfo.ByPassword(testUser, "").AddTag(UserTags.Administrator);
var userInfo = UserInfo.ByPassword("").AddTag(UserTags.Administrator);

await fixture.ManagementClient.CreateUserAsync(userInfo);
await fixture.ManagementClient.CreateUserAsync(testUser, userInfo);
var user = await fixture.ManagementClient.GetUserAsync(testUser);

user.Name.Should().Be(testUser);
Expand Down Expand Up @@ -312,9 +313,9 @@ public async Task Should_be_able_to_create_an_exchange()
[Fact]
public async Task Should_be_able_to_create_an_exchange_with_plus_char_in_the_name()
{
var exchangeInfo = new ExchangeInfo(TestExchangeTestQueueWithPlusChar, "direct");
var exchangeInfo = new ExchangeInfo("direct");

await fixture.ManagementClient.CreateExchangeAsync(Vhost, exchangeInfo);
await fixture.ManagementClient.CreateExchangeAsync(Vhost, TestExchangeTestQueueWithPlusChar, exchangeInfo);
var exchange = await fixture.ManagementClient.GetExchangeAsync(Vhost, TestExchangeTestQueueWithPlusChar);

exchange.Name.Should().Be(TestExchangeTestQueueWithPlusChar);
Expand Down Expand Up @@ -573,8 +574,8 @@ public async Task Should_be_able_to_create_permissions()
if (vhost == null)
throw new EasyNetQTestException($"Test vhost: '{TestVHost}' has not been created");

var permissionInfo = new PermissionInfo(user.Name);
await fixture.ManagementClient.CreatePermissionAsync(vhost, permissionInfo);
var permissionInfo = new PermissionInfo();
await fixture.ManagementClient.CreatePermissionAsync(vhost, user, permissionInfo);
}

[Fact]
Expand All @@ -588,8 +589,8 @@ public async Task Should_be_able_to_create_permissions_in_default_Vhost()
if (vhost == null)
throw new EasyNetQTestException($"Default vhost: '{TestVHost}' has not been created");

var permissionInfo = new PermissionInfo(user.Name);
await fixture.ManagementClient.CreatePermissionAsync(vhost, permissionInfo);
var permissionInfo = new PermissionInfo();
await fixture.ManagementClient.CreatePermissionAsync(vhost, user, permissionInfo);
}

[Fact]
Expand Down Expand Up @@ -678,13 +679,13 @@ public async Task Should_be_able_to_delete_an_exchange_with_pluses()
[Fact]
public async Task Should_be_able_to_delete_permissions()
{
var userInfo = UserInfo.ByPassword(TestUser, "topSecret").AddTag(UserTags.Monitoring).AddTag(UserTags.Management);
await fixture.ManagementClient.CreateUserAsync(userInfo);
var userInfo = UserInfo.ByPassword("topSecret").AddTag(UserTags.Monitoring).AddTag(UserTags.Management);
await fixture.ManagementClient.CreateUserAsync(TestUser, userInfo);
var user = await fixture.ManagementClient.GetUserAsync(TestUser);
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
var permissionInfo = new PermissionInfo(user.Name);
await fixture.ManagementClient.CreatePermissionAsync(vhost, permissionInfo);
var permissionInfo = new PermissionInfo();
await fixture.ManagementClient.CreatePermissionAsync(vhost, user, permissionInfo);

var permission = (await fixture.ManagementClient.GetPermissionsAsync())
.SingleOrDefault(x => x.User == TestUser && x.Vhost == TestVHost);
Expand Down Expand Up @@ -816,8 +817,8 @@ public async Task Should_be_able_to_get_a_queue_by_name_with_plus_char()
[Fact]
public async Task Should_be_able_to_get_a_user_by_name()
{
var userInfo = UserInfo.ByPassword(TestUser, "topSecret");
await fixture.ManagementClient.CreateUserAsync(userInfo);
var userInfo = UserInfo.ByPassword("topSecret");
await fixture.ManagementClient.CreateUserAsync(TestUser, userInfo);
(await fixture.ManagementClient.GetUserAsync(TestUser)).Name.Should().Be(TestUser);
}

Expand Down Expand Up @@ -904,8 +905,8 @@ public async Task Should_check_that_the_broker_is_alive()
await fixture.ManagementClient.CreateVhostAsync(TestVHost);
var vhost = await fixture.ManagementClient.GetVhostAsync(TestVHost);
var user = (await fixture.ManagementClient.GetUsersAsync()).Single(x => x.Name == fixture.User);
var permissionInfo = new PermissionInfo(user.Name);
await fixture.ManagementClient.CreatePermissionAsync(vhost, permissionInfo);
var permissionInfo = new PermissionInfo();
await fixture.ManagementClient.CreatePermissionAsync(vhost, user, permissionInfo);
(await fixture.ManagementClient.IsAliveAsync(vhost)).Should().BeTrue();
}

Expand Down Expand Up @@ -935,14 +936,14 @@ public async Task Should_create_exchange_to_exchange_binding()
const string destinationExchangeName = "management_api_test_destination_exchange";

var vhost = await fixture.ManagementClient.GetVhostAsync(Vhost.Name);
var sourceExchangeInfo = new ExchangeInfo(sourceExchangeName, "direct");
var destinationExchangeInfo = new ExchangeInfo(destinationExchangeName, "direct");
var sourceExchangeInfo = new ExchangeInfo("direct");
var destinationExchangeInfo = new ExchangeInfo("direct");

await fixture.ManagementClient.CreateExchangeAsync(vhost, sourceExchangeInfo);
var sourceExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, sourceExchangeInfo.Name);
await fixture.ManagementClient.CreateExchangeAsync(vhost, sourceExchangeName, sourceExchangeInfo);
var sourceExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, sourceExchangeName);

await fixture.ManagementClient.CreateExchangeAsync(vhost, destinationExchangeInfo);
var destinationExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, destinationExchangeInfo.Name);
await fixture.ManagementClient.CreateExchangeAsync(vhost, destinationExchangeName, destinationExchangeInfo);
var destinationExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, destinationExchangeName);

await fixture.ManagementClient.CreateExchangeBindingAsync(sourceExchange, destinationExchange, new BindingInfo(RoutingKey: "#"));

Expand Down Expand Up @@ -983,14 +984,14 @@ public async Task Should_delete_exchange_to_exchange_binding()
const string destinationExchangeName = "management_api_test_destination_exchange";

var vhost = await fixture.ManagementClient.GetVhostAsync(Vhost.Name);
var sourceExchangeInfo = new ExchangeInfo(sourceExchangeName, "direct");
var destinationExchangeInfo = new ExchangeInfo(destinationExchangeName, "direct");
var sourceExchangeInfo = new ExchangeInfo("direct");
var destinationExchangeInfo = new ExchangeInfo("direct");

await fixture.ManagementClient.CreateExchangeAsync(vhost, sourceExchangeInfo);
var sourceExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, sourceExchangeInfo.Name);
await fixture.ManagementClient.CreateExchangeAsync(vhost, sourceExchangeName, sourceExchangeInfo);
var sourceExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, sourceExchangeName);

await fixture.ManagementClient.CreateExchangeAsync(vhost, destinationExchangeInfo);
var destinationExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, destinationExchangeInfo.Name);
await fixture.ManagementClient.CreateExchangeAsync(vhost, destinationExchangeName, destinationExchangeInfo);
var destinationExchange = await fixture.ManagementClient.GetExchangeAsync(vhost, destinationExchangeName);

await fixture.ManagementClient.CreateExchangeBindingAsync(sourceExchange, destinationExchange, new BindingInfo(RoutingKey: "#"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public async Task Should_be_able_to_provision_a_virtual_host()
var vhost = await fixture.ManagementClient.GetVhostAsync("my_virtual_host");

// next create a user for that virtual host
await fixture.ManagementClient.CreateUserAsync(UserInfo.ByPassword("mike", "topSecret").AddTag(UserTags.Administrator));
await fixture.ManagementClient.CreateUserAsync("mike", UserInfo.ByPassword("topSecret").AddTag(UserTags.Administrator));
var user = await fixture.ManagementClient.GetUserAsync("mike");

// give the new user all permissions on the virtual host
await fixture.ManagementClient.CreatePermissionAsync(vhost, new PermissionInfo(user.Name));
await fixture.ManagementClient.CreatePermissionAsync(vhost, user, new PermissionInfo());

// now log in again as the new user
using var management = new ManagementClient(fixture.Endpoint, user.Name, "topSecret");
Expand All @@ -34,11 +34,11 @@ public async Task Should_be_able_to_provision_a_virtual_host()
await management.IsAliveAsync(vhost);

// create an exchange
await management.CreateExchangeAsync(vhost, new ExchangeInfo("my_exchange", "direct"));
await management.CreateExchangeAsync(vhost, "my_exchange", new ExchangeInfo("direct"));
var exchange = await management.GetExchangeAsync(vhost, "my_exchange");

// create a queue
await management.CreateQueueAsync(vhost, new QueueInfo("my_queue"));
await management.CreateQueueAsync(vhost, "my_queue", new QueueInfo());
var queue = await fixture.ManagementClient.GetQueueAsync(vhost, "my_queue");

// bind the exchange to the queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace EasyNetQ.Management.Client.Tests.Model;
public class ExchangeInfoTests
{
[Fact]
public void Should_be_able_to_get_name()
public void Should_be_able_to_get_type()
{
const string expectedName = "the_name";
var exchangeInfo = new ExchangeInfo(expectedName, "direct");
exchangeInfo.Name.Should().Be(expectedName);
const string expectedType = "direct";
var exchangeInfo = new ExchangeInfo("direct");
exchangeInfo.Type.Should().Be(expectedType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ public class PermissionInfoTests

public PermissionInfoTests()
{
permissionInfo = new PermissionInfo("mikey");
permissionInfo = new PermissionInfo();
}

[Fact]
public void Should_return_the_correct_user_name()
{
permissionInfo.UserName.Should().Be("mikey");
}

[Fact]
public void Should_set_default_permissions_to_allow_all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ public class TopicPermissionInfoTests

public TopicPermissionInfoTests()
{
topicPermissionInfo = new TopicPermissionInfo("mikey");
topicPermissionInfo = new TopicPermissionInfo("topic_exchange");
}

[Fact]
public void Should_return_the_correct_user_name()
public void Should_return_the_correct_exchange()
{
topicPermissionInfo.UserName.Should().Be("mikey");
}

[Fact]
public void Should_set_default_exchange_to_null()
{
topicPermissionInfo.Exchange.Should().BeNull();
topicPermissionInfo.Exchange.Should().Be("topic_exchange");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UserInfoTests

public UserInfoTests()
{
userInfo = UserInfo.ByPassword(userName, password);
userInfo = UserInfo.ByPassword(password);
}

[Fact]
Expand Down
Loading

0 comments on commit a3ddad4

Please sign in to comment.