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

Error mocking Generic Repository #120

Closed
marcelobalexandre opened this issue Jul 18, 2014 · 1 comment
Closed

Error mocking Generic Repository #120

marcelobalexandre opened this issue Jul 18, 2014 · 1 comment

Comments

@marcelobalexandre
Copy link

I'm trying to mock a IDummyRepository which implements IGenericRepository<TEntityKey, TEntity> interface, and need to verify a call for the Add method of IGenericRepository. But with the example code below I'm getting a MockException.

If I replace de IGenericRepository in the ServiceDummy for the IDummyRepository the test works, but not in the way I need.

This is a issue or am I doing something wrong?

Thanks and sorry for possible errors in my english.

[TestClass]
public class DummyServiceSpec
{
    protected DummyService service;
    protected DummyModel model;

    [TestClass]
    public class Work : DummyServiceSpec
    {
        [TestMethod]
        public void ExpectToWork()
        {
            var repositoryMock = new Mock<IDummyRepository>();
            var serviceDummy = new ServiceDummy(repositoryMock.Object);
            var entity = new Dummy { DummyString = "DummyString" };

            serviceDummy.Add(entity);

            repositoryMock.Verify(r => r.Add(It.IsAny<Dummy>()), Times.AtLeastOnce());
        }
    }
}

public class ServiceDummy
{
    protected IGenericRepository<Guid, Dummy> dummyRepository;

    public ServiceDummy(IDummyRepository dummyRepository)
    {
        this.dummyRepository = dummyRepository;
    }

    public virtual void Add(Dummy entity)
    {
        this.dummyRepository.Add(entity);
    }
}
@marcelobalexandre
Copy link
Author

Sorry, I just found the problem, it was a bug in my GenericRepository code. I will close it.

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

1 participant