RajOpteamix / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

Multithreading and invocation count #381

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
void Main()
{
    var fooMock = new Mock<IFoo>();
    fooMock.Setup(v => v.Foo()).Throws<Exception>();

    var tasks = Enumerable.Repeat(0, 20)
                    .Select(v => new Task(() => fooMock.Object.Foo()))
                    .ToArray();

            foreach (var task in tasks)
            {
                task.Start();
            }

    Action waitAllAction = () => Task.WaitAll(tasks);
    waitAllAction.ShouldThrow<AggregateException>();

    fooMock.Verify(v => v.Foo(), Times.Exactly(20)); //Verification fails
}

// Define other methods and classes here

public interface IFoo
{
    int Foo();
}

Version: 4.2.1402.2112. Os: Win2008

Am I correct that verification should succeed

Original issue reported on code.google.com by a.polyak...@gmail.com on 6 Oct 2014 at 11:38