I've set up a mocked object with a couple of arranged methods. How do I pass in parameters to exercise the arranged methods?
When i call target.GetValue with 5/Aug/2012, the GetData method receives the value of 1/Jan/1983 in its startDate parameter. What do i need to do in order for the arranged methods to receive the required parameter value?
------- set up mocking ------------
var dataAccess = Mock.Create<IDataAccess>();
Mock.Arrange(() => dataAccess.DataExists(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(true);
Mock.Arrange(() => dataAccess.RetrieveData(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(data);
DataLoader target = new DataLoader(dataAccess);
// act
int actual;
actual = target.GetValue(location, date)[0];
-------------------- called method on non-mocked object ---------------
public List<int> GetValue(SiteLocation location, DateTime date)
{
var data = new List<int>();
var temp = GetData(location, date, DateTime.Now);
if (temp.Count > 0)
{
// todo: if there are gaps in the data fill with -999
data = temp.Select(t => t.Value).ToList();
}
else { }
return data;
}
------------------------ called method on mocked object ------------------
public List<DataRecord> GetData(SiteLocation location, DateTime startDate, DateTime endDate)
{
var data = new List<DataRecord>();
if (dataAccess.DataExists(location, startDate, endDate))
{
data = dataAccess.RetrieveData(location, startDate, endDate);
}else{}
return data;
}
When i call target.GetValue with 5/Aug/2012, the GetData method receives the value of 1/Jan/1983 in its startDate parameter. What do i need to do in order for the arranged methods to receive the required parameter value?
------- set up mocking ------------
var dataAccess = Mock.Create<IDataAccess>();
Mock.Arrange(() => dataAccess.DataExists(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(true);
Mock.Arrange(() => dataAccess.RetrieveData(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(data);
DataLoader target = new DataLoader(dataAccess);
// act
int actual;
actual = target.GetValue(location, date)[0];
-------------------- called method on non-mocked object ---------------
public List<int> GetValue(SiteLocation location, DateTime date)
{
var data = new List<int>();
var temp = GetData(location, date, DateTime.Now);
if (temp.Count > 0)
{
// todo: if there are gaps in the data fill with -999
data = temp.Select(t => t.Value).ToList();
}
else { }
return data;
}
------------------------ called method on mocked object ------------------
public List<DataRecord> GetData(SiteLocation location, DateTime startDate, DateTime endDate)
{
var data = new List<DataRecord>();
if (dataAccess.DataExists(location, startDate, endDate))
{
data = dataAccess.RetrieveData(location, startDate, endDate);
}else{}
return data;
}