jeudi 28 avril 2016

Unit testing first, Database Count using LINQ

Since I'm now practicing a unit test first development process I had this question while doing the unit test.

I have to create a test that'll verify or assert the items that it will count in a specific table in the database. Also, it has parameters.

  [TestMethod]
  public void verify_items_count()
  {
      //Arrange
      Mock<IRepository> Repo = new Mock<IRepository>();
      Repo.Setup(t => t.Query().Count(t => t.Id == "**WHAT SHOULD I PUT HERE IF THIS IS ONLY A MOCK**")).Returns(12);

      //Act
      //Assert
  }

Seems like it'll be none sense if I assert it checking if it returns 12 having also its parameters since we all know that it doesn't call in the DB. I've set it to 12, though.

Please help me how to write a unit test first. I was thinking if it is supposed to be in an integration testing. But I've read that everything should start in unit testing. So I believe there is a way.

Aucun commentaire:

Enregistrer un commentaire