I'm attempting to mock an ObjectStateEntry from EF4. Unfortunately, it fails at runtime when I create the mocked object. This is my first time using JustMock (although I've done some very basic tests successfully) so I could have something setup/configured incorrectly. I'd appreciate some help getting this to work.
This compiles just fine but has a runtime error:
I'm working towards the following test:
... so that I can perform tests on the commented-out line. However, since I can't even create the mocked object, this is rather difficult...
var mockedEntry = Mock.Create<ObjectStateEntry>();
This compiles just fine but has a runtime error:
TestCase 'Foo'
failed: System.TypeLoadException : Method 'set_EntityKey' in type 'ObjectStateEntry_Proxy_1f0c098e8cf2440f9eb3e6c8fa6abb46' from assembly 'Telerik.JustMock, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8b221631f7271365' does not have an implementation.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\TypeEmitter.cs(287,0): at ..()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\Proxy.cs(87,0): at Telerik.JustMock.DynamicProxy.Proxy.()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\ProxyFactory.cs(78,0): at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\Fluent\FluentProxy.cs(72,0): at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\DynamicProxy\Proxy.cs(81,0): at Telerik.JustMock.DynamicProxy.Proxy.Create(Type target, Action`1 action)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\MockObject.cs(149,0): at ..(Type target, Container container, Object[] args)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\MockObject.cs(123,0): at ..(Type target, Container container, Object[] args, Boolean profilerEnabled)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\MockObject.cs(97,0): at ..(Type target, Behavior behavior, Boolean static, Object[] args)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\MockObject.cs(44,0): at ..get_Instance()
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs(485,0): at Telerik.JustMock.Mock.Create(Type target, Behavior mode, Object[] args)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs(427,0): at Telerik.JustMock.Mock.Create(Type target, Object[] args)
c:\B\Basilisk\Basilisk CI Build\Sources\CodeBase\Telerik.JustMock\Mock.cs(416,0): at Telerik.JustMock.Mock.Create[T]()
ExtensionMethods\ObjectStateEntryExtensionsTests.cs(39,0): at EG.Framework.EntityFramework.Tests.ExtensionMethods.ObjectStateEntryExtensionsTests.Does_UpdateAllEntityAuditFieldsAndCancelDeletes_Properly_Cancel_Deletes()
0 passed, 1 failed, 0 skipped, took 1.00 seconds (NUnit 2.5.5).
I'm working towards the following test:
// Arrange
var mockedEntry = Mock.Create<ObjectStateEntry>();
var entity =
new
ObjectWithAuditFields();
Mock.Arrange(() => mockedEntry.State).Returns(EntityState.Deleted);
Mock.Arrange(() => mockedEntry.Entity).Returns(entity);
Mock.Arrange(() => mockedEntry.EntityKey).IgnoreArguments();
Mock.Arrange(() => mockedEntry.ChangeState(EntityState.Modified))
.DoInstead(() => Mock.Arrange(() => mockedEntry.State).Returns(EntityState.Modified));
// Act
//mockedEntry.UpdateAllEntityAuditFieldsAndCancelDeletes(44);
mockedEntry.ChangeState(EntityState.Modified);
// Assert
Assert.IsTrue(mockedEntry.State == EntityState.Modified);
... so that I can perform tests on the commented-out line. However, since I can't even create the mocked object, this is rather difficult...