Description
When mocking IRequestAdapter from Microsoft.Kiota.Abstractions using IRequestAdapter.Mock(), tests won't build because the generated mock does not implement an interface member with a constrained generic type parameter.
This also occurs when using the [assembly: GenerateMock(typeof(IRequestAdapter))]
Expected Behavior
I expected the IRequestAdapter to be mocked when using both methods.
Actual Behavior
The build fails with the following output:
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,110): Error CS0539 : 'IRequestAdapterMock.SendAsync<ModelType>(RequestInformation, ParsableFactory<ModelType>, Dictionary<string, ParsableFactory<IParsable>>?, CancellationToken)' in explicit interface declaration is not found among members of the interface that can be implemented
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(7,127): Error CS0535 : 'IRequestAdapterMock' does not implement interface member 'IRequestAdapter.SendAsync<ModelType>(RequestInformation, ParsableFactory<ModelType>, Dictionary<string, ParsableFactory<IParsable>>?, CancellationToken)'
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,110): Error CS0453 : The type 'ModelType' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>'
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,278): Error CS0314 : The type 'ModelType' cannot be used as type parameter 'T' in the generic type or method 'ParsableFactory<T>'. There is no boxing conversion or type parameter conversion from 'ModelType' to 'Microsoft.Kiota.Abstractions.Serialization.IParsable'.
Steps to Reproduce
- Import Nuget Package
Microsoft.Kiota.Abstractions.
- Create a test class using the
IRequestAdapter.
- Create a test that mocks the interface using
Mock().
- Build the project (creating a full test isn't necessary).
using Microsoft.Kiota.Abstractions;
namespace TestSpace;
public class TestService(IRequestAdapter requestAdapter)
{
public Task TestMethod()
{
RequestInformation requestInfo = new();
return requestAdapter.SendNoContentAsync(requestInfo);
}
}
public class Test
{
[Test]
public async Task TestMethod_Succeeds()
{
var requestAdapter = IRequestAdapter.Mock();
requestAdapter.SendNoContentAsync(AnyArgs()).ReturnsAsync(Task.CompletedTask);
var sut = new TestService(requestAdapter);
await sut.TestMethod();
requestAdapter.SendNoContentAsync(AnyArgs()).WasCalled(Times.Once);
}
}
TUnit Version
1.61.15
.NET Version
.NET 10.0
Operating System
Windows
IDE / Test Runner
JetBrains Rider
Error Output / Stack Trace
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,110): Error CS0539 : 'IRequestAdapterMock.SendAsync<ModelType>(RequestInformation, ParsableFactory<ModelType>, Dictionary<string, ParsableFactory<IParsable>>?, CancellationToken)' in explicit interface declaration is not found among members of the interface that can be implemented
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(7,127): Error CS0535 : 'IRequestAdapterMock' does not implement interface member 'IRequestAdapter.SendAsync<ModelType>(RequestInformation, ParsableFactory<ModelType>, Dictionary<string, ParsableFactory<IParsable>>?, CancellationToken)'
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,110): Error CS0453 : The type 'ModelType' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>'
2>Microsoft_Kiota_Abstractions_IRequestAdapter_Mock.g.cs(18,278): Error CS0314 : The type 'ModelType' cannot be used as type parameter 'T' in the generic type or method 'ParsableFactory<T>'. There is no boxing conversion or type parameter conversion from 'ModelType' to 'Microsoft.Kiota.Abstractions.Serialization.IParsable'.
Additional Context
We are using this in the context of mocking the Graph Service to test our service that uses Graph for various applications.
IDE-Specific Issue?
Description
When mocking
IRequestAdapterfromMicrosoft.Kiota.AbstractionsusingIRequestAdapter.Mock(), tests won't build because the generated mock does not implement an interface member with a constrained generic type parameter.This also occurs when using the
[assembly: GenerateMock(typeof(IRequestAdapter))]Expected Behavior
I expected the
IRequestAdapterto be mocked when using both methods.Actual Behavior
The build fails with the following output:
Steps to Reproduce
Microsoft.Kiota.Abstractions.IRequestAdapter.Mock().TUnit Version
1.61.15
.NET Version
.NET 10.0
Operating System
Windows
IDE / Test Runner
JetBrains Rider
Error Output / Stack Trace
Additional Context
We are using this in the context of mocking the Graph Service to test our service that uses Graph for various applications.
IDE-Specific Issue?
dotnet testordotnet run, not just in my IDE