コード例 #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);
            });
        }
コード例 #2
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);
            });
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
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);
                });
            }
        }
コード例 #5
0
        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()));
        }