I have tried to use Just Mock with link expression that uses Update All and a Set statement but I keep getting the following error:
Source instance must be an OpenAccess LINQ expression, not an 'System.Linq.EnumerableQuery`1[[IveyCore.Member.MemberLogin, IveyCore, Version=2013.7.18.1916, Culture=neutral, PublicKeyToken=null]]'.
are there any examples of doing this?

public interface IFoo{    IBar GetBar(string x);}public interface IBar{    void DoBar(int x);}public class Tests{    [Fact]    public void First()    {        var foo = Mock.Create<IFoo>();        foo.GetBar("a").DoBar(1);        Mock.Assert(() => foo.GetBar("b").DoBar(1));    }}

Hi. I try to run simple test with JustMock on build machine:
Mock.SetupStatic(typeof(ConsoleApplication1.MyClass));
Mock.Arrange(() => ConsoleApplication1.MyClass.GetNumber()).Returns(777);
Assert.AreEqual(777, ConsoleApplication1.MyClass.GetNumber());
The test failed with message:
«Telerik.JustMock.MockException: Profiler must be enabled to mock/assert target MyClass.GetNumber() method.»
Error Stack Trace:
Telerik.JustMock.Handlers.InterceptorHandler.Create(Object target, MethodInfo methodInfo, Boolean privateMethod)
Telerik.JustMock.MockContext`1.SetupMock(MockExpression`1 expression)
Telerik.JustMock.Mock.<>c__DisplayClass1`1.<Arrange>b__0(MockContext`1 x)
Telerik.JustMock.MockContext.Setup[TDelgate,TReturn](Instruction instruction, Func`2 function)
Telerik.JustMock.Mock.Arrange[TResult](Expression`1 expression)
JustMockTestProject1.JustMockTest1.TestMethod1()
Messages from Event Viewer:
.NET Runtime version 4.0.30319.261 - The profiler was loaded successfully. Profiler CLSID: '{B7ABE522-A68F-44F2-925B-81E7488E9EC0}'. Process ID (decimal): 1044. Message ID: [0x2507].
.NET Runtime version 4.0.30319.261 - Loading profiler failed during CoCreateInstance. Profiler CLSID: '{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}'. HRESULT: 0x80070002. Process ID (decimal): 3028. Message ID: [0x2504].
My build environment:
Windows Server 2008 R2 Standard Service Pack 1
Team Foundation Server - Standard Edition
JustMock Version Q3 2012 (2012.3.1016.3)
To solve this problem I was trying:
Followed this instruction from next link: http://www.telerik.com/help/justmock/integration-code-activity-workflow.html.
But I couldn’t drop JustMockTestRunner activity to build template.
Then I added the text shown below to test project
<Import Project="C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMock.targets" />
<Target Name="BeforeTest">
<JustMockStart />
</Target>
<Target Name="AfterTest">
<JustMockStop />
</Target>
Also I tried to modify workflow template in the way the next post adwises http://www.telerik.com/community/forums/justmock/general-discussions/setupstatic---mockexception-opps-there-were-some-error-intercepting-target-call.aspx#1259708
Also tried this http://www.telerik.com/community/forums/justmock/general-discussions/use-justmock-in-msbuild.aspx#2309253 and this http://www.telerik.com/community/forums/justmock/general-discussions/profiler-must-be-enabled-error.aspx#2254776
So I don’t know what else I can do to run tests on the build environment.
Could you advise some decision?
Best regards,
Eugene Ozerov


