microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Tests/Microsoft.Teams.Common.Tests/Extensions/MethodInfoExtensionsTests.cs

87lines · modeblame

a1e39460Falguni Thakor10 months ago1using Microsoft.Teams.Common.Extensions;
2
3namespace Microsoft.Teams.Common.Tests.Extensions;
4public class MethodInfoExtensionsTests
5{
6private class TestClass
7{
8public bool VoidCalled { get; private set; }
9public object? Value { get; private set; }
10
11public void VoidMethod()
12{
13VoidCalled = true;
14}
15
16public int SyncMethod(int x, int y)
17{
18return x + y;
19}
20
21public async Task AsyncVoidMethod()
22{
23await Task.Delay(1);
24VoidCalled = true;
25}
26
27public async Task<int> AsyncValueMethod(int x, int y)
28{
29await Task.Delay(1);
30return x * y;
31}
32
33public Task<object?> AsyncObjectMethod(object? value)
34{
35Value = value;
36return Task.FromResult(value);
37}
38}
39
40[Fact]
41public async Task InvokeAsync_SyncMethod_ReturnsResult()
42{
43var obj = new TestClass();
44var method = typeof(TestClass).GetMethod(nameof(TestClass.SyncMethod));
45var result = await method!.InvokeAsync(obj, new object[] { 2, 3 });
46Assert.Equal(5, result);
47}
48
49[Fact]
50public async Task InvokeAsync_AsyncValueMethod_ReturnsResult()
51{
52var obj = new TestClass();
53var method = typeof(TestClass).GetMethod(nameof(TestClass.AsyncValueMethod));
54var result = await method!.InvokeAsync(obj, new object[] { 2, 4 });
55Assert.Equal(8, result);
56}
57
58[Fact]
59public async Task InvokeAsync_AsyncVoidMethod_ReturnsNull()
60{
61var obj = new TestClass();
62var method = typeof(TestClass).GetMethod(nameof(TestClass.AsyncVoidMethod));
63var result = await method!.InvokeAsync(obj, null);
64Assert.True(obj.VoidCalled);
65}
66
67[Fact]
68public async Task InvokeAsync_AsyncObjectMethod_ReturnsObject()
69{
70var obj = new TestClass();
71var method = typeof(TestClass).GetMethod(nameof(TestClass.AsyncObjectMethod));
72var input = "test";
73var result = await method!.InvokeAsync(obj, new object?[] { input });
74Assert.Equal(input, result);
75Assert.Equal(input, obj.Value);
76}
77
78[Fact]
79public async Task InvokeAsync_VoidMethod_ReturnsNull()
80{
81var obj = new TestClass();
82var method = typeof(TestClass).GetMethod(nameof(TestClass.VoidMethod));
83var result = await method!.InvokeAsync(obj, null);
84Assert.Null(result);
85Assert.True(obj.VoidCalled);
86}
87}