public async Task SimpleTest()
        {
            var item = new TestDTO();
            var config = new PersistentQueueConfiguration(_queueName);
            config.DataDirectory = Path.GetTempPath();

            var sut = new PersistentQueue<TestDTO>(config);
            await sut.EnqueueAsync(item);
            var actual = await sut.DequeueAsync();

            actual.Id.Should().Be(item.Id);
            actual.UserName.Should().Be(item.UserName);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PersistentQueue{T}"/> class.
        /// </summary>
        /// <exception cref="System.ArgumentNullException">dataDirectory</exception>
        public PersistentQueue(PersistentQueueConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            _dataDirectory = Path.Combine(configuration.DataDirectory, configuration.QueueName);
            _serializer    = configuration.Serializer;
            CreateDirectoryIfNotExists();

            _indexFileName = Path.Combine(configuration.DataDirectory, configuration.QueueName + ".idx");
            _index         = new PersistentCircularIndex(_indexFileName, RecordSize, configuration.MaxCount);

            Encoding = Encoding.UTF8;
        }