public interface IFoo{   event EventHandler<string> Message;}[Fact]public void Sample(){    bool fired = false;    var create = Mock.Create<IFoo>();    create.Message += (o,e) => fired = true;    Mock.Raise(() => create.Message += null, "Test"); //bang    Assert.True(fired);}
StorageAndInventoryService is the class that raises the event. BatchManager is the class subscribed to that event My test:I know that the issue is that we are Mocking as CallOriginal the BatchManager, but we are looking for an alternative, because as you can see is the class that we are trying to unit test. This is the callBack that I want to be executed in the BatchManager class:[TestMethod]publicvoidDestinationUnLockUpdatesBatchesStatus(){batchManager = Mock.Create<BatchManager>(Behavior.CallOriginal);batchManager.StorageInventoryService = Mock.Create<StorageInventoryService>();//Mock dataList<DestinationStatus> destinationStatuses =newList<DestinationStatus>{newDestinationStatus("D1",false, 1, 2,newList<string>())};Mock.Arrange(() => batchManager.StorageInventoryService.GetDestinationStatus(Arg.IsAny<List<string>>())).Returns(destinationStatuses).OccursOnce();batchManager.AddLoadCarrierRequestToBatch(materialFlowContext).Wait();DestinationInfo destinationInfo = batchManager.BatchRepository.GetDestination("D1");List<BatchInfo> batchInfos = batchManager.BatchRepository.GetBatchesByDestination(destinationInfo, 99).ToList();batchManager.SelectAndReserveLoadCarrierRequests(newstring[] {"D1"}).Wait();Assert.IsTrue(destinationInfo.IsAvailable ==false);Assert.IsTrue(batchInfos.FirstOrDefault().Status == BatchStatus.Suspended);MfsLocationLockChangedDataEventArgs mfsLocationLockChangedDataEventArgs =newMfsLocationLockChangedDataEventArgs(newMfsLocationLockChangedData("D1",true,string.Empty));Mock.Raise(() => batchManager.StorageInventoryService.LocationLockChanged +=null, mfsLocationLockChangedDataEventArgs);Assert.IsTrue(batchInfos.FirstOrDefault().Status == BatchStatus.InProgress);}privatevoidStorageInventoryServiceOnLocationLockChanged(objectsender, MfsLocationLockChangedDataEventArgs mfsLocationLockChangedDataEventArgs){Log.Debug("** StorageInventoryServiceOnLocationLockChanged has changed**");if(!mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.IsLocked){DestinationInfo destinationInfo = BatchRepository.GetDestination(mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.AddressName);if(destinationInfo !=null){BatchRepository.UpdateDestinationAvailability(destinationInfo.Address,true);List<BatchInfo> batchInfos = BatchRepository.GetBatchesByDestination(destinationInfo, 99).ToList();foreach(BatchInfo batchinbatchInfos){BatchRepository.UpdateBatchStatus(batch.BatchId, BatchStatus.InProgress);foreach(stringloadCarrierinbatch.LoadCarriers){BatchRepository.UpdateLoadCarrierRequestStatus(loadCarrier, LoadCarrierRequestStatus.New);}}OnDestinationUnLocked(newDestinationStatusChangedEventArgs{Destinations =newList<string>{mfsLocationLockChangedDataEventArgs.MfsLocationLockChangedData.AddressName}});}}}


public interface IMyInterface{   IOther GetOther();}public interface IOther{   int Foo(string test);}[Fact]public void TestMethod(){   var myInterface = Mock.Create<IMyInterface>();       Mock.Assert(() => myInterface.GetOther(), Occurs.Never());   Mock.Arrange(() => myInterface.GetOther().Foo(null)).IgnoreArguments().Returns(1);   Mock.Assert(() => myInterface.GetOther(), Occurs.Never()); // BANG}
************** Exception Text **************
System.MethodAccessException:
UnsafeNativeMethods._AxlGetIssuerPublicKeyHash(IntPtr,
Microsoft.Win32.SafeHandles.SafeAxlBufferHandle ByRef)
   bei
System.Security.Cryptography.X509Certificates.X509Native.UnsafeNativeMethods._AxlGetIssuerPublicKeyHash(IntPtr
pCertContext, SafeAxlBufferHandle& ppwszPublicKeyHash)
   bei System.Security.Cryptography.Xml.ManifestSignedXml.VerifyAuthenticodePublisher(X509Certificate2 publisherCertificate)
   bei
System.Security.Cryptography.Xml.ManifestSignedXml.VerifyAuthenticodeSignature(XmlElement
signatureNode, X509RevocationFlag revocationFlag, X509RevocationMode
revocationMode)
   bei
System.Security.Cryptography.Xml.ManifestSignedXml.VerifySignature(X509RevocationFlag
revocationFlag, X509RevocationMode revocationMode)
   bei
System.Security.Cryptography.ManifestSignatureInformation.VerifySignature(ActivationContext
application, ManifestKinds manifests, X509RevocationFlag
revocationFlag, X509RevocationMode revocationMode)
   bei
Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyCertificateSignature(ActivationContext
context, OnlineOfflineState offlineState, String productName,
DeploymentSignatureInformation& signatureInformation)
   bei
Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySecurity(ActivationContext
context, Uri manifest, AddInInstallationStatus installState)
   bei Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5472 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Runtime.v10.0
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.40305.0
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Runtime.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Runtime.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.40305.0
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.40305.0
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0
    Assembly Version: 9.0.0.0
    Win32 Version: 9.0.30729.5806
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.40305.0
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5468 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Core
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.30729.5420 built by: Win7SP1
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Deployment
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5476 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5476 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Security
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5475 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Security/2.0.0.0__b03f5f7f11d50a3a/System.Security.dll
----------------------------------------
System.Deployment.resources
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase:
file:///C:/Windows/assembly/GAC_MSIL/System.Deployment.resources/2.0.0.0_de_b03f5f7f11d50a3a/System.Deployment.resources.dll
----------------------------------------
mscorlib.resources
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5472 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Xml.Linq
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.30729.5420 built by: Win7SP1
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml.Linq/3.5.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
VSTO Error:
NET Runtime version 2.0.50727.5472 - Failed to CoCreate profiler.
