小编Cok*_*oke的帖子

使用ARM模板为容器部署Web App

我一直在尝试自动将资源部署到Azure上的资源组。现在,我正在使用ARM模板,到目前为止,我已经能够使用模板创建App Insights和App Service Plan。它是这样的:

{
   "apiVersion": "2015-05-01",
   "name": "[variables('servicePlan')]",
   "kind": "linux",
   "type": "Microsoft.Web/serverfarms",
   "location": "[resourceGroup().location]",
   "tags": {
           "displayName": "BTC Push Notification Settings HostingPlan"
    },
    "sku": {
           "name": "[variables('skuNamePlan')]",
           "capacity": "[variables('skuSizePlan')]"
    },
    "properties": {
            "name": "[variables('servicePlan')]"
    }
},
{
    "apiVersion": "2015-05-01",
    "name": "[variables('appInsights')]",
    "type": "Microsoft.Insights/components",
    "location": "southcentralus",
    "tags": {
            "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('appInsights'))]": "Resource",
            "displayName": "BTC Push Notification Settings App Insights"
     },
     "properties": {
            "applicationId": "[variables('appInsights')]"
        }
 }
Run Code Online (Sandbox Code Playgroud)

我很难创建用于容器的Web App,并使用ARM模板将其指向我的docker映像。我已经手动完成它和它的工作,我也做到了,通过azure-cli这样az webapp create --resource-group ExampleGroupAlpina --plan myAppServicePlan --name DockerContainer …

json azure azure-rm-template

2
推荐指数
2
解决办法
2745
查看次数

模拟CloudStorageAccount和CloudTable for Azure表存储

因此,我试图测试Azure表存储并模拟我依赖的东西。我的类的构造方式是,在构造函数中建立连接,即,创建一个新实例,CloudStorageAccount在其中创建StorageCredentials具有storageNameand 的实例storageKey。之后,创建一个实例CloudTable,在代码中进一步使用它来执行CRUD操作。我的课如下:

public class TableStorage : ITableStorage
    {
        private const string _records = "myTable";
        private CloudStorageAccount _storageAccount;
        private CloudTable _table;
        private ILogger<TableStorage> _logger;

        public AzureTableStorageService(ILogger<TableStorage> loggingService)
        {
            _storageAccount = new CloudStorageAccount(new StorageCredentials(
                 ConfigurationManager.azureTableStorageName, ConfigurationManager.azureTableStorageKey), true);
            _table = _storageAccount.CreateCloudTableClient().GetTableReference(_records);
            _table.CreateIfNotExistsAsync();
            _logger = loggingService;
        }

        //...
        //Other methods here
}
Run Code Online (Sandbox Code Playgroud)

_table在整个类中被重用于不同的目的。我的目标是模拟它,但是由于它是虚拟的并且没有实现任何接口,因此我无法提出一个简单的Mock解决方案,例如:

_storageAccount = new Mock<CloudStorageAccount>(new Mock<StorageCredentials>(("dummy", "dummy"), true));
_table  = new Mock<CloudTable>(_storageAccount.Object.CreateCloudTableClient().GetTableReference(_records));
Run Code Online (Sandbox Code Playgroud)

因此,当我尝试以这种方式构造单元测试时,我得到: Type to mock must be an …

c# unit-testing mocking azure azure-table-storage

2
推荐指数
1
解决办法
2325
查看次数