Exemplo n.º 1
0
        public void It_should_push_extended_data_set_to_persisted_instance()
        {
            var newData = new byte[] { 4, 5, 6 };

            SubjectUnderTest.AddBytes(newData);

            Assert.That(SubjectUnderTest.ToString(), Is.EqualTo("position=3 | bytes=[1 2 3 4 5 6 ] & size=6"));

            SubjectUnderTest.PersistMeTo(_fsi);

            var savedBytes = ((FileSystemInterfaceFake)_fsi).Bytes;

            var position = ByteArrayConverter.ByteArrayToLong(savedBytes);

            Assert.That(position, Is.EqualTo(_position));

            var size = ByteArrayConverter.ByteArrayToInt(savedBytes, 8);

            Assert.That(size, Is.EqualTo(_data.Length + newData.Length));

            Assert.That(savedBytes[12], Is.EqualTo(_data[0]));
            Assert.That(savedBytes[13], Is.EqualTo(_data[1]));
            Assert.That(savedBytes[14], Is.EqualTo(_data[2]));
            Assert.That(savedBytes[15], Is.EqualTo(newData[0]));
            Assert.That(savedBytes[16], Is.EqualTo(newData[1]));
            Assert.That(savedBytes[17], Is.EqualTo(newData[2]));
        }
Exemplo n.º 2
0
        public void It_should_allow_you_to_create_empty_write_action_and_then_add_data_set_to_persisted_instance()
        {
            var writeAction = new WriteAction(_position);

            Assert.That(writeAction.ToString(), Is.EqualTo("position=3 | bytes=[] & size=0"));

            writeAction.AddBytes(_data);

            writeAction.PersistMeTo(_fsi);

            var savedBytes = ((FileSystemInterfaceFake)_fsi).Bytes;
            var savedWriteInTransaction = ((FileSystemInterfaceFake)_fsi).WriteInTransaction;

            Assert.That(savedWriteInTransaction, Is.False);

            var position = ByteArrayConverter.ByteArrayToLong(savedBytes);

            Assert.That(position, Is.EqualTo(_position));

            var size = ByteArrayConverter.ByteArrayToInt(savedBytes, 8);

            Assert.That(size, Is.EqualTo(_data.Length));

            Assert.That(savedBytes[12], Is.EqualTo(_data[0]));
            Assert.That(savedBytes[13], Is.EqualTo(_data[1]));
            Assert.That(savedBytes[14], Is.EqualTo(_data[2]));
        }
        public void It_should_convert_long_to_binary_and_from_binary_to_long_with_the_success()
        {
            const long value = 1234567891011121314L;

            var byteArray      = ByteArrayConverter.LongToByteArray(value);
            var convertedValue = ByteArrayConverter.ByteArrayToLong(byteArray);

            Assert.That(convertedValue, Is.EqualTo(value));
        }
Exemplo n.º 4
0
        public virtual void TestLong()
        {
            long l1 = 785412;
            var  b  = ByteArrayConverter.LongToByteArray(l1);
            var  l2 = ByteArrayConverter.ByteArrayToLong(b);

            AssertEquals(l1, l2);
            l1 = long.MaxValue;
            b  = ByteArrayConverter.LongToByteArray(l1);
            l2 = ByteArrayConverter.ByteArrayToLong(b);
            AssertEquals(l1, l2);
            l1 = long.MinValue;
            b  = ByteArrayConverter.LongToByteArray(l1);
            l2 = ByteArrayConverter.ByteArrayToLong(b);
            AssertEquals(l1, l2);
        }
Exemplo n.º 5
0
        public void It_should_push_single_data_set_to_persisted_instance()
        {
            SubjectUnderTest.PersistMeTo(_fsi);

            var savedBytes = ((FileSystemInterfaceFake)_fsi).Bytes;
            var savedWriteInTransaction = ((FileSystemInterfaceFake)_fsi).WriteInTransaction;

            Assert.That(savedWriteInTransaction, Is.False);

            var position = ByteArrayConverter.ByteArrayToLong(savedBytes);

            Assert.That(position, Is.EqualTo(_position));

            var size = ByteArrayConverter.ByteArrayToInt(savedBytes, 8);

            Assert.That(size, Is.EqualTo(_data.Length));

            Assert.That(savedBytes[12], Is.EqualTo(_data[0]));
            Assert.That(savedBytes[13], Is.EqualTo(_data[1]));
            Assert.That(savedBytes[14], Is.EqualTo(_data[2]));
        }