mercredi 3 août 2016

validate MOQ unit test method return value

I have the below class and test class written using MOQ

public class Mytest : testin
{
        public int getId(int id)
        {
          int s = 2;
          return s;
        }

}

test class

  public void returngetId()
        {

            // Build up our mock object

            _mock.Setup(x => x.getId(It.IsAny<int>())).Returns(1)

        }

I'm returning 2 from the function and in unit test cases checking for the value 1. As per my understanding the test cases should fail. But im getting success message. How i can validate the return value is exactly what im expecting? I want to fail the test if it returning other than 1.

Aucun commentaire:

Enregistrer un commentaire