Hi I am trying to mock a Property that is of type DataServiceQuery<EntityLock> like this:
as soon as I try to execute this line I am getting the next exception:
Initialization method Tgw.Wcs.Windows.U.Test.ComponentTests.Modules.LoadCarriers.LocksViewModelTest.TestInitialize threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'System.Data.Services.Client.DataServiceQuery`1' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I have also tried not to Mock this property and initialize it in the constructor of the class that I am trying to test:
here is part of the constructor:
And here is part of my InitializeTest:
locksViewModel.Query = Mock.Create<DataServiceQuery<EntityLock>>();
Initialization method Tgw.Wcs.Windows.U.Test.ComponentTests.Modules.LoadCarriers.LocksViewModelTest.TestInitialize threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'System.Data.Services.Client.DataServiceQuery`1' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I have also tried not to Mock this property and initialize it in the constructor of the class that I am trying to test:
here is part of the constructor:
public
LocksViewModel(IEnumerable<LoadCarrier> selectedLoadCarriers, ILoadCarrierRepository loadCarrierRepository)
{
if
(selectedLoadCarriers !=
null
&& loadCarrierRepository !=
null
)
{
DataContext = loadCarrierRepository.DataModelServiceContext;
Query = (DataServiceQuery<EntityLock>)loadCarrierRepository.GetEntityLocks(selectedLoadCarriers.Select(x=>x.Id));
And here is part of my InitializeTest:
And I am getting this exception: Initialization method Tgw.Wcs.Windows.U.Test.ComponentTests.Modules.LoadCarriers.LocksViewModelTest .TestInitialize threw exception. System.InvalidCastException: System.InvalidCastException: Unable to cast object of type 'Castle.Proxies.IQueryable`1Proxy' to type 'System.Data.Services.Client.DataServiceQuery`1[Tgw.Wcs.Windows.Data.UIModel.EntityLock]'..IQueryable<EntityLock> entityLocks = Mock.Create<IQueryable<EntityLock>>();
LoadCarrierRepository loadCarrierRepository = Mock.Create<LoadCarrierRepository>();
loadCarrierRepository.DataContext = Mock.Create<ClientDataModelServiceContext>();
Mock.Arrange(() => loadCarrierRepository.GetEntityLocks(Arg.IsAny<IEnumerable<Guid>>())).ReturnsCollection(entityLocks);
Mock.Arrange(() => loadCarrierRepository.GetLockReasons()).ReturnsCollection(
new
List<
string
> {
"fooLockReason1"
,
"fooLockReason2"
});
locksViewModel =
new
LocksViewModel(
new
ObservableCollectionEx<LoadCarrier>() { loadCarrier }, loadCarrierRepository);