devlooped / moq

The most popular and friendly mocking framework for .NET
Other
5.94k stars 802 forks source link

Make Moq portable to .NET Core #168

Closed kuhlenh closed 7 years ago

kuhlenh commented 9 years ago

This is Kasey from the .NET team and we are trying to help authors make their libraries portable across different platforms (especially .NET Core).

.NET Core is a modular implementation of the .NET Framework that can run on any platform (Windows, Mac, Linux). Side-by-side hosting enables apps to run no matter what Framework version the host has installed (if any). Developers include their dependencies (.NET libraries and your libraries) in their app via NuGet packages. .NET Core is a great new option for web and cloud developers and is the same underlying .NET runtime and framework used by ASP.NET 5.

The .NET team has made many .NET Framework libraries available as part of .NET Core and ASP.NET 5. With that work largely done, we need more open source libraries to support .NET Core so that developers can easily both move existing apps and create new apps that run on .NET Core. Our goal is to make app developers successful, building these new apps that target .NET Core and that run on Windows, OS X and Linux.

Check out the .NET Portability Analyzer. This tool gives you a detailed report on how portable your library is across platforms and will sometimes provide recommendations. This is an easy way for you to assess the effort required to support .NET Core and other platforms with Moq.

Please @mention me in this issue to discuss porting Moq to .NET Core. I'm happy to help get you started. If you have broader questions or concerns, you can also file an issue on the dotnet/corefx repo.

Thanks, Kasey

ghost commented 9 years ago

Any news on this? This is something myself and a few others would really like to see.

Also happy to help out with any port

kzu commented 9 years ago

We'd definitely appreciate the help @sblackler! Nobody's working on that port for now.

ghost commented 9 years ago

At a quick glance, I'm not sure what we can do about Silverlight support currently. Maybe @kuhlenh could provide some insight on what to do/when/if support will be coming?

Also, when I import all the files into a new class library project, most of the errors seem to be around the Castle dependency. I think that's going to be the biggest stumbling block for porting.

kzu commented 9 years ago

Indeed :(.

So how about getting Castle to port first somehow? ;)

On Mon, May 4, 2015 at 5:34 PM Stuart Blackler notifications@github.com wrote:

At a quick glance, I'm not sure what we can do about Silverlight support currently. Maybe @kuhlenh https://github.com/kuhlenh could provide some insight on what to do/when/if support will be coming?

Also, when I import all the files into a new class library project, most of the errors seem to be around the Castle dependency. I think that's going to be the biggest stumbling block for porting.

Reply to this email directly or view it on GitHub https://github.com/Moq/moq4/issues/168#issuecomment-98843282.

kuhlenh commented 9 years ago

I've put your report online for future reference.

If you reach out to Castle, feel free to direct them my way if they need any help. Otherwise, I'm happy to reach out to them for you!

kzu commented 9 years ago

Maybe I can just bring @kkozmic to the discussion :)

kkozmic commented 9 years ago

and I appear :)

MattGal commented 9 years ago

In previous exploration of what it's like to port existing content to CoreCLR, I have actually already done a private (not ready for PR) port based off of the Moq4 Silverlight 5 version, and would be interested in doing so in a more publicly sharable fashion.

Having a usable version of Castle.Core that isn't me hacking around would be great. @kkozmic , can you comment how close to reality this might be? Having already done it, I think the Moq port should be pretty reasonable.

hidori commented 9 years ago

:+1:

jeremymeng commented 9 years ago

I started experimenting on a port based on the Castle.Core PR by @MattGal (https://github.com/castleproject/Core/pull/92/).

Update I now have a version at https://github.com/jeremymeng/Moq4/tree/netcore-beta5. It works with Asp.Net vNext.

oadrian2 commented 9 years ago

@jeremymeng Have you pushed a nuget package for beta5?

richlander commented 9 years ago

We could. I just replied to the Castle Core thread to see if we can get the code finally merged. That will mitigate the need for a separate package.

Also, beta 5 is now a ways out of date. We should be targeting beta 7.

oadrian2 commented 9 years ago

@richlander Any progress on this, especially now that we're at ASP.Net beta 8 and now feature-complete?

ghost commented 9 years ago

Hellloooo....? Any news?

jeremymeng commented 9 years ago

Moq is depending on https://github.com/castleproject/Core/issues/90. Hope we are seeing progress soon on the Castle.Core port.

jeremymeng commented 8 years ago

Castle.Core support is around the corner so I will submit a PR earlier to get feedback.

davunderscorei commented 8 years ago

Is there any update on Core CLR support?

jeremymeng commented 8 years ago

Castle.Core alpha1 package on nuget.org already support .NET Core. I've updated #225 to work with that. Right now everyone is waiting for RC2 release. Once that happens, Castle.Core will be updated to use RC2, and so will Moq.

jeremymeng commented 8 years ago

I've updated my PR to work with RC2. Moq Team members, please take a look.

lucabriguglia commented 8 years ago

Moq team members any news on this? Thanks :-)

kzu commented 8 years ago

https://twitter.com/kzu/status/735944176953655296?s=09

On Sun, May 29, 2016, 8:44 AM Luca Briguglia notifications@github.com wrote:

Moq team members any news on this? Thanks :-)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/moq/moq4/issues/168#issuecomment-222356361, or mute the thread https://github.com/notifications/unsubscribe/AAKW66RZ0Ne0FuiEFG3lF4RWzQwPPDDdks5qGXw5gaJpZM4EM6yQ .

lucabriguglia commented 8 years ago

thanks @kzu

kzu commented 8 years ago

@jeremymeng did all the hard work :)

Should the PR be merged to a netcore feature branch and pushed to nuget.org as alpha? We are kinda waiting for .net core to RTM ;)

On Sun, May 29, 2016, 9:38 AM Luca Briguglia notifications@github.com wrote:

thanks @kzu https://github.com/kzu

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/moq/moq4/issues/168#issuecomment-222358489, or mute the thread https://github.com/notifications/unsubscribe/AAKW65_66562jhwGgkOxrPhVeCPUmeK1ks5qGYjbgaJpZM4EM6yQ .

neoKushan commented 8 years ago

@kzu I would say so, yes. For all of my projects, Moq is the only thing that currently requires a separate nuget feed to build. It's not a biggie, but would certainly be nice :)

jeremymeng commented 8 years ago

Should the PR be merged to a netcore feature branch and pushed to nuget.org as alpha?

Yes please. It would make other people's life easier!

rmarinho commented 8 years ago

Yes please @kzu :)

kzu commented 8 years ago

Done!

https://www.nuget.org/packages/Moq/4.6.25-alpha

lucabriguglia commented 8 years ago

Thank you very much Daniel!

ghost commented 8 years ago

I am on .net core RTM and see this version is not compatible with "netstandard1.6" because of Castle.Core 4.0.0-alpha001.

Issue here:https://github.com/castleproject/Core/issues/191

martinnormark commented 8 years ago

Hey - I see that Castle Core published a pre-release package two days ago which should fix the targeting issue: https://www.nuget.org/packages/Castle.Core/4.0.0-beta001

https://github.com/castleproject/Core/pull/205

Is it possible to get a pre-release of Moq published to test what @NickolasAcosta was doing?

klanglie commented 8 years ago

I am not familiar with this code any but would be glad to help with a port. Let's branch and organize. Does anyone know of an alternative to this project targeting Core?

jeremymeng commented 8 years ago

@martinnormark @PivotalAnimal I have a PR open, and here's the latest nupkg from it: https://ci.appveyor.com/project/MobileEssentials/moq4/build/1.0.58/artifacts

JasonBock commented 8 years ago

I'm currently trying to use "4.6.25-alpha" in a .NET Core class library project set up for xUnit based on their guidelines:

https://xunit.github.io/docs/getting-started-dotnet-core.html

Here's what project.json looks like:

"dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
    "FluentAssertions": "4.12.0",
    "Moq": "4.6.25-alpha"
},

"frameworks": {
    "netcoreapp1.0": {
        "dependencies": {
            "Microsoft.NETCore.App": {
                "type": "platform",
                "version": "1.0.0"
            }
        }
    }
}

I'm getting the Castle.Core issue:

Error NU1002 The dependency Castle.Core 4.0.0-alpha001 does not support framework .NETCoreApp,Version=v1.0.

Any chance of getting the nupkg from @jeremymeng pushed to Nuget soon as this will probably fix the issue (I think :))?

RichardD012 commented 8 years ago

Under frameworks, if you add in the import to dnxcore, it should work.

"netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "netcoreapp1.0"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.0-*",
          "type": "platform"
        },
      }
    }
JasonBock commented 8 years ago

Yes @RichardD012 that does work, thanks. Now to see if my unit test code will work :)

alexellis commented 8 years ago

Guys - does this or any Moq/Mocking framework exist for DNCore + XUnit?

neoKushan commented 8 years ago

@alexellis Yes, you will need to show pre-release packages in Nuget and look at the posts just above yours.

jeremymeng commented 8 years ago

https://www.nuget.org/packages/Moq/4.6.36-alpha

alexellis commented 8 years ago

@jeremymeng @neoKushan I got somewhere with this https://github.com/alexellis/dncore-market-rates

It seems like xunit has dependencies that need to bring in more than DNCore itself?

Link to issue: https://github.com/dotnet/core-docs/issues/828#issuecomment-234109735

Could not run this through the official .NET Core Docker images.

jeremymeng commented 8 years ago

@alexellis I suspect that you are missing the global.json file in the image? It tells dotnet restore where to look for projects. If I import microsoft/dotnet:latest and add the following it works.

COPY ./global.json ./global.json
jeremymeng commented 8 years ago

(Totally unrelated to Moq though)

klanglie commented 8 years ago

Thanks! I’ve updated my repository by adding some base test classes from Microsoft Identity that I will use later. So far it is building and the 8 added tests from Microsoft that were able to build are testing successfully.

From: Jeremy Meng [mailto:notifications@github.com] Sent: Wednesday, July 20, 2016 7:08 PM To: moq/moq4 moq4@noreply.github.com Cc: Kai Langlie kai@langlie.com; Mention mention@noreply.github.com Subject: Re: [moq/moq4] Make Moq portable to .NET Core (#168)

https://www.nuget.org/packages/Moq/4.6.36-alpha

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/moq/moq4/issues/168#issuecomment-234111168 , or mute the thread https://github.com/notifications/unsubscribe-auth/ANIqZaqpY-ao6IG_Ba3XcXKjlfyaVBdjks5qXqpEgaJpZM4EM6yQ . https://github.com/notifications/beacon/ANIqZTLTtGuso5AOsWSVAVrAIeSWUu0-ks5qXqpEgaJpZM4EM6yQ.gif

alexellis commented 8 years ago

Thanks I added global.json - I completely missed the fact it was not added. Is there a smart way of restoring so that Docker can cache that step rather than repeating it every single build?

martinnormark commented 8 years ago

Hi - I'm seeing random test failures when using Verify in PreMailer.Net (PR: milkshakesoftware/PreMailer.Net#122)

This is output from build 186 running this unit test:

    PreMailer.Net.Tests.LinkTagCssSourceTests.GetCSS_CallsWebDownloader_WithSpecifiedDomain [FAIL]
      Moq.MockException : 
Expected invocation on the mock at least once, but was never performed: w => w.DownloadString(It.Is<Uri>(u => u.Scheme == "http" && u.Host == "a.co"))
      No setups configured.
      No invocations performed.
      Stack Trace:
           at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable`1 setups, IEnumerable`1 actualCalls, Expression expression, Times times, Int32 callCount)
           at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
           at Moq.Mock.Verify[T,TResult](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
           at Moq.Mock`1.Verify[TResult](Expression`1 expression)
        C:\projects\premailer-net\PreMailer.Net\PreMailer.Net.Core.Tests\LinkTagCssSourceTests.cs(38,0): at PreMailer.Net.Tests.LinkTagCssSourceTests.GetCSS_CallsWebDownloader_WithSpecifiedDomain()

And this is from build 189 running another unit test:

    PreMailer.Net.Tests.LinkTagCssSourceTests.GetCSS_CallsWebDownloader_WithSpecifiedBundle [FAIL]
      Moq.MockException : 
Expected invocation on the mock at least once, but was never performed: w => w.DownloadString(It.Is<Uri>(u => u.PathAndQuery == "/Content/css?v=7V7TZzP9Wo7LiH9_q-r5mRBdC_N0lA_YJpRL_1V424E1"))
      No setups configured.
      No invocations performed.
      Stack Trace:
           at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable`1 setups, IEnumerable`1 actualCalls, Expression expression, Times times, Int32 callCount)
           at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
           at Moq.Mock.Verify[T,TResult](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
           at Moq.Mock`1.Verify[TResult](Expression`1 expression)
        C:\projects\premailer-net\PreMailer.Net\PreMailer.Net.Tests\LinkTagCssSourceTests.cs(49,0): at PreMailer.Net.Tests.LinkTagCssSourceTests.GetCSS_CallsWebDownloader_WithSpecifiedBundle()

Both tests works fine locally on both Mac and Windows, so it could be something to specific to the environment running in AppVeyor.

benrr101 commented 8 years ago

Found a missing runtime package dependency in the beta package released on MyGet. System.Diagnostics.TraceSource is needed at runtime but isn't listed in the dependencies for the package. Please let me know if you need any more info on this issue.

jeremymeng commented 8 years ago

@benrr101 Which version of Moq are you using? There was an issue in Castle.Core but it has been fixed in the latest version. The System.Diagnostics.TraceSource dependency should be pulled in by Castle.Core. See the dependency list at https://www.nuget.org/packages/Castle.Core/4.0.0-beta001.

benrr101 commented 8 years ago

@jeremymeng We're using version moq.netcore 4.4.0-beta8 from myget.org, which has a dependency on Castle.Core >=3.3.4-beta8 (which is the version that got pulled in). Can this dependency get bumped up in the next beta release of moq.netcore?

jeremymeng commented 8 years ago

@benrr101 Please use the latest version from NuGet: https://www.nuget.org/packages/Moq/4.6.36-alpha. The version you are using is from ASP.NET myget feed, which is pretty old now.

benrr101 commented 8 years ago

@jeremymeng you are right! My coworker who suggested using the myget feed version made it seem like this was the only version that worked with .net core. We didn't even think to try the packages on nuget.org. Thanks!

redowl3 commented 8 years ago

I'm having no luck creating a project that references Moq and Xunit after following the advice from above. I'm getting the dependency Castle.Core 4.0.0-alpha001 does not support framework .NETCoreApp,Version=v1.0. error

Any ideas?

{ "version": "1.0.0-*", "testRunner": "xunit", "dependencies": { "xunit": "2.2.0-beta2-build3300", "dotnet-test-xunit": "2.2.0-preview2-build1029", "Moq": "4.6.36-alpha" },

"frameworks": { "netcoreapp1.0": { "imports": [ "dnxcore50", "netcoreapp1.0" ], "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0-*", "type": "platform" } } } } }