The second assertion never executes in the unit test below:
namespace Foo {
public class MyClass {
}
}
namespace Bar {
public class MyClass {
}
}
namespace Quux {
public interface IRepo {
object Get<T>() where T : new();
}
}
namespace Tests {
[TestFixture]
public class MyTests {
private Mock<Quux.IRepo> repo = new Mock<Quux.IRepo>();
[SetUp]
public void Setup() {
repo.Setup(r => r.Get<Foo.MyClass>()).Returns(new Object());
repo.Setup(r => r.Get<Bar.MyClass>()).Returns(new Object());
}
[Test]
public void Test() {
Assert.IsNotNull(repo.Object.Get<Foo.MyClass>());
Assert.IsNotNull(repo.Object.Get<Bar.MyClass>()); // Never reached.
}
}
}
Looks like setting up Get<Bar.MyClass>() overwrites the setup for Get<Foo.MyClass>(). Does this mean Moq ignores the namespaces Foo and Bar when setting up Get<T>()? Is there a way around this without renaming the MyClass classes and without implementing IRepo? I'm using Moq 3.1.416.3.
Update: Looks like this is fixed for next release.