Beispiel #1
0
        public void TrimZeroTerminationCharacters()
        {
            var bytes       = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x00 };
            var valueReader = new DhcpBinaryValue(bytes, 0, bytes.Length);

            Assert.Equal("Hello", valueReader.AsString());
        }
Beispiel #2
0
        public void ReturnAsciiRepresentationOfBytes()
        {
            var bytes       = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            var valueReader = new DhcpBinaryValue(bytes, 0, bytes.Length);

            Assert.Equal("Hello", valueReader.AsString());
        }
Beispiel #3
0
        public void ReadValueFromGivenOffset()
        {
            var bytes       = new byte[] { 0x00, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            var valueReader = new DhcpBinaryValue(bytes, 3, 5);

            Assert.Equal("Hello", valueReader.AsString());
        }
        public void ThrowInvalidOperationException_GivenInvalidLength(byte length)
        {
            var valueReader = new DhcpBinaryValue(TestBytes, 0, length);

            Assert.Throws <InvalidOperationException>(
                () => valueReader.AsInt32());
        }
Beispiel #5
0
        public void ThrowArgumentOutOfRange_GivenOffsetAndLengthExceedingLimit()
        {
            var binaryValue = new DhcpBinaryValue(Bytes, 0, 3);

            Assert.Throws <ArgumentOutOfRangeException>(
                () => binaryValue.CreateSubsetValue(2, 2));
        }
Beispiel #6
0
        public void ThrowArgumentOutOfRange_GivenOffsetExceedingLength(int offset)
        {
            var binaryValue = new DhcpBinaryValue(Bytes, 0, Bytes.Length);

            Assert.Throws <ArgumentOutOfRangeException>(
                () => binaryValue.CreateSubsetValue(offset, 2));
        }
Beispiel #7
0
        public void ThrowArgumentOutOfRange_GivenLengthExceedingDataLength(int length)
        {
            var binaryValue = new DhcpBinaryValue(Bytes, 0, Bytes.Length);

            Assert.Throws <ArgumentOutOfRangeException>(
                () => binaryValue.CreateSubsetValue(0, length));
        }
Beispiel #8
0
        public void ThrowInvalidOperationException_GivenInvalidTypeAndLengthCombination(Type outputType, byte length)
        {
            var valueReader = new DhcpBinaryValue(TestBytes, 0, length);

            Assert.Throws <InvalidOperationException>(
                () => valueReader.As(outputType));
        }
        public void ThrowInvalidOperationException_GivenBytesWithPaddingOptionInMiddle()
        {
            var valueReader = new DhcpBinaryValue(PaddingOptionInMiddleBytes, 0, (byte)PaddingOptionInMiddleBytes.Length);

            Assert.Throws <InvalidOperationException>(
                () => valueReader.AsTaggedValueCollection());
        }
Beispiel #10
0
        public void ReadValueFromGivenOffset()
        {
            var valueReader = new DhcpBinaryValue(TestBytes, 2, 8);

            Assert.Equal(IPAddress.Parse("34.51.68.85"), valueReader.AsIpAddressPairList().Single().Item1);
            Assert.Equal(IPAddress.Parse("102.119.136.153"), valueReader.AsIpAddressPairList().Single().Item2);
        }
        public void ThrowInvalidOperationException_GivenBytesWithInvalidLengthOfLastValue()
        {
            var valueReader = new DhcpBinaryValue(InvalidOptionLengthBytes, 0, (byte)InvalidOptionLengthBytes.Length);

            Assert.Throws <InvalidOperationException>(
                () => valueReader.AsTaggedValueCollection());
        }
        public void ReadValueFromGivenOffset()
        {
            var bytes       = new byte[] { 0x00, 0x00, 0x01, 0x00 };
            var valueReader = new DhcpBinaryValue(bytes, 2, 1);

            Assert.True(valueReader.AsBoolean());
        }
        internal DhcpNetWareSubOptionsOption(DhcpBinaryValue binaryValue)
        {
            var firstByteBinaryValue = binaryValue.CreateSubsetValue(0, 1);

            State = ParseState(firstByteBinaryValue);

            var remainingValueLength = binaryValue.Length - 1;

            if (remainingValueLength > 0)
            {
                if (!StateAllowsSubOptions())
                {
                    throw new FormatException(
                              $"The NetWare sub options first byte is {State} which does not allow further sub options, but other sub options have been found.");
                }

                var subOptionsBinaryValue = binaryValue.CreateSubsetValue(1, binaryValue.Length - 1);

                SubOptions = ParseSubOptions(subOptionsBinaryValue);
            }
            else
            {
                SubOptions = new INetWareSubOption[0];
            }
        }
Beispiel #14
0
        public void ReturnTrue_GivenValidLength()
        {
            var bytes = new byte[10];

            var valueReader = new DhcpBinaryValue(bytes, 0, 1);

            Assert.True(valueReader.IsValidByte());
        }
Beispiel #15
0
        public void ReturnTrue_GivenValidLength()
        {
            var bytes = new byte[8];

            var binaryValue = new DhcpBinaryValue(bytes, 0, 8);

            Assert.True(binaryValue.IsValidIpAddressPairList());
        }
Beispiel #16
0
        public void ThrowFormatException_GivenValueWithFirstByteNotAllowingOtherSubOptionsAndOtherSubOptions(NetWareIpState state)
        {
            var bytes       = new byte[] { (byte)state, 0x01, 0xaa, 0xaa };
            var binaryValue = new DhcpBinaryValue(bytes, 0, bytes.Length);

            Assert.Throws <FormatException>(
                () => new DhcpNetWareSubOptionsOption(binaryValue));
        }
Beispiel #17
0
        public void ThrowFormatException_GivenValueWithInvalidFirstByte(byte firstByte)
        {
            var bytes       = new[] { firstByte };
            var binaryValue = new DhcpBinaryValue(bytes, 0, bytes.Length);

            Assert.Throws <FormatException>(
                () => new DhcpNetWareSubOptionsOption(binaryValue));
        }
        public void ReturnValue_GivenValidLength(byte binaryValue, bool expectedValue)
        {
            var bytes = new[] { binaryValue };

            var valueReader = new DhcpBinaryValue(bytes, 0, 1);

            Assert.Equal(expectedValue, valueReader.AsBoolean());
        }
Beispiel #19
0
        public void ReturnTrue_GivenValidLength(byte length)
        {
            var bytes = new byte[20];

            var valueReader = new DhcpBinaryValue(bytes, 0, length);

            Assert.True(valueReader.IsValidUnsignedInt16List());
        }
Beispiel #20
0
        public void ReturnFalse_GivenInvalidLength(int length)
        {
            var bytes = new byte[length];

            var binaryValue = new DhcpBinaryValue(bytes, 0, length);

            Assert.False(binaryValue.IsValidIpAddressPairList());
        }
        public void ReturnTrue_GivenValidLength(Type outputType, byte length)
        {
            var bytes = new byte[30];

            var valueReader = new DhcpBinaryValue(bytes, 0, length);

            Assert.True(valueReader.IsValid(outputType));
        }
Beispiel #22
0
        public void ReturnFalse_GivenInvalidLength(byte length)
        {
            var bytes = new byte[10];

            var valueReader = new DhcpBinaryValue(bytes, 0, length);

            Assert.False(valueReader.IsValidByte());
        }
Beispiel #23
0
        public void ReturnSubSetValue()
        {
            var binaryValue = new DhcpBinaryValue(Bytes, 0, Bytes.Length);

            var subsetValue   = binaryValue.CreateSubsetValue(2, 2);
            var expectedValue = new byte[] { 0x03, 0x04 };

            Assert.Equal(expectedValue, subsetValue.AsBytes());
        }
Beispiel #24
0
        public void ReturnSingleIpPair_GivenBytesForOneIpPair()
        {
            var valueReader = new DhcpBinaryValue(TestBytes, 0, 8);

            var ipPair = valueReader.AsIpAddressPairList().Single();

            Assert.Equal(IPAddress.Parse("0.17.34.51"), ipPair.Item1);
            Assert.Equal(IPAddress.Parse("68.85.102.119"), ipPair.Item2);
        }
Beispiel #25
0
        public void SetStateFromFirstOption(byte firstByte, NetWareIpState expectedState)
        {
            var bytes       = new[] { firstByte };
            var binaryValue = new DhcpBinaryValue(bytes, 0, bytes.Length);

            var option = new DhcpNetWareSubOptionsOption(binaryValue);

            Assert.Equal(expectedState, option.State);
        }
Beispiel #26
0
        public void ThrowInvalidOperationException_GivenInvalidLength(byte length)
        {
            var bytes = new byte[10];

            var valueReader = new DhcpBinaryValue(bytes, 0, length);

            Assert.Throws <InvalidOperationException>(
                () => valueReader.AsIpAddressPairList());
        }
Beispiel #27
0
        public void SetEmptySubOptions_GivenValueWithNoSubOptions()
        {
            var bytes       = new byte[] { 0x01 };
            var binaryValue = new DhcpBinaryValue(bytes, 0, bytes.Length);

            var option = new DhcpNetWareSubOptionsOption(binaryValue);

            Assert.NotNull(option.SubOptions);
        }
        public void ReturnTwoNumbers_GivenBytesForTwoNumbers()
        {
            var valueReader = new DhcpBinaryValue(TestBytes, 0, 8);

            var numberList = valueReader.AsUnsignedInt16List();

            Assert.Equal(17U, numberList[0]);
            Assert.Equal(8755U, numberList[1]);
        }
        public void ReturnResult_GivenBytesWithoutPaddingByte()
        {
            var valueReader = new DhcpBinaryValue(ValidNoPaddingOptionBytes, 0, (byte)ValidNoPaddingOptionBytes.Length);

            var values = valueReader.AsTaggedValueCollection();

            Assert.Equal(1, values.Count);
            Assert.Equal(9, values.Single().Key);
        }
        public void ReturnResultWithoutItemsAfterEndByte_GivenBytesWithEndByteInMiddle()
        {
            var valueReader = new DhcpBinaryValue(ValidEndByteInMiddleBytes, 0, (byte)ValidEndByteInMiddleBytes.Length);

            var values = valueReader.AsTaggedValueCollection();

            Assert.Equal(1, values.Count);
            Assert.Equal(9, values.Single().Key);
        }