示例#1
0
 public void PacketStreamWriteWhenReadOnlyTest()
 {
     using (ILitePacketStream packetStream = new LitePacketStream(_randomizer.Bytes(_randomizer.Byte())))
     {
         Assert.Throws <InvalidOperationException>(() => packetStream.Write <byte>(_randomizer.Byte()));
     }
 }
示例#2
0
 public void PacketStreamReadNonPrimitiveTest()
 {
     using (var packetStream = new NetPacketStream(_randomizer.Bytes(_randomizer.Byte())))
     {
         Assert.Throws <NotImplementedException>(() => packetStream.Read <object>());
     }
 }
 public NetServerClientTests()
 {
     _randomizer          = new Randomizer((int)DateTime.UtcNow.Ticks);
     _serverConfiguration = new NetServerConfiguration("127.0.0.1", 4444);
     _serverMock          = new NetServerMock <CustomClient>(_serverConfiguration);
     _customClient        = new CustomClient(null)
     {
         Server = _serverMock.Object
     };
     _otherClient       = new CustomClient(null);
     _customClientsList = Enumerable.Repeat(new CustomClient(null), _randomizer.Byte());
     _packet            = new NetPacket();
     _packet.Write(_randomizer.String(_randomizer.Byte()));
 }
示例#4
0
        public async Task SendPacketTest()
        {
            byte[] message = _randomizer.Bytes(_randomizer.Byte());

            _clientMock.SocketMock.ConfigureSendResult(false); // Instant send

            _sender.Start();
            _sender.Send(new NetMessageData(_clientMock.Object, message));

            // Wait 1 second so the sender task can process the previous message.
            await Task.Delay(1000).ConfigureAwait(false);

            _clientMock.SocketMock.VerifySend(It.IsAny <SocketAsyncEventArgs>(), Times.Once());

            _sender.Stop();
            Assert.False(_sender.IsRunning);
        }
示例#5
0
 public void generate_a_byte()
 {
     r.Byte(1, 128).Should().Be(78);
 }
示例#6
0
 public void Byte_range_is_inclusive()
 {
     CanReturn(() => _randomizer.Byte(byte.MaxValue - 10, byte.MaxValue), byte.MaxValue);
     CanReturn(() => _randomizer.Byte(byte.MinValue, byte.MinValue + 10), byte.MinValue);
 }