I have some integration tests around stored procs. Typically I do the test setup using Dapper. This is fine for simple cases, but in some cases to setup up the system correctly it would be far simpler to call the necessary stored procs. It would be simpler because some entities have many relationships and constraints and replicating that in Dapper is time consuming, plus if I change the system I have to then change my Dapper test setup code too.
Is it a good idea to use the system to setup the system to test or should I keep the setup of the system independent of the system?
I've added a simple code sample, below, (not representative of my actual system) to help clarify what I mean. In the first test I'm checking that CreatePerson actually adds an entity into the Person table. In the second test I use the method I just tested, CreatePerson, to setup the system and then test something else.
public class When_CreatePerson_is_called
{
[Fact]
public void It_should_create_entity()
{
// arrange
var db = new Database();
// act - testing CreatePerson does what is expected of it
int id = db.CreatePerson();
Person p = db.GetPerson(id);
Assert.NotNull(p);
}
}
public class When_UpdatePerson_is_called
{
[Fact]
public void It_should_update_untity()
{
// arrange
var db = new Database();
int id = db.CreatePerson(); // Should I use a different way to initialize the system or is it ok to use the system?
// act
db.UpdatePerson(id, "John Smith");
Person p = db.GetPerson(id);
Assert.Equal("John Smith", p.FullName);
}
}