I am having a problem when using the Moq for unit testing the a function which accepts number of parameters. I did the bellow steps to moq the service.
-
Created a mock object to interface. the relevant method in the interface contains four arguments namely int type, a collection and a object. so i initailized the variable needed for those first,
-
Then setup the mock object to return a a predefined type of object.
-
After that the relevant method in the service class is called with the reuired arguments but the method deos not return the object that it is supposed to return like above it rather sends a object with null values.
Am I missing anything in the code bellow?
Collection spec = new Collection() { new MyIdSample() { SampleID = 1234 } }; int index = 0; int maxNoOfRows = 2; MyDocumentListSortFields sortFeild = new MyDocumentListSortFields() { Descending = false, SortField = MyDocumentListSortFields.SortFields.Date };
var bundleOfObjects = new bundleOfObjects { Entry = new List() };
MySampleDocument resource_1 = new MySampleDocument(); resource_1.Id = "1005823"; resource_1.Description = "Test 1"; resource_1.Created = "11/20/2017 12:59:47 PM";
bundleOfObjects.AddTobundleOfObjects(resource_1, null); var m_documentWrapperHelperMock = new Mock(); var m_configMock = new Mock();
m_documentWrapperHelperMock.Setup(x => x.GetSampleDocumentsWithOffSets(spec, index, maxNoOfRows, sortFeild)).Returns(bundleOfObjects);
var service = new MySampleDocumentService(m_configMock.Object, m_documentWrapperHelperMock.Object);
Aucun commentaire:
Enregistrer un commentaire