Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core 如何配置.net core 3.1 appsettings以在Github操作上运行测试_.net Core_Integration Testing_Github Actions - Fatal编程技术网

.net core 如何配置.net core 3.1 appsettings以在Github操作上运行测试

.net core 如何配置.net core 3.1 appsettings以在Github操作上运行测试,.net-core,integration-testing,github-actions,.net Core,Integration Testing,Github Actions,我正在使用.Net core 3.1开发一个web API,试图将其集成到Github操作中,以便在创建拉请求时运行集成测试 我在开发模式中使用存储API令牌和其他敏感数据 secrets.json 在GitHub上,我尝试使用与我的Secrets JSON相同的名称添加Secrets(),但没有成功。 我创建的GitHub秘密如下 (KEY - VALUE) LOGIN - foo@bar.com PASSWORD - FooBar 在我的测试类中,我在测试之前使用以下配置调用环境变量 p

我正在使用.Net core 3.1开发一个web API,试图将其集成到Github操作中,以便在创建拉请求时运行集成测试

我在开发模式中使用存储API令牌和其他敏感数据

secrets.json

在GitHub上,我尝试使用与我的Secrets JSON相同的名称添加Secrets(),但没有成功。 我创建的GitHub秘密如下

(KEY - VALUE)
LOGIN - foo@bar.com 
PASSWORD - FooBar
在我的测试类中,我在测试之前使用以下配置调用环境变量

public MyTestClass()
{           
    var builder = new ConfigurationBuilder() 
        .AddUserSecrets<MyTestClass>()
        .AddEnvironmentVariables();

    Configuration = builder.Build();
    _settings = Configuration.Get<Settings>();
}

在GitHub内部执行操作时,如何加载设置?

不确定我是否没有说明明显的问题(您没有提到如何启动测试应用程序),但GitHub机密=环境变量。如果用户需要,它们可以是,但不是自动完成的

-运行:program.exe
在这种情况下,程序将不知道登录名/密码,因为它无法访问这些数据

-运行:program.exe
环境:
登录:${secrets.LOGIN}
密码:${secrets.PASSWORD}
在这种情况下,程序将知道登录名/密码,因为机密被“转换”为应用程序可以看到的环境变量

-run:program.exe--login=${{{secrets.login}}--password=${{{secrets.password}}
在这种情况下,程序将知道登录名/密码,因为机密是通过命令行参数传递的,应用程序可以看到。在这种情况下,环境变量保持不变


另一种选择是在存储库中保存encrypted secrets.json,并在工作流运行时对其进行解密;有关详细信息,请参阅。

He@Samira,感谢您的见解,我已使用当前的.yml更新了我的问题。我想知道我是否在c#端的测试设置中遗漏了一些东西,或者我是否必须以与json配置匹配的方式设置环境变量,因此解决方案最终与我如何创建环境变量有关。我必须让它们与我的课程结构相匹配。在本例中,Settings.Firebase.Login具有env变量=Firebase\uuu Login
public MyTestClass()
{           
    var builder = new ConfigurationBuilder() 
        .AddUserSecrets<MyTestClass>()
        .AddEnvironmentVariables();

    Configuration = builder.Build();
    _settings = Configuration.Get<Settings>();
}
jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.300
    - name: Nuget
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal
      env: 
        LOGIN: ${{ secrets.LOGIN }}
        PASSWORD: ${{ secrets.PASSWORD}}
        URL: ${{ secrets.URL}}