Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Jul 1, 2024
1 parent 5f5b255 commit 5f9614a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/MagicOnion.Server.Tests/StreamingHubHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ byte[] BuildMessage()
fakeStreamingHubContext.Responses[0].Memory.ToArray().Should().Equal(BuildMessage());
}

[Fact]
public async Task MethodAttributeLookup()
{
// Arrange
var services = new ServiceCollection();
var serviceProvider = services.BuildServiceProvider();
var hubType = typeof(StreamingHubHandlerTestHub);
var hubMethod = hubType.GetMethod(nameof(StreamingHubHandlerTestHub.Method_Attribute))!;

// Act
var handler = new StreamingHubHandler(hubType, hubMethod, new StreamingHubHandlerOptions(new MagicOnionOptions()), serviceProvider);

// Assert
Assert.NotEmpty(handler.AttributeLookup);
Assert.NotEmpty(handler.AttributeLookup[typeof(CustomMethodAttribute)]);
Assert.NotEmpty(handler.AttributeLookup[typeof(CustomHubAttribute)]);
}

interface IStreamingHubHandlerTestHubReceiver
{
}
Expand All @@ -482,8 +500,16 @@ interface IStreamingHubHandlerTestHub : IStreamingHub<IStreamingHubHandlerTestHu
void Method_Parameterless_Void();
void Method_Parameter_Single_Void(int arg0);
void Method_Parameter_Multiple_Void(int arg0, string arg1, bool arg2);

Task Method_Attribute();
}

[AttributeUsage(AttributeTargets.Class)]
class CustomHubAttribute : Attribute;
[AttributeUsage(AttributeTargets.Method)]
class CustomMethodAttribute : Attribute;

[CustomHub]
class StreamingHubHandlerTestHub : IStreamingHubHandlerTestHub
{
public List<string> Results { get; } = new List<string>();
Expand Down Expand Up @@ -548,5 +574,8 @@ public void Method_Parameter_Multiple_Void(int arg0, string arg1, bool arg2)
{
Results.Add(nameof(Method_Parameter_Multiple_Void) + $"({arg0},{arg1},{arg2}) called.");
}

[CustomMethod]
public Task Method_Attribute() => Task.CompletedTask;
}
}

0 comments on commit 5f9614a

Please sign in to comment.