this error is trown by the following TEST. If i test the DataLayer, the database gets updated and everything works. however the mock keeps sending out this error. i have a similar test that does work with almost the exact code (on the InsertRPAData). the only diffrence i can see is that the XMLDataEntity is a diffrent entity in the test compared to the Verify but both of them use the barcode = 1 though.
this test needs to be worked on and the XMLDataEntity is just there to allow me to verefy the Test. also ignore the return for now.
[TestInitialize]
public void TestInitialize()
{
_mockRepository = new Mock<IRPADataLayer>();
UnityUtil.UnityContainer = new UnityContainer();
UnityUtil.UnityContainer.RegisterInstance(typeof(IRPADataLayer), _mockRepository.Object);
}
[TestMethod]
public void TestDoSuppressions()
{
//Arange
var suppressiontest = new Suppression();
//Import the XML File
XElement newElement = XElement.Parse(get090XML());
XDocument testdoc = new XDocument();
testdoc.Add(newElement);
String string2Stream = String.Concat("1");
Stream reader = new MemoryStream(ASCIIEncoding.Default.GetBytes(string2Stream));
RPADataEntity rpa = new RPADataEntity();
XMLDataEntity test = new XMLDataEntity();
test.barcode = 1;
rpa.RPAID = 1;
rpa.XMLData = testdoc;
//Act
Int32 success = suppressiontest.DoSuppressions(reader, rpa);
//Assert
_mockRepository.Verify(x => x.UploadPreprocData(rpa, test));
}
The method being called is this one.
public Int32 DoSuppressions(Stream reader, RPADataEntity rpa)
{
XMLDataEntity test = new XMLDataEntity();
test.barcode = 1;
_IRPADataLayer.UploadPreprocData(rpa, test);
return 1;
}
and the interface is this
public interface IRPADataLayer
{
void InsertPreProcData(PreProcDataEntity PreProcDataEntity);
void InsertRpaData(RPADataEntity RPADataEntity);
RPATypeEntity GetRPAType(String type);
void UploadPreprocData(RPADataEntity rpa, XMLDataEntity xml);
}
Your verify is expecting a certain instance of
XMLDataEntity, (the one your instantiating in your test).However the method that is being tested creates it’s own
XMLDataEntityand calls UploadPreprocData.So the verification fails because the method hasn’t been called with the expected instance of
XMLDataEntity.Most mocking frameworks provide a way to to specify that the expected parameter can be of any instance, so that might be what your wanting here.
Hope that helps.
Edit:
In Moq, verifying and excepting any parameter of a given type is done by using:
Where T is the type of the expected instance.
In your case this can be done like so: