AWSSDK.IntegrationTests.S3.S3TestUtils.ListObjectsHelper C# (CSharp) Method

ListObjectsHelper() public static method

public static ListObjectsHelper ( AmazonS3Client client, string bucketName ) : List
client Amazon.S3.AmazonS3Client
bucketName string
return List
        public static List<S3Object> ListObjectsHelper(AmazonS3Client client, string bucketName)
        {
            AutoResetEvent ars = new AutoResetEvent(false);
            Exception responseException = new Exception();
            List<S3Object> s3Objects = null;
            client.ListObjectsAsync(new ListObjectsRequest()
            {
                BucketName = bucketName
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    s3Objects = response.Response.S3Objects;
                }
                ars.Set();
            }, new AsyncOptions { ExecuteCallbackOnMainThread = false });

            ars.WaitOne();
            if (responseException != null)
            {
                throw responseException;
            }
            return s3Objects;
        }

Usage Example

        private void SimplePostTestInner()
        {
            AutoResetEvent ars = new AutoResetEvent(false);
            Exception      responseException = new Exception();
            VersionStatus  status            = null;

            Client.GetBucketVersioningAsync(new GetBucketVersioningRequest()
            {
                BucketName = BucketName
            }, (response) =>
            {
                responseException = response.Exception;
                if (responseException == null)
                {
                    status = response.Response.VersioningConfig.Status;
                }
                ars.Set();
            }, new AsyncOptions {
                ExecuteCallbackOnMainThread = false
            });
            ars.WaitOne();
            Assert.IsNull(responseException);
            Assert.AreEqual(VersionStatus.Off, status);
            List <S3Object> s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);

            Assert.IsNotNull(s3Objects);
            var count = s3Objects.Count;

            var key = string.Format(FileNameFormat, DateTime.Now.Ticks);

            S3TestUtils.PostObjectHelper(Client, BucketName, key);

            s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);
            Assert.IsNotNull(s3Objects);
            Assert.AreEqual(count + 1, s3Objects.Count);

            S3TestUtils.DeleteObjectHelper(Client, BucketName, key);

            s3Objects = S3TestUtils.ListObjectsHelper(Client, BucketName);
            Assert.IsNotNull(s3Objects);
            Assert.AreEqual(count, s3Objects.Count);
        }