public void ResolveReference_NonReferenced_ReturnNull() { ClientReferenceResolver clientReferenceResolver = new ClientReferenceResolver(); var mockObject = new MockProxy(); var proxy = clientReferenceResolver.ResolveReference(this, mockObject.DtoGuid.ToString()); Assert.IsNull(proxy); }
public void ResolveReferenceGuid_NonReferenced_ReturnNull() { ClientReferenceResolver clientReferenceResolver = new ClientReferenceResolver(); PrivateObject po = new PrivateObject(clientReferenceResolver); var mockObject = new MockProxy(); var proxy = clientReferenceResolver.ResolveReference(mockObject.DtoGuid); Assert.IsNull(proxy, "Proxy not null!"); }
public void ResolveReferenceGuid_Referenced_ReturnProxy() { ClientReferenceResolver clientReferenceResolver = new ClientReferenceResolver();; PrivateObject po = new PrivateObject(clientReferenceResolver); var mockObject = new MockProxy(); clientReferenceResolver.AddReference(this, mockObject.DtoGuid.ToString(), mockObject); var proxy = clientReferenceResolver.ResolveReference(mockObject.DtoGuid); Assert.AreEqual(mockObject, proxy, "Object are not the same!"); }
public void ResolveReference_ReferencedAlive_ReturnDto() { ClientReferenceResolver clientReferenceResolver = new ClientReferenceResolver(); var mockObject = new MockProxy(); clientReferenceResolver.AddReference(this, mockObject.DtoGuid.ToString(), mockObject); var proxy = clientReferenceResolver.ResolveReference(this, mockObject.DtoGuid.ToString()); Assert.AreEqual(mockObject, proxy); }
public void ResolveReference_ReferenceFinalized_ReturnDto() { ClientReferenceResolver clientReferenceResolver = new ClientReferenceResolver(); WeakReference <ProxyObjectBase> weakReference = null; Guid guid = Guid.Empty; new Action(() => { var mockObject = new MockProxy { DtoGuid = Guid.NewGuid() }; weakReference = new WeakReference <ProxyObjectBase>(mockObject, true); clientReferenceResolver.AddReference(this, mockObject.DtoGuid.ToString(), mockObject); guid = new Guid(mockObject.DtoGuid.ToString()); })(); GC.Collect(); GC.WaitForPendingFinalizers(); if (ProxyObjectBase.FinalizeRequested.Count < 1) { Assert.Fail("Object did not finalize or finalized instantly"); } new Action(() => { ProxyObjectBase.FinalizeRequested.TryGetValue(guid, out var target); if (target == null) { Assert.Fail("Guid mismatch"); } target.Resurrect(); var proxy = clientReferenceResolver.ResolveReference(guid); Assert.AreEqual(target, proxy, "Proxy did not resurrected properly"); })(); GC.Collect(); GC.WaitForPendingFinalizers(); new Action(() => { if (ProxyObjectBase.FinalizeRequested.ContainsKey(guid)) { ProxyObjectBase.FinalizeRequested.TryGetValue(guid, out var target); target.FinalizeProxy(); } else { Assert.Fail("Could not final finalize. Object not found in FinalizeRequested collection."); } })(); GC.Collect(); GC.WaitForPendingFinalizers(); if (ProxyObjectBase.FinalizeRequested.Count > 0 && !weakReference.TryGetTarget(out _)) { Assert.Fail("Object did not finalize properly."); } }