AWSSDK_DotNet.IntegrationTests.Tests.S3.DualstackTests.executeSomeBucketOperations C# (CSharp) Method

executeSomeBucketOperations() private method

private executeSomeBucketOperations ( AmazonS3Config s3Config ) : void
s3Config Amazon.S3.AmazonS3Config
return void
        private void executeSomeBucketOperations(AmazonS3Config s3Config)
        {
            using (var s3Client = new AmazonS3Client(s3Config))
            {
                // Call ListBuckets first to verify that AmazonS3PostMarshallHandler.ProcessRequestHandlers
                // correctly computes the endpoint when no bucket name is present.
                var listBucketsResponse = s3Client.ListBuckets();
                Assert.IsNotNull(listBucketsResponse);
                Assert.IsFalse(string.IsNullOrEmpty(listBucketsResponse.ResponseMetadata.RequestId));

                // Bonus call on ListObjects if we can find a bucket compatible with the test region (to avoid 301
                // errors due to addressing bucket on wrong endpoint). This verifies that  
                // AmazonS3PostMarshallHandler.ProcessRequestHandlers correctly computes the endpoint when 
                // a bucket name is present.
                string bucketName = null;
                foreach (var bucket in listBucketsResponse.Buckets)
                {
                    try
                    {
                        var bucketLocationResponse = s3Client.GetBucketLocation(bucket.BucketName);
                        if (string.IsNullOrEmpty(bucketLocationResponse.Location) && s3Config.RegionEndpoint == RegionEndpoint.USEast1)
                            bucketName = bucket.BucketName;
                        else if (string.Equals(s3Config.RegionEndpoint.SystemName, bucketLocationResponse.Location, StringComparison.OrdinalIgnoreCase))
                            bucketName = bucket.BucketName;

                        if (!string.IsNullOrEmpty(bucketName))
                            break;
                    }
                    catch(AmazonS3Exception e)
                    {
                        if (e.StatusCode != System.Net.HttpStatusCode.NotFound)
                            throw;
                    }
                }

                if (!string.IsNullOrEmpty(bucketName))
                {
                    var listObjectsResponse = s3Client.ListObjects(new ListObjectsRequest { BucketName = bucketName });
                    Assert.IsNotNull(listObjectsResponse);
                    Assert.IsNotNull(listObjectsResponse.ResponseMetadata);
                }
            }
        }