Exemplo n.º 1
0
        public void Delete_unknown_container_should_fail()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containersCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk = swiftclient.GetContainers(tokenSource.Token);
                containersCollection = tsk.Result;
            });

            Assert.NotNull(containersCollection);
            string validUri = containersCollection.First().Endpoint.ToString();

            validUri = validUri.Substring(0, validUri.LastIndexOf("/"));

            Container badContainer = new Container()
            {
                Endpoint = new Uri(validUri + "/" + "##I_am_super_bad##")
            };


            Assert.Throws(typeof(AggregateException), () => {
                var tsk  = swiftclient.DeleteContainer(badContainer, tokenSource.Token);
                var coll = tsk.Result;
                Assert.Null(coll);
            });
        }
        public void Delete_existing_container()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;
            string containerName = Guid.NewGuid().ToString();

            //
            // Create container
            Assert.DoesNotThrow(() =>
            {
                var tsk             = swiftclient.CreateContainer(containerName, tokenSource.Token);
                containerCollection = tsk.Result;
            });

            Assert.NotNull(containerCollection);
            Assert.True(containerCollection.Any(c => c.Name.Equals(containerName)));

            ContainerCollection containerCollection2 = null;
            Container           container            = containerCollection.First(c => c.Name.Equals(containerName));

            //
            // Delete this container
            Assert.DoesNotThrow(() => {
                var tsk1             = swiftclient.DeleteContainer(container, tokenSource.Token);
                containerCollection2 = tsk1.Result;
            });

            //
            // Is not exist in new list
            Assert.False(containerCollection2.Any(c => c.Name.Equals(containerName)));
        }
Exemplo n.º 3
0
        public void Delete_unknown_object_from_container_should_throw()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;

            Assert.DoesNotThrow(() =>
            {
                var tsk             = swiftclient.GetContainers(tokenSource.Token);
                containerCollection = tsk.Result;
            });

            Assert.NotNull(containerCollection);


            Container   container = containerCollection.First();
            SwiftObject badObject = new SwiftObject()
            {
                Name = "##I_am_super_bad##"
            };

            Assert.Throws(typeof(AggregateException), () => {
                var tsk  = swiftclient.DeleteObject(container, badObject, tokenSource.Token);
                var coll = tsk.Result;
                Assert.NotNull(coll);
            });
        }
        public void Should_throw_on_container_that_does_not_exist()
        {
            byte[] bRndName = new byte[10];
            new Random().NextBytes(bRndName);

            string containerName = System.Text.Encoding.Default.GetString(bRndName);

            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk             = swiftclient.GetContainers(tokenSource.Token);
                containerCollection = tsk.Result;
            });


            //
            // Check that it does not exist
            Assert.False(containerCollection.Any(c => c.Name.Equals(containerName)));

            //
            // Should throw
            Assert.Throws(typeof(ArgumentNullException), () => {
                var tsk2 = swiftclient.DeleteContainer(containerName, tokenSource.Token);
            });
        }
Exemplo n.º 5
0
        [PropertyData("RandomFileAtAllContainers")]        //[PropertyData("FixedFileName")]
        public void Upload_object(string fileName, Container container)
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            System.Diagnostics.Trace.WriteLine("File: " + fileName + " gonna be uploaded to container: " + container.Name);

            Assert.DoesNotThrow(() => {
                var tsk2 = swiftclient.UploadObject(fileName, container, tokenSource.Token);
                tsk2.Wait();
            });
        }
        public void Work_normally()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            AccountDetails accountDetails = null;

            Assert.DoesNotThrow(() => {
                var tsk        = swiftclient.GetAccountDetails(tokenSource.Token);
                accountDetails = tsk.Result;
                Assert.NotNull(accountDetails);
            });
        }
