单元测试Azure Blob存储连接

时间:2020-03-02 18:04:24

标签: azure azure-storage-blobs

我正在编写用于检查Azure blob容器是否存在的单元测试。这是我的代码:

  [TestMethod]
    public async Task StorageAccountConnectionTest()
    {
        var storageCredentials = new StorageCredentials(_mockFuncXTransConfiguration.Object.StorageAccountName, _mockFuncXransConfiguration.Object.StorageAccountKey);
        var cloudStorageAccount = new CloudStorageAccount(storageCredentials, true);
        var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
        var container = cloudBlobClient.GetContainerReference(_mockFuncXTransConfiguration.Object.BlobName);
        bool result = await container.ExistsAsync();
        Assert.AreEqual(true, result);
    }

其中容器的类型为Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer,而_mockFuncXTransConfiguration.Object.StorageAccountName, _mockFuncXransConfiguration.Object.StorageAccountKey, _mockFuncXTransConfiguration.Object.BlobName包含实际值

enter image description here

但是我在第二行中遇到以下错误:

Test method StorageAccountConnectionTest threw exception: 
    Microsoft.WindowsAzure.Storage.StorageException: No such host is known. ---> System.Net.Http.HttpRequestException: No such host is known. ---> System.Net.Sockets.SocketException: No such host is known.

这是整个堆栈跟踪:

ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
    --- End of inner exception stack trace ---
    ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
    HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
    HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
    RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
    Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
    --- End of inner exception stack trace ---
    Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
    funcDataPlatformTransTest.StorageAccountConnectionTest() line 35
    ThreadOperations.ExecuteWithAbortSafety(Action action)

我要去哪里错了?

0 个答案:

没有答案