Beispiel #1
0
        public async Task Delete()
        {
            StorageQueue storage = await QueueSetup();

            var msg = new CloudQueueMessage(Guid.NewGuid().ToByteArray());
            await storage.Send(msg);

            var returned = await storage.Get();

            await storage.Delete(returned);

            await storage.Delete();
        }
Beispiel #2
0
        public async Task PeekGeneric()
        {
            StorageQueue storage = await QueueSetup();

            var expected = new TestCustomObject {
                FooInt = 42, FooString = "The Answer"
            };
            var expected2 = new TestCustomObject {
                FooInt = 43, FooString = "The Answer 2"
            };
            var expectedList = new List <TestCustomObject> {
                expected, expected2
            };

            foreach (var item in expectedList)
            {
                await storage.SendAsync(item);
            }

            var peeked = (await storage.PeekAsync <TestCustomObject>(2)).ToList();

            Assert.AreEqual(expectedList.Count, peeked.Count);
            Assert.IsTrue(expectedList.Any(m => m.FooInt == expected.FooInt && m.FooString == expected.FooString));
            Assert.IsTrue(expectedList.Any(m => m.FooInt == expected2.FooInt && m.FooString == expected2.FooString));

            var returned = (await storage.GetManyAsync <TestCustomObject>()).ToList();

            Assert.AreEqual(expectedList.Count, returned.Count);
            Assert.IsTrue(returned.Any(m => m.FooInt == expected.FooInt && m.FooString == expected.FooString));
            Assert.IsTrue(returned.Any(m => m.FooInt == expected2.FooInt && m.FooString == expected2.FooString));
            await storage.Delete();
        }
Beispiel #3
0
        public void DeleteNull()
        {
            var name = Guid.NewGuid().ToString();
            var t    = new StorageQueue(name, ConnectionString);

            Assert.That(() => t.Delete(null), Throws.TypeOf <ArgumentNullException>());
        }
Beispiel #4
0
        public async Task CreateIfNotExists()
        {
            var name    = GetQueueName();
            var storage = new StorageQueue(name, TestHelpers.DevConnectionString);
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);
            await storage.Delete();
        }
Beispiel #5
0
        public async Task ApproixmateMessageCountNone()
        {
            StorageQueue storage = await QueueSetup();

            var result = await storage.ApproixmateMessageCount();

            Assert.AreEqual(0, result);
            await storage.Delete();
        }
Beispiel #6
0
        public async Task ConstructorAccount()
        {
            var name    = GetQueueName();
            var account = CloudStorageAccount.Parse(TestHelpers.DevConnectionString);
            var storage = new StorageQueue(name, account, TimeSpan.FromSeconds(34));
            var created = await storage.CreateIfNotExists();

            Assert.IsTrue(created);
            await storage.Delete();
        }
Beispiel #7
0
        public async Task Delete()
        {
            var storage = new StorageQueue(QueueName, ConnectionString);

            var msg = new CloudQueueMessage(Guid.NewGuid().ToByteArray());
            await storage.Send(msg);

            var returned = await storage.Get();

            await storage.Delete(returned);
        }
Beispiel #8
0
        public async Task RoundTripMsgAsObj()
        {
            StorageQueue storage = await QueueSetup();

            var msg = new CloudQueueMessage(Guid.NewGuid().ToByteArray());
            await storage.Send((object)msg);

            var returned = await storage.Get();

            Assert.AreEqual(msg.AsBytes, returned.AsBytes);
            await storage.Delete();
        }
Beispiel #9
0
        public async Task RoundTripObject()
        {
            StorageQueue storage = await QueueSetup();

            var expected = Guid.NewGuid();
            await storage.Send(expected);

            var returned = await storage.Get();

            var guid = JsonConvert.DeserializeObject <Guid>(returned.AsString);

            Assert.AreEqual(expected, guid);
            await storage.Delete();
        }
Beispiel #10
0
        public async Task GenericGet()
        {
            StorageQueue storage = await QueueSetup();

            var expected = new TestCustomObject {
                FooInt = 42, FooString = "The Answer"
            };
            await storage.SendAsync(expected);

            var returned = await storage.GetAsync <TestCustomObject>();

            Assert.AreEqual(expected.FooString, returned.FooString);
            Assert.AreEqual(expected.FooInt, returned.FooInt);
            await storage.Delete();
        }
Beispiel #11
0
        public async Task Peek()
        {
            StorageQueue storage = await QueueSetup();

            var msg = new CloudQueueMessage(Guid.NewGuid().ToByteArray());
            await storage.Send(msg);

            var peeked = await storage.PeekAsync();

            Assert.AreEqual(msg.AsBytes, peeked.First().AsBytes);

            var returned = await storage.Get();

            Assert.AreEqual(msg.AsBytes, returned.AsBytes);
            await storage.Delete();
        }
Beispiel #12
0
        public async Task ApproixmateMessageCount()
        {
            var          random  = new Random();
            var          count   = random.Next(1, 1000);
            StorageQueue storage = await QueueSetup();

            for (var i = 0; i < count; i++)
            {
                await storage.SendAsync(Guid.NewGuid());
            }

            var result = await storage.ApproixmateMessageCount();

            Assert.AreEqual(count, result);
            await storage.Delete();
        }
Beispiel #13
0
        public async Task RoundTripObject()
        {
            StorageQueue storage = await QueueSetup();

            var expected = new TestCustomObject {
                FooInt = 42, FooString = "The Answer"
            };
            await storage.SendAsync <TestCustomObject>(expected);

            var returned = await storage.Get();

            var deserialized = JsonConvert.DeserializeObject <TestCustomObject>(returned.AsString);

            Assert.AreEqual(expected.FooString, deserialized.FooString);
            Assert.AreEqual(expected.FooInt, deserialized.FooInt);
            await storage.Delete();
        }
        public async Task Queues()
        {
            var name    = 'a' + Guid.NewGuid().ToString().ToLowerInvariant().Replace('-', 'a');
            var storage = new StorageQueue(name, ConnectionString);
            var created = await storage.CreateIfNotExists();

            var resources = new AzureStorageResources(ConnectionString);
            var queues    = resources.Queues();

            var exists = (from q in queues
                          where q.Name == name
                          select true).FirstOrDefault();

            Assert.IsTrue(exists);

            await storage.Delete();
        }
Beispiel #15
0
        public async Task GetManyNegative()
        {
            var random = new Random();
            var count  = random.Next(1, 25);

            StorageQueue storage = await QueueSetup();

            for (var i = 0; i < count; i++)
            {
                var msg = new CloudQueueMessage(Guid.NewGuid().ToByteArray());
                await storage.Send(msg);
            }

            var returned = await storage.GetMany(-1);

            Assert.AreEqual(1, returned.Count());
            await storage.Delete();
        }
Beispiel #16
0
        public void TearDown()
        {
            var storage = new StorageQueue(QueueName, ConnectionString);

            storage.Delete().Wait();
        }