Created
January 7, 2012 18:29
-
-
Save Rookian/1575568 to your computer and use it in GitHub Desktop.
The current proxy generator can not intercept the specified method for the following reason: - Sealed methods can not be intercepted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UnitOfWork : IUnitOfWork | |
{ | |
private ObjectContext _db; | |
public UnitOfWork(ObjectContext db) | |
{ | |
_db = db; | |
} | |
public void Commit() | |
{ | |
_db.SaveChanges(); | |
} | |
public void Dispose() | |
{ | |
_db.Dispose(); | |
_db = null; | |
} | |
} | |
[Subject(typeof(BaseForm<>))] | |
public class When_disposing_form | |
{ | |
static PosForm PosForm; | |
static ObjectContext ObjectContext; | |
private static IUnitOfWork UnitOfWork; | |
private static IPosDeviceRepository PosDeviceRepository; | |
Establish context = () => | |
{ | |
ObjectContext = new ErsManagementEntities(); | |
UnitOfWork = A.Fake<UnitOfWork>(x => x.WithArgumentsForConstructor( | |
() => new UnitOfWork(ObjectContext))); | |
PosDeviceRepository = new PosDeviceRepository(ObjectContext); | |
}; | |
Because of = () => | |
{ | |
using (PosForm = new PosForm(null, null, null, null, UnitOfWork, PosDeviceRepository, null, null, null)) | |
{ | |
} | |
}; | |
It should_dispose_object_context = () => A.CallTo(() => UnitOfWork.Dispose()).MustHaveHappened(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Das ist eher eine Usability Issue (kannst sie trotzdem gerne reporten). Ich habe FIE selbst kompiliert, das ist die Exception die der Dynamic Proxy Generator von Castle wirft:
Due to limitations in CLR, DynamicProxy was unable to successfully replicate non-inheritable attribute System.Security.Permissions.UIPermissionAttribute on ClassLibrary2.BaseForm`1[[ClassLibrary2.IEntity, ClassLibrary2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].ProcessMnemonic. To avoid this error you can chose not to replicate this attribute type by calling 'Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(System.Security.Permissions.UIPermissionAttribute))'.
Sie wird dann fälschlicherweise in die Exception die du bekommst "umgewandelt" und damit maskiert. Zugriff auf die korrekte
InnerException
wäre hier praktisch.Befolgt man den Hinweis aus dem Exception Text geht's übrigens gleich weiter mit
TargetInvocationException
die eineNullReferenceException
beinhaltet. Grund hierfür ist dass derctor
vonForm
auf irgendwelche Properties zugreift die nicht initialisiert sind (konkret:DefaultMargin
):Merke: Windows Forms zu faken is nich.