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

Cannot use the most basic example #45

Open
francotiveron opened this issue Feb 18, 2025 · 4 comments
Open

Cannot use the most basic example #45

francotiveron opened this issue Feb 18, 2025 · 4 comments

Comments

@francotiveron
Copy link

sealed class MyRepo
{
    public int ExpensiveDatabaseCall() => 1;
}
using MockMe;

var mock = Mock.Me(default(MyRepo)); //error

Argument 1: cannot convert from 'MyRepo' to 'MockMe.DummyClass'

@connorivy
Copy link
Owner

connorivy commented Feb 19, 2025

This specific error is part of the common errors page. This typically means that the source generator hasn’t ran and that you may need to rebuild your test project. Have you tried that?

@francotiveron
Copy link
Author

francotiveron commented Feb 19, 2025

ConsoleApp3.zip
Yes I have Cleaned and Rebuilt, no luck

@connorivy
Copy link
Owner

connorivy commented Feb 19, 2025

hey @francotiveron,

thanks for reporting this issue and providing an example. It made the issue very easy to find. This is a bug in the source generator where it isn't creating valid c# for types declared under the global namespace. This is the method call that is being generated (not valid because of the error in the fully qualified type name)

Image

I am going to leave this issue open until I can fix it, but in the meantime, you can fix this issue by simply changing

sealed class MyRepo
{
    public int ExpensiveDatabaseCall() => 1;
}

to

namespace MyProject; // <-- add a namespace

sealed class MyRepo
{
    public int ExpensiveDatabaseCall() => 1;
}

@francotiveron
Copy link
Author

works now

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