Azure DevOps托管构建控制器-是否支持Azure存储模拟器?

Azure DevOps托管构建控制器-是否支持Azure存储模拟器?,azure,azure-devops,azure-sdk-.net,azure-storage-emulator,Azure,Azure Devops,Azure Sdk .net,Azure Storage Emulator,我想运行单元/集成测试,使用Azure存储模拟器,而不是Azure DevOps构建中的真实存储 仿真器作为Azure SDK的一部分安装在上的通常位置(C:\Program Files(x86)\Microsoft SDK\Azure\Storage emulator\AzureStorageEmulator.exe) 但是,仿真器在生成控制器上处于未初始化状态。尝试从命令行运行该命令时,出现以下错误: This operation requires an interactive window

我想运行单元/集成测试,使用Azure存储模拟器,而不是Azure DevOps构建中的真实存储

仿真器作为Azure SDK的一部分安装在上的通常位置(C:\Program Files(x86)\Microsoft SDK\Azure\Storage emulator\AzureStorageEmulator.exe)

但是,仿真器在生成控制器上处于未初始化状态。尝试从命令行运行该命令时,出现以下错误:

This operation requires an interactive window station

是否有已知的解决方法或计划在Azure DevOps版本中支持仿真器?

否,托管的版本控制器不以交互模式运行,因此仿真器无法在该环境下工作。有关详细信息,请参见中的Q&A

问:您需要在交互模式下运行构建服务吗

答:没有。然后您可以使用托管的生成控制器


我建议您设置本地生成控制器,并以交互模式运行生成服务器。有关详细信息,请参阅和。

答案可能来自Visual Studio Online。如果有人有类似的问题,就会有一个条目


我不太清楚为什么模拟器没有非交互模式,我个人99%的时间都不使用它的UI。有一个使Azure存储更易于单元测试的通用条目。

如前所述,您无法运行Azure存储模拟器。不过,您可以运行的是开源替代方案

请注意:Azurite可以模拟blob、表和队列。但是,我仅以这种方式使用blob存储模拟

在构建配置开始时,添加一个运行自定义nuget命令的nuget步骤
install Azurite-version 2.2.2
。然后添加运行
start/b$(Build.SourcesDirectory)\Azurite.2.2.2\tools\blob.exe
的命令行步骤


它与Azure Storage Emulator在同一端口上运行,因此您可以使用标准连接字符串。

尽管这里的答案与此相反,但我已经在VS2017托管的构建代理上运行Azure Storage Emulator一年多了

诀窍是首先初始化SQLLocalDB(仿真器使用它),然后启动仿真器。可以通过运行以下命令行任务来执行此操作:

sqllocaldb create MSSQLLocalDB
sqllocaldb start MSSQLLocalDB
sqllocaldb info MSSQLLocalDB

"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start

如果要在C#中的集成测试代码中正确启动Azure Storage Emulator,可以将其放入测试初始化(启动)代码中(该示例适用于xUnit):

[集合(“数据库集合”)]
公共密封类集成测试
{
公共集成测试(数据库夹具)
{
这个。夹具=夹具;
}
[事实]
公共异步任务TestMethod1()
{
//使用fixture.Table在Azure存储上运行测试
}
专用只读数据库;
}
公共类DatabaseFixture:IDisposable
{
公共数据库fixture()
{
StartProcess(“SqlLocalDB.exe”,“创建MSSQLSLOCALDB”);
StartProcess(“SqlLocalDB.exe”、“启动MSSQLLocalDB”);
StartProcess(“SqlLocalDB.exe”、“info-MSSQLLocalDB”);
StartProcess(执行路径,“开始”);
var client=CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();
Table=client.GetTableReference(“tablename”);
InitAsync().Wait();
}
公共空间处置()
{
Table.DeleteIfExistsAsync().Wait();
StartProcess(执行路径,“停止”);
}
专用异步任务InitAsync()
{
wait Table.DeleteIfExistsAsync();
wait Table.CreateAsync();
}
静态void StartProcess(字符串路径、字符串参数、int waitTime=WAIT\u FOR\u EXIT)=>
Process.Start(路径、参数).WaitForExit(waitTime);
公共云表{get;}
私有常量字符串EXE_路径=
“C:\\ProgramFiles(x86)\\Microsoft SDK\\Azure\\Storage Emulator\\AzureStorageEmulator.exe”;
私人const int WAIT_FOR_EXIT=60_000;
}
[集合定义(“数据库集合”)]
公共类数据库集合:ICollectionFixture
{
//这个类没有代码,也从来没有被创建过
//是应用[CollectionDefinition]和所有
//ICollectionFixture接口。
}

请注意,除了下面的答案之外,即使VSTS承载的生成代理支持交互模式,Azure Storage Emulator仍然无法工作,因为权限不足。看见
[Collection("Database collection")]
public sealed class IntegrationTests
{
    public IntegrationTests(DatabaseFixture fixture)
    {
        this.fixture = fixture;
    }

    [Fact]
    public async Task TestMethod1()
    {
        // use fixture.Table to run tests on the Azure Storage
    }

    private readonly DatabaseFixture fixture;
}

public class DatabaseFixture : IDisposable
{
    public DatabaseFixture()
    {
        StartProcess("SqlLocalDB.exe", "create MSSQLLocalDB");
        StartProcess("SqlLocalDB.exe", "start MSSQLLocalDB");
        StartProcess("SqlLocalDB.exe", "info MSSQLLocalDB");
        StartProcess(EXE_PATH, "start");

        var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();
        Table = client.GetTableReference("tablename");
        InitAsync().Wait();
    }

    public void Dispose()
    {
        Table.DeleteIfExistsAsync().Wait();
        StartProcess(EXE_PATH, "stop");
    }

    private async Task InitAsync()
    {
        await Table.DeleteIfExistsAsync();
        await Table.CreateAsync();
    }

    static void StartProcess(string path, string arguments, int waitTime = WAIT_FOR_EXIT) => 
        Process.Start(path, arguments).WaitForExit(waitTime);

    public CloudTable Table { get; }

    private const string EXE_PATH = 
    "C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe";
    private const int WAIT_FOR_EXIT = 60_000;
}

[CollectionDefinition("Database collection")]
public class DatabaseCollection : ICollectionFixture<DatabaseFixture>
{
    // This class has no code, and is never created. Its purpose is simply
    // to be the place to apply [CollectionDefinition] and all the
    // ICollectionFixture<> interfaces.
}