Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Ability to setup a property of type Task<ConcreteType> by mocking interface #1460

Open
1 task done
wizofaus opened this issue Feb 1, 2024 · 2 comments
Open
1 task done

Comments

@wizofaus
Copy link

wizofaus commented Feb 1, 2024

Category

  • Feature request

Describe the feature

I'm trying to mock a class in a library that uses concrete types for several of its properties, but I happen to know that the properties are only ever accessed via an interface that the concrete type implements.
This works fine:

        `mock.SetupGet<IInterface>(l => l.Property).Returns(Mock.Of<IInterface>())`

Despite the fact that the mocked type defines "Property" as an object of type "ConcreteType" (presumably it would fail if there were code that relied on Property genuinely being of type "ConcreteType", but so far no such issues).

The issue is that one property is actually of type Task<ConcreteType>, and I want to replace it with mocked Task<IInterface>, and so far I haven't found any syntax that allows that.

If there were a SetupAsync( ) or similar function (matching ReturnsAsync()), I would think it might be possible?

Back this issue
Back this issue

Copy link

Due to lack of recent activity, this issue has been labeled as 'stale'.
It will be closed if no further activity occurs within 30 more days.
Any new comment will remove the label.

@github-actions github-actions bot added the stale label Aug 24, 2024
@github-actions github-actions bot removed the stale label Sep 3, 2024
@kzu
Copy link
Member

kzu commented Sep 3, 2024

You should be able to set the return value value to Task.FromResult(Mock.OfType<IInterface>()), I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants