Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

ValueTask confuses NSubstitute
MihaMarkic
#1 Posted : Tuesday, August 28, 2018 2:45:35 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/8/2015(UTC)
Posts: 11
Location: Slovenia

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
I'm seeing a problem probably related to NCrunch.

See the code below.
One needs NUnit and NSubstitute nuget packages. It's a .net 4.6.1 class library.
The test passes.

Now, add System.Threading.Tasks.Extensions 4.5.1 nuget library and test will start failing.
If running outside NCrunch test still succeeds.
If I downgrade System.Threading.Tasks.Extensions to i.e. 4.4.0. it works again.

I think that MS screwed something with System.Threading.Tasks.Extensions 4.5.1 (it manifests problems in i.e. Xamarin as well).

Perhaps something to consider.

You can download repro here.


Code:
[TestFixture]
    public class Tests
    {
        [Test]
        public async Task Test()
        {
            var target = new Some();
            var worker = Substitute.For<IWorker>();

            await target.ProcessAsync(worker);

            worker.Received(1).Confirm();
        }
    }

    public interface IWorker
    {
        void Confirm();
    }

    public class Some
    {
        public async Task<bool> ProcessAsync(IWorker worker)
        {
            await Tubo();
            worker.Confirm();
            return true;
        }
        async ValueTask<bool> Tubo()
        {
            return true;
        }
    }
Remco
#2 Posted : Wednesday, August 29, 2018 2:16:02 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
MihaMarkic
#3 Posted : Wednesday, August 29, 2018 6:36:15 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/8/2015(UTC)
Posts: 11
Location: Slovenia

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Yep, this version seems to fix it.
1 user thanked MihaMarkic for this useful post.
Remco on 8/29/2018(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download