Skip to content

Commit

Permalink
Compact IManagementClientAPI (Get/Put/Delete/Post)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Nikulshin committed Feb 14, 2024
1 parent d49a9d8 commit c79ee3e
Show file tree
Hide file tree
Showing 16 changed files with 724 additions and 1,006 deletions.

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

0 comments on commit c79ee3e

Please sign in to comment.