Skip to content

Using MockBehavior.Strict #20

@Lapov

Description

@Lapov

Hi guys!
I tried to make a mock for my simple DbContext and It works fine For MockBehavior.Default, But when I try to use MockBehavior.Strict I cannot even get an Object of this mock.

I made some workaround for one exception using additional Setup for Set<> method:

_myContextMock.Setup(x => x.MyEntities).Returns(mockSetObject);
_myContextMock.Setup(x => x.Set<MyEntity>()).Returns(mockSetObject);

but now got:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> Moq.MockException : IEnumerable.GetEnumerator() invocation failed with mock behavior Strict.
All invocations on the mock must have a corresponding setup.

And it is when I try to get an Object of my Mock, I mean when I use _myContextMock.Object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions