lundi 8 juin 2015

Unit testing a table creation function using Moq

I have a class Operations that takes a DBContext and performs operations on that context.

One of these operations is CreateTable that tries to create a table in the database and return a Boolean indicating success or failure.

I am required to unit test Operations.CreateTable, for which I will inject a mock DBContext using Moq.

But I am little bit blocked. How could I check that the code within Operations.CreateTable actually creates a table in the Mock object?

Some simplified code:

public Operations<IProvider>()
{
  public bool CreateTable
  {
    try
    {
      // Code to create a table within the dbcontext
      return true;
    }
    catch
    {
      return false;
    }
  }
}

public interface IProvider()
{
  public DBContext Context;
}

Note: I suspect this pattern may not be suitable, but it is what I was given. Thank You.

Aucun commentaire:

Enregistrer un commentaire