Exemplo n.º 7
0
        public void Delete_all_objects_for_all_containers()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk             = swiftclient.GetContainers(tokenSource.Token);
                containerCollection = tsk.Result;
            });

            Assert.NotNull(containerCollection);

            List <Tuple <Container, SwiftObjectsCollection> > listOfEverything = new List <Tuple <Container, SwiftObjectsCollection> >();

            containerCollection.ForEach(container => {
                Assert.DoesNotThrow(() => {
                    var tsk2 = swiftclient.GetObjects(container, tokenSource.Token);
                    listOfEverything.Add(new Tuple <Container, SwiftObjectsCollection>(container, tsk2.Result));
                });
            });

            Assert.True(listOfEverything.Count > 0);

            foreach (Tuple <Container, SwiftObjectsCollection> record in listOfEverything)
            {
                SwiftObjectsCollection originalCollection  = record.Item2;
                SwiftObjectsCollection generatedCollection = null;

                originalCollection.ForEach(obj => {
                    Assert.DoesNotThrow(() => {
                        System.Diagnostics.Trace.WriteLine("[Objects] Going to delete object: " + obj.Name + " from container: " + record.Item1.Name);

                        var tsk3            = swiftclient.DeleteObject(record.Item1, obj, tokenSource.Token);
                        generatedCollection = tsk3.Result;
                    });

                    Assert.NotNull(generatedCollection);

                    Assert.False(originalCollection.Intersect(generatedCollection).Count() == originalCollection.Count);
                });
            }
        }
        public void Create_container_and_enshure_it()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;
            string containerName = Guid.NewGuid().ToString();

            Assert.DoesNotThrow(() =>
            {
                var tsk             = swiftclient.CreateContainer(containerName, tokenSource.Token);
                containerCollection = tsk.Result;
            });

            Assert.NotNull(containerCollection);
            Assert.True(containerCollection.Any(c => c.Name.Equals(containerName)));
        }
        public void Work_normally()
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            ContainerCollection containerCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk             = swiftclient.GetContainers(tokenSource.Token);
                containerCollection = tsk.Result;
            });

            Assert.NotNull(containerCollection);

            System.Diagnostics.Trace.WriteLine("Found: " + containerCollection.Count.ToString() + " containers");
            containerCollection.AsParallel().ForAll(cont => System.Diagnostics.Trace.WriteLine("Container name: " + cont.Name + " Endpoint: " + cont.Endpoint.ToString()));
        }
Exemplo n.º 10
0
        public void Bring_all_objects(Container targetContainer)
        {
            swiftConnectionData = KeystoneData.GetKeystoneToken();
            tokenSource         = new CancellationTokenSource();

            swiftclient = new Swift(swiftConnectionData.Item1, swiftConnectionData.Item2, KeystoneData.keystoneTenant);

            SwiftObjectsCollection swiftObjectCollection = null;

            Assert.DoesNotThrow(() => {
                var tsk = swiftclient.GetObjects(targetContainer, tokenSource.Token);
                swiftObjectCollection = tsk.Result;
            });

            //
            // Even if they are not objects the 'data' could not be null
            Assert.NotNull(swiftObjectCollection);

            System.Diagnostics.Trace.WriteLine("Container: " + targetContainer.Name + " has " + swiftObjectCollection.Count.ToString() + " objects inside it");
            swiftObjectCollection.AsParallel().ForAll(obj => System.Diagnostics.Trace.WriteLine("Swift object name: " + obj.Name + " Hash: " + obj.MD5Hash + " length: " + obj.Length + " Endpoint: " + obj.Endpoint.ToString()));
        }
        public void Should_fail_on_wrong_token()
        {
            tokenSource         = new CancellationTokenSource();
            swiftConnectionData = KeystoneData.GetKeystoneToken();

            //Uri endpoint, string token, string tenant
            swiftclient = new Swift(swiftConnectionData.Item1, "$$wrong_token", KeystoneData.keystoneTenant);

            Assert.Throws(typeof(AggregateException), () =>
            {
                var tsk = swiftclient.GetAccountDetails(tokenSource.Token);
                tsk.Wait();
            });

            try
            {
                var tsk = swiftclient.GetAccountDetails(tokenSource.Token);
                tsk.Wait();
            }
            catch (AggregateException exp_agr)
            {
                AggregateException exp2 = exp_agr.Flatten();

                //
                // Find System.UnauthorizedAccessException in inner exceptions
                bool found = false;

                foreach (var exp in exp2.InnerExceptions)
                {
                    if (exp.GetType().Equals(typeof(System.UnauthorizedAccessException)))
                    {
                        found = true;
                    }
                }

                Assert.True(found);
            }
        }