Exemple #1
0
        public async Task CleanDestinationSourceItemsNull()
        {
            var destination = Substitute.For <IDataLister>();
            var e           = new Echoer(destination);

            Assert.That(async() => await e.CleanDestination(null), Throws.TypeOf <ArgumentNullException>());
        }
Exemple #2
0
        public async Task CleanDestinationNothingToDelete()
        {
            var random = new Random();
            var count  = random.Next(1, 64);

            var sItems = new List <IStorageItem>(count);
            var dItems = new List <IStorageItem>(count);

            for (var i = 0; i < count; i++)
            {
                var item = Substitute.For <IStorageItem>();
                item.RelativePath.Returns(Guid.NewGuid().ToString());

                sItems.Add(item);
                dItems.Add(item);
            }

            var destination = Substitute.For <IDataLister>();

            destination.List().Returns(dItems);

            var e = new Echoer(destination);
            await e.CleanDestination(sItems);

            destination.Received().List();

            foreach (var di in dItems)
            {
                di.Received(0).Delete();
            }
        }
Exemple #3
0
        public async Task CleanDestinationSourceItemsEmpty()
        {
            var destination = Substitute.For <IDataLister>();

            destination.List().Returns(new List <IStorageItem>());

            var e = new Echoer(destination);
            await e.CleanDestination(new List <IStorageItem>());
        }
Exemple #4
0
        public async Task CleanDestinationDestinationItems()
        {
            var sItems = new List <IStorageItem>();

            sItems.Add(Substitute.For <IStorageItem>());
            var destination = Substitute.For <IDataLister>();

            destination.List().Returns((IEnumerable <IStorageItem>)null);

            var e = new Echoer(destination);
            await e.CleanDestination(sItems);

            destination.Received().List();
        }
Exemple #5
0
        public async Task FolderToBlob()
        {
            var random = new Random();

            var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", "");
            var from          = string.Format("{0}\\{1}", Environment.CurrentDirectory, Guid.NewGuid());

            Directory.CreateDirectory(from);

            var to = new Container(containerName, ConnectionString);
            await to.CreateIfNotExists();

            var extraCount = random.Next(1, 25);
            var extra      = new List <Validation>(extraCount);

            for (var i = 0; i < extraCount; i++)
            {
                var v = new Validation
                {
                    Data     = Guid.NewGuid().ToByteArray(),
                    FileName = Guid.NewGuid().ToString(),
                };

                await to.Save(v.FileName, v.Data);

                extra.Add(v);
            }

            var e = new Echoer(new BlobReader(to));
            await e.CleanDestination(new FolderReader(from).List());

            var items = to.List();

            Assert.AreEqual(0, items.Count());

            await to.Delete();

            Directory.Delete(from, true);
        }
Exemple #6
0
        public async Task BlobToBlob()
        {
            var random            = new Random();
            var containerName     = string.Format("a{0}b", random.Next());
            var destContainerName = string.Format("c{0}d", random.Next());

            var from = new Container(containerName, ConnectionString);
            await from.CreateIfNotExists();

            var to = new Container(destContainerName, ConnectionString);
            await to.CreateIfNotExists();

            var count = random.Next(1, 25);

            for (var i = 0; i < count; i++)
            {
                var v = new Validation
                {
                    Data     = Guid.NewGuid().ToByteArray(),
                    FileName = Guid.NewGuid().ToString(),
                };

                await to.Save(v.FileName, v.Data);
            }

            var sourceItems = new BlobReader(from).List();

            var e = new Echoer(new BlobReader(to));
            await e.CleanDestination(sourceItems);

            var items = to.List();

            Assert.AreEqual(0, items.Count());

            //Clean-Up
            await from.Delete();

            await to.Delete();
        }
Exemple #7
0
        public async Task BlobToFolder()
        {
            var random        = new Random();
            var containerName = 'a' + Guid.NewGuid().ToString().Replace("-", "");
            var from          = new Container(containerName, ConnectionString);
            await from.CreateIfNotExists();

            var to = string.Format("{0}\\{1}", Environment.CurrentDirectory, Guid.NewGuid());

            Directory.CreateDirectory(to);

            var count = random.Next(1, 25);

            for (var i = 0; i < count; i++)
            {
                var v = new Validation
                {
                    Data     = new byte[64],
                    FileName = string.Format("{0}.{1}", Guid.NewGuid(), i),
                };

                var bytes = new byte[64];
                random.NextBytes(v.Data);

                File.WriteAllBytes(string.Format("{0}\\{1}", to, v.FileName), v.Data);
            }

            var e = new Echoer(new FolderReader(to));
            await e.CleanDestination(new BlobReader(from).List());

            var items = Directory.GetFiles(to);

            Assert.AreEqual(0, items.Count());

            Directory.Delete(to, true);

            await from.Delete();
        }