Пример #1
0
        public void when_disposed_then_disposes_all_items()
        {
            // ACT
            _disposableCollection.Dispose();

            // ASSERT
            Assert.True(_disposable1.HasBeenDisposed);
            Assert.True(_disposable2.HasBeenDisposed);
        }
		public void Dispose_Count_IsEmpty()
		{
			var collection = new DisposableCollection();
			collection.Dispose();
			var count = collection.Count;
			Assert.AreEqual(0, count);
		}
Пример #3
0
        static void Main(string[] args)
        {
            using (var token = event1.Register(Event1))
            {
                event1.Invoke();         // Outputs "Received event1!"
            }
            event1.Invoke();             // Outputs nothing

            var token1 = event2.Register(x => Console.WriteLine("Got: " + x));
            var token2 = event2.Register(x => Console.WriteLine("Really got: " + x));
            var token3 = event2.Register(x => Console.WriteLine("Yes! I've got: " + x));

            event2.Invoke("Ham");             // Outputs "Got: Ham", "Really got: Ham", "Yes! I've got: Ham"

            token2.Dispose();

            event2.Invoke("Ham");             // Outputs "Got: Ham", "Yes! I've got: Ham"

            var tokens = new DisposableCollection();

            tokens.Add(token1);
            tokens.Add(token3);

            tokens.Dispose();

            event2.Invoke("Milk?");             // Outputs nothing
        }
Пример #4
0
        public void TestDisposing()
        {
            var disposable  = new Disposable();
            var disposables = new DisposableCollection(disposable);

            disposables.Dispose();
            Assert.True(disposable.IsDisposed);
        }
		public void Add_Dispose()
		{
			var collection = new DisposableCollection();

			var disposable = new Mock<IDisposable>(MockBehavior.Strict);
			disposable.Setup(_ => _.Dispose());
			collection.Add(disposable.Object);

			collection.Dispose();
			disposable.Verify(_ => _.Dispose(), Times.Once);
			Assert.AreEqual(0, collection.Count);
		}
Пример #6
0
        public void TestObjectDisposedException()
        {
            var c = new DisposableCollection();

            c.Dispose();
            c.Dispose(); // second call should have no effect

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Add(new MockDisposable()));

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Clear());

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Contains(new MockDisposable()));

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.GetEnumerator());

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Remove(new MockDisposable()));
        }
Пример #7
0
        public void Throws_ObjectDisposedException()
        {
            var d1 = new Component();
            var collection = new DisposableCollection {d1};
            collection.Dispose();

            Assert.Throws<ObjectDisposedException>(() => collection.Add(d1));
            Assert.Throws<ObjectDisposedException>(() => collection.Insert(0, d1));

            // Cannot test object disposed exception for removal, as the collection
            // is empty after it has been disposed.
            Assert.AreEqual(0, collection.Count);
        }
        protected override void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing && _disposeTexturesWhenClose)
            {
                _textures.Dispose();
            }

            _isDisposed = true;
        }
Пример #9
0
 public void EndGame(Side winner)
 {
     Debug.LogFormat("End multiplayer game, winner: {0}", winner);
     if (winner == Side.Bottom)
     {
         Model.CheckBestScore();
     }
     OnGameOver.Dispatch(winner);
     if (Model.IsHost)
     {
         _netService.SendGameOver(winner);
     }
     _disposableCollection.Dispose();
 }
Пример #10
0
        public void Dispose_DoubleDisposeWorks()
        {
            var expected = new TestDisposableObject();

            //Act
            using (var target = new DisposableCollection())
            {
                target.Add(expected);

                target.Dispose();
            };

            //Assert
            expected.IsDisposed.Should().BeTrue();
        }
Пример #11
0
        public void DisposableCollection_Dispose()
        {
            _count = 0;

            DisposableCollection <Dummy> collection
                = new DisposableCollection <Dummy>
                {
                new Dummy(),
                new Dummy(),
                new Dummy()
                };

            collection.Dispose();

            Assert.AreEqual(3, _count);
        }
