I receive the error:
Test method Ryland.Crm.Plugins.Tests.ContactRequiredFieldsPluginTest.ExecuteRequiredFieldTelerikTest threw exception System.AccessViolationException, but exception Microsoft.Crm.Sdk.InvalidPluginExecutionException was expected. Exception message: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Telerik.DynamicProxy.ProxyFactory.Create()
Telerik.DynamicProxy.Fluent.FluentProxy.NewInstance()
Telerik.DynamicProxy.Proxy.Create(Type target, Action`1 action)
ctor(Type target, BehaviorMode mode, Object[] args)
Telerik.JustMock.Mock.Create(Type target, BehaviorMode mode, Object[] args)
Telerik.JustMock.Mock.Create(Type target, Object[] args)
Telerik.JustMock.Mock.Create[T]()
Ryland.Crm.Plugins.Tests.ContactRequiredFieldsPluginTest.ExecuteRequiredFieldTelerikTest() in C:\projects\RylandStandards\RylandStandards\tests\Ryland.Crm.Plugins.Tests\ContactRequiredFieldsPluginTest.cs: line 58
My code is below. Also note I am running on a Hyper-V Guest and do have references to other Mocking frameworks in the project since I am comparing and contrasting Rhino Mocks, Moq and JustMock. I have JustMock enabled. The Microsoft Crm sdk contains the IPluginExecutionContext and only the sdk is needed to test this scenario, not Crm.
If the syntax below works for this test, I will definitely recommend this framework. The simplicity is great compared to RhinMocks and slightly better than Moq. Understanding the API is important to adoption and the ability to avoid needing different calls for stubbing or mocking is very nice. I also am assuming the typical Create will essentially cause properties to behave like simple get/set properties without any setup.
///
<summary>
///
///</summary>
[
TestMethod()]
[
ExpectedException(typeof(InvalidPluginExecutionException))]
public void ExecuteRequiredFieldTelerikTest()
{
ContactRequiredFieldsPlugin target = new ContactRequiredFieldsPlugin(string.Empty, string.Empty);
var context = TelerikMock.Mock.Create<IPluginExecutionContext>(); //!!!!!!!!! Fails here
var service = TelerikMock.Mock.Create<ICrmService>();
TelerikMock.Mock.Arrange(() => context.CreateCrmService(true)).Returns(service);
DynamicEntity
entity = new DynamicEntity(EntityName.contact.ToString());
entity.Properties.Add(
new StringProperty("telephone1", ""));
entity.Properties.Add(
new StringProperty("emailaddress1", ""));
context.InputParameters[
ParameterName.Target] = entity;
target.Execute(context);
}