public void UsingDisposedObject_Throws() { var cache = new CameraCache <int>(); cache.Dispose(); Assert.Throws <System.ObjectDisposedException>(() => cache.GetOrCreate(0, 0)); Assert.Throws <System.ObjectDisposedException>(() => cache.ClearCamerasUnusedFor(0, 0)); Assert.Throws <System.ObjectDisposedException>(() => cache.Clear()); Assert.Throws <System.ObjectDisposedException>(() => cache.Dispose()); }
public void GetOrCreate_And_Dispose_Works() { var cache = new CameraCache <int>(); // Create the camera var camera = cache.GetOrCreate(0, 0); Assert.IsNotNull(camera); // Get the same camera var sameCamera = cache.GetOrCreate(0, 0); Assert.IsNotNull(sameCamera); Assert.True(ReferenceEquals(camera, sameCamera)); Assert.AreEqual(camera.GetInstanceID(), sameCamera.GetInstanceID()); // Get another camera var otherCamera = cache.GetOrCreate(1, 0); Assert.IsNotNull(otherCamera); Assert.False(ReferenceEquals(camera, otherCamera)); Assert.AreNotEqual(camera.GetInstanceID(), otherCamera.GetInstanceID()); // Clear the cameras cache.Dispose(); // Assert the cameras are destroyed on the C++ side Assert.True(camera.Equals(null)); Assert.True(sameCamera.Equals(null)); Assert.True(otherCamera.Equals(null)); }