Пример #12
0
        public void TestBasicDisposal()
        {
            var d1 = new MockDisposable();
            var d2 = new MockDisposable();

            Assert.IsFalse(d1.Disposed);
            Assert.IsFalse(d2.Disposed);

            var coll = new DisposableCollection {
                d1, d2
            };

            coll.Dispose();

            Assert.IsTrue(d1.Disposed);
            Assert.IsTrue(d2.Disposed);
        }
Пример #13
0
        public void Add_and_dispose()
        {
            var collection = new DisposableCollection();
            var d1 = new Component();
            var d2 = new DodgyDisposable();
            var d3 = new Component();

            collection.Add(d1);
            collection.Add(d2);
            collection.Add(d3);

            var d1Disposed = false;
            d1.Disposed += (sender, args) => d1Disposed = true;
            var d3Disposed = false;
            d3.Disposed += (sender, args) => d3Disposed = true;

            Assert.IsFalse(collection.IsDisposed);
            collection.Dispose();
            Assert.IsTrue(collection.IsDisposed);
            Assert.IsTrue(d1Disposed);
            Assert.IsTrue(d3Disposed);
            Assert.AreEqual(1, d2.DisposeCount);
        }
Пример #14
0
 public void TearDown()
 {
     _disposables.Dispose();
 }
		public void Dispose_Add_Fail()
		{
			var collection = new DisposableCollection();
			collection.Dispose();
			collection.Add(Disposable.Empty);
		}
Пример #16
0
 public void Dispose()
 {
     _bindings.Dispose();
     _appliedBindings.Dispose();
 }
		public void Dispose_Remove_Fail()
		{
			var collection = new DisposableCollection();
			collection.Dispose();
			collection.Remove(Disposable.Empty);
		}
		public void Dispose_Reverse()
		{
			var order = String.Empty;
			var collection = new DisposableCollection();

			const int count = 6;
			for (var i = 1; i <= count; ++i)
			{
				var local = i;
				var disposable = new Mock<IDisposable>(MockBehavior.Strict);
				disposable.Setup(_ => _.Dispose()).Callback(() => order += local);
				collection.Add(disposable.Object);
			}

			Assert.AreEqual(count, collection.Count);
			collection.Dispose();

			Assert.AreEqual(0, collection.Count);
			Assert.AreEqual("654321", order);
		}
		public void Dispose_Clear_Fail()
		{
			var collection = new DisposableCollection();
			collection.Dispose();
			collection.Clear();
		}
Пример #20
0
        private IDisposable SetupOpenCL(out Context context, out Device device, out CommandQueue commandQueue, out Kernel kernel, out Kernel kernel4, bool runOnGPU, bool useRelaxedMath, bool enableProfiling)
        {
            var disposables = new DisposableCollection <IDisposable>(true);

            try
            {
                string buildOptions = "-cl-fast-relaxed-math";

                if (runOnGPU)
                {
                    Console.WriteLine("Trying to run on a processor graphics");
                }
                else
                {
                    Console.WriteLine("Trying to run on a CPU");
                }

                Platform platform = GetIntelOpenCLPlatform();
                Assert.IsNotNull(platform, "Failed to find Intel OpenCL platform.");

                // create the OpenCL context
                if (runOnGPU)
                {
                    Device[] devices = platform.GetDevices(DeviceType.Gpu);
                    device  = devices[0];
                    context = Context.Create(device);
                    disposables.Add(context);
                }
                else
                {
                    Device[] devices = platform.GetDevices(DeviceType.Cpu);
                    device  = devices[0];
                    context = Context.Create(device);
                }

                commandQueue = context.CreateCommandQueue(device, enableProfiling ? CommandQueueProperties.ProfilingEnable : 0);
                disposables.Add(commandQueue);

                string  source  = @"
__kernel void
SimpleKernel( const __global float *input, __global float *output)
{
    size_t index = get_global_id(0);
    output[index] = rsqrt(fabs(input[index]));
}

__kernel /*__attribute__((vec_type_hint(float4))) */ void
SimpleKernel4( const __global float4 *input, __global float4 *output)
{
    size_t index = get_global_id(0);
    output[index] = rsqrt(fabs(input[index]));
}
";
                Program program = context.CreateProgramWithSource(source);
                disposables.Add(program);

                program.Build(useRelaxedMath ? buildOptions : null);
                kernel = program.CreateKernel("SimpleKernel");
                disposables.Add(kernel);

                kernel4 = program.CreateKernel("SimpleKernel4");
                disposables.Add(kernel4);

                Console.WriteLine("Using device {0}...", device.Name);
                Console.WriteLine("Using {0} compute units...", device.MaxComputeUnits);
                Console.WriteLine("Buffer alignment required for zero-copying is {0} bytes", device.MemoryBaseAddressAlignment);
            }
            catch
            {
                disposables.Dispose();
                throw;
            }

            return(disposables);
        }
		public void Add_Remove_Dispose()
		{
			var collection = new DisposableCollection();

			var disposable = new Mock<IDisposable>(MockBehavior.Strict);
			disposable.Setup(_ => _.Dispose());
			collection.Add(disposable.Object);

			var contains = collection.Remove(disposable.Object);
			Assert.IsTrue(contains);

			collection.Dispose();
			disposable.Verify(_ => _.Dispose(), Times.Never);
			Assert.AreEqual(0, collection.Count);
		}
