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 == "test@test.test")
{
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 = "update@update.update",
attivo = 0
};
user.Update();
user = new User(1);
if ((user.id == 1) && user.username == "update" &&
user.nominativo == "update" && user.active == 0
&& user.mail == "update@update.update")
{
result = true;
}
Assert.That(result, Is.EqualTo(true));
}
[TearDown]
public void Teardown()
{
//Execute query "ROLLBACK"
}
}