There are no ReturnsAsync methods for mocking container async methods.
There should be a set of methods to mock async methods of a container similar to regular object mocking.
As a user I should be able to write code like:
container.Arrange<IContainer>(r => r.SomeAsyncMethod("data")).ReturnsAsync("returnValue");
Provide support for .NET MAUI projects.
Let me explain in details the current situation:
I have Unit Test project using JustMock and running into a problem. It seems like JustMock is using the wrong version number to locate the SDK. let me explain:
The project is set to: <TargetFramework>net7.0</TargetFramework>
But it also has <UseMaui>true</UseMaui> enabled
I am getting the following error:
"Framework: 'Microsoft.Maui.Core', version '7.0.92' (x64) .NET location: C:\Program Files\dotnet No frameworks were found.
That 7.0.92 version is only for the MAUI workload version, not the SDK versions. It seems JustMock uses a workload version as a SDK version.
JustMock interprets anonymous types as tuples. The sample below demonstrates the issue:
public interface IAnsweringService
{
(int code, string desc) GetAnswer(string question);
}
[TestMethod]
public void AnswerToTheUniverseQuestionTest()
{
var apiMock = Mock.Create<IAnsweringService>();
var expectedAnswer = new { code = 42, desc = "Answer to the Ultimate Question of Life" };
Mock.Arrange(() => apiMock.GetAnswer(Arg.AnyString)).Returns(expectedAnswer);
var actualAnswer = apiMock.GetAnswer("What is a universe question answer?");
Assert.AreEqual(expectedAnswer.code, actualAnswer.code);
Assert.AreEqual(expectedAnswer.desc, actualAnswer.desc);
}
Telerik.JustMock.Core.MockException: The chained return value type '<>f__AnonymousType1`2[System.Int32,System.String]' is not compatible with the arranged method's return type 'System.ValueTuple`2[System.Int32,System.String]'
The threading model of UI apps differs from the test host and this might become a source of issues like the following: System.InvalidOperationException: "The calling thread must be STA, because many UI components require this". The request is about extending JustMock with some helpers that can be used to solve this issue easily.
The new public API should allow the developer to access the invocations for a particular arrangement. Something like the following:
IEnumerable<IInvocaiton> invocations = foo.GetInvocationsFor((x) => x.CalcData(2, 2));
Implement a new public API that will allow the developer to iterate over all invocations of mock arrangements. Something like the following:
IEnumerable<IInvocaiton> invocations = Mock.Invocations;