示例#1
0
        public void TryWrite_should_return_false_when_record_serialization_fails()
        {
            recordSerializer
            .TrySerialize(item, itemSerializer, timestamp, buffer)
            .Returns(false);

            TryWrite().Should().BeFalse();
        }
示例#2
0
        public bool TryWrite <T>(T item, IAirlockSerializer <T> serializer, DateTimeOffset timestamp, IBufferPool bufferPool)
        {
            if (!bufferPool.TryAcquire(out var buffer))
            {
                return(false);
            }

            var startingPosition       = buffer.Position;
            var serializationSucceeded = false;

            try
            {
                serializationSucceeded = recordSerializer.TrySerialize(item, serializer, timestamp, buffer);
            }
            finally
            {
                if (serializationSucceeded)
                {
                    buffer.WrittenRecords++;
                }
                else
                {
                    buffer.Position = startingPosition;
                }

                bufferPool.Release(buffer);
            }

            return(serializationSucceeded);
        }
示例#3
0
        public void TestSetup()
        {
            timestamp      = DateTimeOffset.UtcNow;
            item           = Guid.NewGuid().ToString();
            itemSerializer = Substitute.For <IAirlockSerializer <string> >();

            buffer = Substitute.For <IBuffer>();
            buffer.WrittenRecords.Returns(5);
            buffer.Position.Returns(10);

            bufferPool = Substitute.For <IBufferPool>();
            bufferPool
            .TryAcquire(out _)
            .Returns(
                x =>
            {
                x[0] = buffer;
                return(buffer != null);
            });

            recordSerializer = Substitute.For <IRecordSerializer>();
            recordSerializer
            .TrySerialize(item, itemSerializer, timestamp, buffer)
            .Returns(true);

            recordWriter = new RecordWriter(recordSerializer);
        }