Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock class's method with multiple parameter only take last paramter #88

Closed
duongthaiha opened this issue Feb 4, 2014 · 2 comments
Closed

Comments

@duongthaiha
Copy link

Hi I have tried to mock and class and set up it as followed. What ever I tried only one assert return is true. I have tired to replace Input with String and Output class with int and its works fine. Any suggestion please? Thank you very much

[TestFixture]
class TestSample
{
[Test]
public void Test1()
{
    Mock<SampleClass> mockObject = new Mock<SampleClass>();
    var  mockInput1 = new Mock<InputClass>();
    var mockInput2 = new Mock<InputClass>();
    var mockOutPut1 = new Mock<OutputClass>();
    var mockOutPut2 = new Mock<OutputClass>();
    mockObject.Setup(x => x.Get(mockInput1.Object)).Returns(mockOutPut1.Object);
    mockObject.Setup(x => x.Get(mockInput2.Object)).Returns(mockOutPut2.Object);

    var returned = mockObject.Object.Get(mockInput1.Object);
    Assert.AreEqual(mockOutPut1, returned);

    returned = mockObject.Object.Get(mockInput2.Object);
    Assert.AreEqual(mockOutPut2, returned);

    returned = mockObject.Object.Get(mockInput1.Object);
    Assert.AreEqual(mockOutPut1, returned);
}
}

public class SampleClass
{
public  virtual OutputClass Get(InputClass a)
{
    return null;
}
}

public class InputClass {}
public class OutputClass {}
@jwChung
Copy link

jwChung commented Feb 4, 2014

It seems to me that you mean mockOutPut1.Object instead of mockOutPut1 as below.

Assert.AreEqual(mockOutPut1.Object, returned);

@duongthaiha
Copy link
Author

JwChung Sorry it was my bad You are right after I changed it then it is correct. Rookie mistake my bad my bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants