我正在用 Moq 做一些单元测试,我想做相当于:
Location location = new Location();
LocationTimes locationTimes = new LocationTimes();
location.LocationTimes.Add(locationTimes);
所以我尝试了这个:
var mockLocation = new Mock<Location>();
var mockLocationTime = new Mock<LocationTimes>();
mockLocationTime.SetupProperty(f => f.isEarlyHoursSupported, true);
mockLocationTime.SetupProperty(f => f.isEarlyHoursSupportedManual, true);
var mockLocationTimeList = new List<Mock<LocationTimes>>();
mockLocationTimeList.Add(mockLocationTime);
this.mockLocation1 = new Mock<Location>();
mockLocation1.SetupProperty(f => f.LocationTimes, mockLocationTimeList);
...但我在最后一行出现错误,因为 mockLocationTimeList 现在是一个起订量列表。
我该怎么做?