jeudi 16 avril 2020

C# Test SQL trigger. Problem with IValidatableObject

My problem: I wrote tests to check the operation of the SQL trigger (It validates some value on the SQL side before the insert). Now I need to check the validation on the model side. I am using IValidatableObject. The problem is that in it I validate two values based on data downloaded from the database, like this:

using (EntityBase ent = new EntityBase())
{
    UsersView = ent.GetUsersViewbyUser(this.UserId);
    ItemView = ent.GetItemViewByTaskId(this.TaskId);
}

if (UsersView == null)
{
    yield return new ValidationResult("User not found.", new List<string> { "UserId" });
}

And now when I want to validate the model from the test side, I don't have a database connection, because the context in the tests is not the same as in IValidatableObject.

How can I get around this?

Aucun commentaire:

Enregistrer un commentaire