예제 #1
0
        [InlineData(1, 1, 2)]  // count high
        public async Task OutOfRange_Throws(int length, int offset, int count)
        {
            using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            ArraySegment <byte> buffer = new FakeArraySegment
            {
                Array = new byte[length], Count = count, Offset = offset
            }.ToActual();

            await Assert.ThrowsAnyAsync <ArgumentOutOfRangeException>(() => SendToAsync(socket, buffer, ValidUdpRemoteEndpoint));
        }
예제 #2
0
        [InlineData(1, 1, 1)]  // count high
        public async Task OutOfRange_Throws_ArgumentOutOfRangeException(int length, int offset, int count)
        {
            using var socket = CreateSocket();

            ArraySegment <byte> buffer = new FakeArraySegment
            {
                Array = new byte[length], Count = count, Offset = offset
            }.ToActual();

            await AssertThrowsSynchronously <ArgumentOutOfRangeException>(() => SendToAsync(socket, buffer, GetGetDummyTestEndpoint()));
        }
예제 #3
0
        [InlineData(1, 1, 2)]  // count high
        public void BufferList_InvalidArguments_Throws(int length, int offset, int count)
        {
            using (var e = new SocketAsyncEventArgs())
            {
                ArraySegment <byte> invalidBuffer = new FakeArraySegment {
                    Array = new byte[length], Offset = offset, Count = count
                }.ToActual();
                Assert.Throws <ArgumentOutOfRangeException>(() => e.BufferList = new List <ArraySegment <byte> > {
                    invalidBuffer
                });

                ArraySegment <byte> validBuffer = new ArraySegment <byte>(new byte[1]);
                Assert.Throws <ArgumentOutOfRangeException>(() => e.BufferList = new List <ArraySegment <byte> > {
                    validBuffer, invalidBuffer
                });
            }
        }
예제 #4
0
        [InlineData(1, 1, 2)]    // count high
        public async Task InvalidArguments_Throws(int?length, int offset, int count)
        {
            if (length == null && !ValidatesArrayArguments)
            {
                return;
            }

            using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                Type expectedExceptionType = length == null ? typeof(ArgumentNullException) : typeof(ArgumentOutOfRangeException);

                var validBuffer   = new ArraySegment <byte>(new byte[1]);
                var invalidBuffer = new FakeArraySegment {
                    Array = length != null ? new byte[length.Value] : null, Offset = offset, Count = count
                }.ToActual();

                await Assert.ThrowsAsync(expectedExceptionType, () => ReceiveAsync(s, invalidBuffer));

                await Assert.ThrowsAsync(expectedExceptionType, () => ReceiveAsync(s, new List <ArraySegment <byte> > {
                    invalidBuffer
                }));

                await Assert.ThrowsAsync(expectedExceptionType, () => ReceiveAsync(s, new List <ArraySegment <byte> > {
                    validBuffer, invalidBuffer
                }));

                await Assert.ThrowsAsync(expectedExceptionType, () => SendAsync(s, invalidBuffer));

                await Assert.ThrowsAsync(expectedExceptionType, () => SendAsync(s, new List <ArraySegment <byte> > {
                    invalidBuffer
                }));

                await Assert.ThrowsAsync(expectedExceptionType, () => SendAsync(s, new List <ArraySegment <byte> > {
                    validBuffer, invalidBuffer
                }));
            }
        }