Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact IManagementClient API (Get/Put/Delete/Post) #319

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ private static MethodDeclarationSyntax GenerateReplacementExtensionMethod(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
SyntaxFactory.IdentifierName(thisParameter.Identifier.Text),
SyntaxFactory.IdentifierName(method.Name)
method.GetAccessName()
),
SyntaxFactory.ArgumentList(
SyntaxFactory.SeparatedList(argumentExpressions.Select(a => SyntaxFactory.Argument(a))))
);

return SyntaxFactory.MethodDeclaration(method.ReturnType.GetTypeSyntax(), methodName)
.WithTypeParameterList(method.GetTypeParameterListSyntax())
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword))
.WithParameterList(SyntaxFactory.ParameterList(parameters))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static MethodDeclarationSyntax GenerateSyncExtensionMethod(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
SyntaxFactory.IdentifierName(thisParameter.Identifier.Text),
SyntaxFactory.IdentifierName(method.Name)
method.GetAccessName()
),
SyntaxFactory.ArgumentList(
SyntaxFactory.SeparatedList(argumentExpressions.Select(a => SyntaxFactory.Argument(a))))
Expand All @@ -90,6 +90,7 @@ private static MethodDeclarationSyntax GenerateSyncExtensionMethod(
method.IsAwaitable(out var awaitableResultType);

return SyntaxFactory.MethodDeclaration(awaitableResultType!.GetTypeSyntax(), methodName)
.WithTypeParameterList(method.GetTypeParameterListSyntax())
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword))
.WithParameterList(SyntaxFactory.ParameterList(parameters))
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ public static SeparatedSyntaxList<ParameterSyntax> GetParameterListSyntax(this I
{
return (SyntaxFactory.ParseMemberDeclaration(method.ToDisplayString(MethodDisplayFormat)) as MethodDeclarationSyntax)!.ParameterList.Parameters;
}

public static TypeParameterListSyntax? GetTypeParameterListSyntax(this IMethodSymbol method)
{
return (SyntaxFactory.ParseMemberDeclaration(method.ToDisplayString(MethodDisplayFormat)) as MethodDeclarationSyntax)!.TypeParameterList;
}

public static SimpleNameSyntax GetAccessName(this IMethodSymbol method)
{
if (method.IsGenericMethod)
{
var arguments = method.GetTypeParameterListSyntax()!.Parameters.Select(typeParameter => SyntaxFactory.IdentifierName(typeParameter.Identifier));
return SyntaxFactory.GenericName(method.Name).WithTypeArgumentList(SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList<TypeSyntax>(arguments)));
}
else
{
return SyntaxFactory.IdentifierName(method.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1215,11 +1215,39 @@ public async Task Should_get_queues()
}

[Fact]
public async Task Should_get_queues_without_stats()
public async Task Should_get_queues_with_stats_criteria()
{
await CreateTestQueue(TestQueue);
var queues = await fixture.ManagementClient.GetQueuesWithoutStatsAsync();
queues.Should().NotBeNullOrEmpty();
var queue = await CreateTestQueue(TestQueue);

var publishInfo = new PublishInfo(
TestQueue,
"Hello World",
PayloadEncoding.String,
new Dictionary<string, object?>
{
{ "app_id", "management-test" }
}
);

await fixture.ManagementClient.PublishAsync("/", "amq.default", publishInfo);
Queue queueWithStats;
do
{
queueWithStats = (await fixture.ManagementClient.GetQueuesAsync()).Single(q => q.Name == TestQueue);
} while (queueWithStats.Messages == 0);
queueWithStats.Messages.Should().Be(1);
queueWithStats.MessagesDetails.Should().NotBeNull();
queueWithStats.MessageStats.Should().NotBeNull();

var queueWithoutStats = (await fixture.ManagementClient.GetQueuesAsync(StatsCriteria.Disable)).Single(q => q.Name == TestQueue);
queueWithoutStats.Messages.Should().Be(0);
queueWithoutStats.MessagesDetails.Should().BeNull();
queueWithoutStats.MessageStats.Should().BeNull();

var queueWithTotalsOnly = (await fixture.ManagementClient.GetQueuesAsync(StatsCriteria.QueueTotalsOnly)).Single(q => q.Name == TestQueue);
queueWithTotalsOnly.Messages.Should().Be(1);
queueWithTotalsOnly.MessagesDetails.Should().BeNull();
queueWithTotalsOnly.MessageStats.Should().BeNull();
}


Expand Down
Loading
Loading