public void DecodePropertyId_NotEnoughData_ShouldThrow(int length)
        {
            var data = new byte[length];

            using (var stream = new MemoryStream(data, false))
            using (var reader = new BinaryReader(stream))
            {
                Assert.Throws<EndOfStreamException>(() => TestTransactionPayloadEncoder.DecodePropertyId(reader));
            }
        }
        public void DecodePropertyId_WithInvalidData_ShouldThrow(int length, int id)
        {
            // Arrange.
            var data = new byte[length];

            using (var stream = new MemoryStream(data))
            using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                writer.Write(IPAddress.HostToNetworkOrder(id));
                stream.Seek(0, SeekOrigin.Begin);

                // Act.
                Assert.Throws<ArgumentOutOfRangeException>(
                    () => TestTransactionPayloadEncoder.DecodePropertyId(reader)
                );
            }
        }
        public void DecodePropertyAmount_WithEnoughData_ShouldSuccess(int length, long amount)
        {
            // Arrange.
            var data = new byte[length];

            using (var stream = new MemoryStream(data))
            using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                writer.Write(IPAddress.HostToNetworkOrder(amount));
                stream.Seek(0, SeekOrigin.Begin);

                // Act.
                var result = TestTransactionPayloadEncoder.DecodePropertyAmount(reader);

                // Assert.
                Assert.Equal(amount, result.Indivisible);
                Assert.Equal(8L, stream.Position);
            }
        }
        public void DecodePropertyId_WithValidData_ShouldSuccess(int length, int id)
        {
            // Arrange.
            var data = new byte[length];

            using (var stream = new MemoryStream(data))
            using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
            using (var reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                writer.Write(IPAddress.HostToNetworkOrder(id));
                stream.Seek(0, SeekOrigin.Begin);

                // Act.
                var result = TestTransactionPayloadEncoder.DecodePropertyId(reader);

                // Assert.
                Assert.Equal((uint)id, result.Value);
                Assert.Equal(4, stream.Position);
            }
        }
        public TransactionPayloadEncoderTests()
        {
            var stream = new MemoryStream();

            try
            {
                this.payload = new BinaryReader(stream, Encoding.UTF8);

                try
                {
                    this.subject = new TestTransactionPayloadEncoder();
                }
                catch
                {
                    this.payload.Dispose();
                    throw;
                }
            }
            catch
            {
                stream.Dispose();
                throw;
            }
        }