mardi 24 avril 2018

Make method testable for unit tests c#

So , i have the following code structure

public void method1(int index)
{
   switch(index)
   {
       case 1:
           Method2();break;
       case 2:
            Method3();break;
   }
 }

 public void Method2()
 {
     var entity = new SomeEntity();
     repo.Add(entity);

     var anotherEntity= new AnotherEntity();
     repo.Update(anotherEntity);
 }

While covering method2 with unit test, i ran into issue, that if i want to check that entity add to db, anyway it runs an update method too. How i can split it somehow, just wanna get maybe some best practices for method in which it's needed to do multiple operations with db. Thanks for helping me!

Aucun commentaire:

Enregistrer un commentaire