Reputation: 952
I'm trying to create an integration test for my User
class using NUnit
, what I want do is start a transaction
, update my MySQL
test db and than rollback.
This is my code, the update is fine but at the and my db remains updated.
Calling my query in MySQL Workbench
works fine.
[TestFixture]
public class UtenteIntTest
{
private User user;
bool result;
[SetUp]
public void Setup()
{
//Execute query "START TRANSACTION"
result = false;
}
[Test]
public void ConstId_IdUser_User()
{
user = new User(1);
if ((user.id == 1) && user.username == "test" &&
user.name == "test" && user.active == 1
&& user.mail == "[email protected]")
{
result = true;
}
Assert.That(result, Is.EqualTo(true));
}
[Test]
public void Update_User_UpdatedUser()
{
user = new User(1)
{
username = "update",
password = "update",
name = "update",
mail = "[email protected]",
attivo = 0
};
user.Update();
user = new User(1);
if ((user.id == 1) && user.username == "update" &&
user.nominativo == "update" && user.active == 0
&& user.mail == "[email protected]")
{
result = true;
}
Assert.That(result, Is.EqualTo(true));
}
[TearDown]
public void Teardown()
{
//Execute query "ROLLBACK"
}
}
Upvotes: 2
Views: 434
Reputation: 198
check if your database supports transactions.
You can use the Transactionscope to test transactions. see. How do I test database-related code with NUnit?
Upvotes: 3