I am mocking a function call with two arguments. 1. input immutable class object 2. out parameter.
sample code:
Mock<ISample> mockSample = new Mock<ISample>();
SampleClass MyKey = new SampleClass() { prop1 = 1 };
SampleOutput output = new SampleOutput() { prop2 = 2 };
mockSample.setup(s => s.SampleMethod(It.is<SampleKey>(t => t.Equals(MyKey)),
out sampleOut))).Returns(true);
in actual code execution this mocked function return proper value if the key is same as mocked key, However, i am seeing a problem that this mocked function is returning same out value even if key does not match.
Any inputs?
Adding key code:
public class Key
{
public readonly DateTime prop1;
public readonly string prop2;
public Key(DateTime prop1, string prop2)
{
this.prop1 = prop1;
this.prop2 = prop2;
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
if (ReferenceEquals(this, obj))
return true;
Key other = obj as Key;
return this.prop1 == other.prop1 && string.Compare(this.prop2, other.prop2);
}
public override int GetHashCode()
{
return prop1.GetHashCode() ^ prop2.GetHashCode();
}
}