-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathIssue6456Tests.cs
More file actions
51 lines (42 loc) · 1.69 KB
/
Copy pathIssue6456Tests.cs
File metadata and controls
51 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Serialization;
using TUnit.Mocks;
namespace TUnit.Mocks.Tests;
/// <summary>
/// Regression tests for #6456: Microsoft.Kiota.Abstractions.IRequestAdapter could not be mocked
/// because its generic methods carry 'where ModelType : IParsable'. The generated explicit
/// interface implementations omitted the 'where ModelType : default' clause, so the compiler
/// parsed Task<ModelType?> as Task<Nullable<ModelType>> (CS0453/CS0539/CS0535/CS0314).
/// </summary>
public class Issue6456Tests
{
private sealed class TestModel : IParsable
{
public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() =>
new Dictionary<string, Action<IParseNode>>();
public void Serialize(ISerializationWriter writer)
{
}
}
[Test]
public async Task SendNoContentAsync_Can_Be_Mocked_And_Verified()
{
var mock = IRequestAdapter.Mock();
var requestInfo = new RequestInformation();
await mock.Object.SendNoContentAsync(requestInfo);
mock.SendNoContentAsync(Any(), Any(), Any()).WasCalled(Times.Once);
}
[Test]
public async Task SendAsync_With_Constrained_Generic_Returns_Configured_Value()
{
var mock = IRequestAdapter.Mock();
var expected = new TestModel();
mock.SendAsync<TestModel>(Any(), Any(), Any(), Any()).Returns(expected);
var result = await mock.Object.SendAsync(
new RequestInformation(),
static _ => new TestModel(),
errorMapping: null,
CancellationToken.None);
await Assert.That(result).IsSameReferenceAs(expected);
}
}