Пример #22
0
 public void Dispose()
 {
     _disposableCollection.Dispose();
 }
Пример #23
0
        private IDisposable SetupOpenCL(out Context context, out Device device, out CommandQueue commandQueue, out Kernel kernel, out Kernel kernel4, bool runOnGPU, bool useRelaxedMath, bool enableProfiling)
        {
            DisposableCollection<IDisposable> disposables = new DisposableCollection<IDisposable>(true);
            try
            {
                string buildOptions = "-cl-fast-relaxed-math";

                if (runOnGPU)
                    Console.WriteLine("Trying to run on a processor graphics");
                else
                    Console.WriteLine("Trying to run on a CPU");

                Platform platform = GetIntelOpenCLPlatform();
                Assert.IsNotNull(platform, "Failed to find Intel OpenCL platform.");

                // create the OpenCL context
                if (runOnGPU)
                {
                    Device[] devices = platform.GetDevices(DeviceType.Gpu);
                    device = devices[0];
                    context = Context.Create(device);
                    disposables.Add(context);
                }
                else
                {
                    Device[] devices = platform.GetDevices(DeviceType.Cpu);
                    device = devices[0];
                    context = Context.Create(device);
                }

                commandQueue = context.CreateCommandQueue(device, enableProfiling ? CommandQueueProperties.ProfilingEnable : 0);
                disposables.Add(commandQueue);

                string source = @"
            __kernel void
            SimpleKernel( const __global float *input, __global float *output)
            {
            size_t index = get_global_id(0);
            output[index] = rsqrt(fabs(input[index]));
            }

            __kernel /*__attribute__((vec_type_hint(float4))) */ void
            SimpleKernel4( const __global float4 *input, __global float4 *output)
            {
            size_t index = get_global_id(0);
            output[index] = rsqrt(fabs(input[index]));
            }
            ";
                Program program = context.CreateProgramWithSource(source);
                disposables.Add(program);

                program.Build(useRelaxedMath ? buildOptions : null);
                kernel = program.CreateKernel("SimpleKernel");
                disposables.Add(kernel);

                kernel4 = program.CreateKernel("SimpleKernel4");
                disposables.Add(kernel4);

                Console.WriteLine("Using device {0}...", device.Name);
                Console.WriteLine("Using {0} compute units...", device.MaxComputeUnits);
                Console.WriteLine("Buffer alignment required for zero-copying is {0} bytes", device.MemoryBaseAddressAlignment);
            }
            catch
            {
                disposables.Dispose();
                throw;
            }

            return disposables;
        }
 public void TearDown()
 {
     _disposableCollection.Dispose();
 }
Пример #25
0
 public void Dispose()
 {
     _tokens?.Dispose();
 }