microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
devtools-port-no-auth

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

88lines · modecode

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