0
_usuario = CriaUsuario(new Login("Roberto"), new Senha("Senha"));
var dao = new Mock<IUsuarioDao>();
dao.Setup(d => d.Autenticar(It.IsAny<Login>(), It.IsAny<Senha>())).Returns(_usuario);
var usuario = dao.Object.Autenticar(new Login("Roberto"), new Senha("Senha"));
What do I want to know and if it’s worth taking this kind of test? Because I look like this, I prefer to do the test accessing the database because that would test the query
anyway.. what’s the best way?
I don’t know if I understand your difficulty. Is this in your normal code? It seems wrong to me. You shouldn’t use your normal code to produce tests. And the tests should test exactly what the code should do. Your mock should work as if it were the database and do all checks if everything is ok with data and environment controlled. Is it easy to do this? No, but people don’t tell you about it. Is it worth a unit test? It depends on several factors.
– Maniero