Beispiel #1
0
        public void TestFilePersistentQueue()
        {
            var serializer = new BinarySerializer <MockClass>(BinarySerializerTest.MockSerializer, BinarySerializerTest.MockDeserializer);
            var directory  = Path.Combine(QueueDirectory, "TestFilePersistentQueue");

            if (Directory.Exists(directory))
            {
                Directory.Delete(directory, true);
            }

            var queue = new FilePersistentQueue <MockClass>(1000, directory, serializer);
            var list  = BinarySerializerTest.CreateList().Where(i => queue.TryEnqueue(i)).ToList();

            Assert.Equal(list.Count, queue.Count);
            Assert.Equal(list.Count, Directory.GetFiles(directory, "0*").Count());

            var list2 = new List <MockClass>();

            while (queue.TryDequeue(out var item))
            {
                list2.Add(item);
            }

            Assert.True(list.SequenceEqual(list2, new MockClassComparer()));
            Assert.Equal(0, queue.Count);
            Assert.Empty(Directory.GetFiles(directory, "0*"));
        }
        private static void LoadQueue(FilePersistentQueue <MockClass> queue)
        {
            var random = Utility.Random;

            for (int i = 0; i < 10; i++)
            {
                queue.TryEnqueue(new MockClass
                {
                    AnInt         = random.Next(),
                    ALong         = random.Next(),
                    ADateTime     = DateTime.Now,
                    AString       = TestUtility.RandomString(1000),
                    AMemortySteam = Utility.StringToStream(TestUtility.RandomString(1000))
                });
            }
        }
        public void TestFilePersistentQueue()
        {
            var serializer = new BinarySerializer <MockClass>(BinarySerializerTest.MockSerializer, BinarySerializerTest.MockDeserializer);

            var queue = new FilePersistentQueue <MockClass>(1000, _queueDirectory, serializer, _dataFileProvider, NullLogger.Instance);
            var list  = BinarySerializerTest.CreateList().Where(i => queue.TryEnqueue(i)).ToList();

            Assert.Equal(list.Count, queue.Count);
            Assert.Equal(list.Count, Directory.GetFiles(Path.Combine(_appDataDir, _queueDirectory), "0*").Count());

            var list2 = new List <MockClass>();

            while (queue.TryDequeue(out var item))
            {
                list2.Add(item);
            }

            Assert.True(list.SequenceEqual(list2, new MockClassComparer()));
            Assert.Equal(0, queue.Count);
            Assert.Empty(Directory.GetFiles(Path.Combine(_appDataDir, _queueDirectory), "0*"));
        }