コード例 #1
0
        public static void ClassInitialize(TestContext testContext)
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                return;
            }

            accountInfoFilePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                "SyncProTesting",
                "BackblazeB2AccountInfo.json");

            if (File.Exists(accountInfoFilePath))
            {
                string fileContent = File.ReadAllText(accountInfoFilePath);
                accountInfo = JsonConvert.DeserializeObject <BackblazeB2AccountInfo>(fileContent);

                return;
            }

            CredentialResult credentials;

            try
            {
                credentials = CredentialHelper.PromptForCredentials(
                    "Enter your Backblaze AccountID (username) and Application Key (password)");
            }
            catch (Win32Exception win32Exception)
                when(win32Exception.NativeErrorCode ==
                     (int)NativeMethods.CredUI.CredUIReturnCodes.ERROR_CANCELLED)
                {
                    Assert.Inconclusive("Backblaze B2 credentials are required to run tests");

                    // ReSharper disable once HeuristicUnreachableCode
                    return;
                }

            accountInfo = new BackblazeB2AccountInfo
            {
                AccountId      = credentials.Username,
                ApplicationKey = credentials.Password
            };

            using (BackblazeB2Client client = CreateClient())
            {
                IList <Bucket> allBuckets = client.ListBucketsAsync().Result;
                Bucket         bucket     = allBuckets.FirstOrDefault(b => b.BucketName == DefaultBucketName);

                if (bucket == null)
                {
                    bucket = client.CreateBucket(DefaultBucketName, Constants.BucketTypes.Private).Result;
                }

                accountInfo.BucketId = bucket.BucketId;
            }

            string serializedInfo = JsonConvert.SerializeObject(accountInfo, Formatting.Indented);

            File.WriteAllText(accountInfoFilePath, serializedInfo);
        }
コード例 #2
0
        public static void ClassInitialize(TestContext testContext)
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                return;
            }

            AdapterRegistry.RegisterAdapter(
                AzureStorageAdapter.TargetTypeId,
                typeof(AzureStorageAdapter),
                typeof(AzureStorageAdapterConfiguration));


            string accountInfoFilePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                "SyncProTesting",
                "AzureStorageAccountInfo.json");

            if (File.Exists(accountInfoFilePath))
            {
                string fileContent = File.ReadAllText(accountInfoFilePath);
                accountInfo = JsonConvert.DeserializeObject <AzureStorageAdapterConfiguration>(fileContent);

                return;
            }

            CredentialResult credentials;

            try
            {
                credentials = CredentialHelper.PromptForCredentials(
                    "Enter your storage account name (username) and account key (password)");
            }
            catch (Win32Exception win32Exception)
                when(win32Exception.NativeErrorCode ==
                     (int)NativeMethods.CredUI.CredUIReturnCodes.ERROR_CANCELLED)
                {
                    Assert.Inconclusive("Azure storage credentials are required to run tests");

                    // ReSharper disable once HeuristicUnreachableCode
                    return;
                }

            accountInfo = new AzureStorageAdapterConfiguration
            {
                AccountName   = credentials.Username,
                AccountKey    = credentials.Password,
                ContainerName = DefaultContainerName
            };

            string serializedInfo = JsonConvert.SerializeObject(accountInfo, Formatting.Indented);

            File.WriteAllText(accountInfoFilePath, serializedInfo);
        }