Example #1
0
        public void when_remove_existing_item_then_disposes_item_being_removed()
        {
            // ACT
            _disposableCollection.Remove(_disposable1);

            // ASSERT
            Assert.True(_disposable1.HasBeenDisposed);
        }
Example #2
0
        private void HandleDataReceived(IAsyncResult ar)
        {
            int bytesRead = 0;

            byte[] message = new byte[0];
            if (IsRunning && ((Player)ar.AsyncState).Tcp.Connected)
            {
                var _Session = (Player)ar.AsyncState;
                var _Stream  = _Session.NetworkStream;

                try
                {
                    bytesRead = _Stream.EndRead(ar);
                    //verifica se o tamanho do pacote é zero
                    if (bytesRead == 0)
                    {
                        lock (m_Clients)
                        {
                            m_Clients.Remove(_Session);

                            OnClientDisconnected(_Session);
                            return;
                        }
                    }

                    //variável para armazenar a mensagem recebida
                    message = new byte[bytesRead];

                    //Copia mensagem recebida
                    Buffer.BlockCopy(MsgBufferRead, 0, message, 0, bytesRead);

                    s_AllReceBytes += bytesRead;
                    //ler o proximo pacote(se houver)
                    _Stream.BeginRead(MsgBufferRead, 0, MsgBufferRead.Length, HandleDataReceived, _Session);
                }
                catch
                {
                    lock (m_Clients)
                    {
                        m_Clients.Remove(_Session);

                        OnClientDisconnected(_Session);
                        return;
                    }
                }

                //checa se o tamanho da mensagem é zerada
                if (message.Length > 0)
                {
                    var packet = new Packet(message, _Session.Key);
                    //Dispara evento OnPacketReceived
                    PlayerRequestPacket(_Session, packet);
                }
            }
        }
Example #3
0
        public IDisposable Apply()
        {
            while (_bindings.Count > 0)
            {
                var binding = _bindings[0];

                if (binding.Apply())
                {
                    _appliedBindings.Add(binding);
                }

                _bindings.Remove(binding);
            }

            return(this);
        }
        public void Remove_DisposesOfItem()
        {
            var target = new DisposableCollection();
            var item   = new TestDisposableObject();

            //Act
            target.Add(item);
            var actual = target.Remove(item);

            //Assert
            actual.Should().BeTrue();
            item.IsDisposed.Should().BeTrue();
        }
Example #5
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()));
        }
		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);
		}
		public void Dispose_Remove_Fail()
		{
			var collection = new DisposableCollection();
			collection.Dispose();
			collection.Remove(Disposable.Empty);
		}