-
-
Save Rookian/1575568 to your computer and use it in GitHub Desktop.
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(); | |
} |
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 eine NullReferenceException
beinhaltet. Grund hierfür ist dass der ctor
von Form
auf irgendwelche Properties zugreift die nicht initialisiert sind (konkret: DefaultMargin
):
at Castle.Proxies.BaseForm`1Proxy.get_DefaultMargin()
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.Control..ctor()
at System.Windows.Forms.ScrollableControl..ctor()
at System.Windows.Forms.ContainerControl..ctor()
at System.Windows.Forms.Form..ctor()
at ClassLibrary2.BaseForm`1..ctor(IUnitOfWork uow, IRepository`1 repository) in D:\Users\agross\Coding\.NET\ClassLibrary2\ClassLibrary2\Class1.cs:line 19
at Castle.Proxies.BaseForm`1Proxy..ctor(IInterceptor[] , IUnitOfWork , IRepository`1 )
Merke: Windows Forms zu faken is nich.
Ja an der liegt es. Für mich scheint es so als ob FakeItEasy da nen Bug hat.