How to overwrite settings from appsettings.json in ABP Framework

351 Views Asked by At

Let's say I have this in appsettings.json:

{
  "Sample": {
    "Setting1": "ORIGINAL_VALUE"
   }
}

When creating a normal ASP.NET integration tests, I can override that setting using code like this:

var updatedValueForSetting1 = "UPDATED_VALUE";
var Factory = _factory
    .WithWebHostBuilder(builder =>
    {
        builder.UseSetting("Sample:Setting1", updatedValueForSetting1);
    });

I would like to ask how to do override that setting in ABP Framework's integration tests. If this is a dumb question, please pardon me because I'm still new to ABP.

I would just like to mention that I found out a way of doing it, by using IOptions, like this:

public class SampleOptions
{
    public string Setting1 { get; set; } // NOTE: public setter
}
public class SampleModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var configuration = context.Services.GetConfiguration();
        Configure<SampleOptions>(configuration.GetSection("Sample"));
    }
}
public abstract class SampleApplicationTestBase : SampleTestBase<SampleApplicationTestModule>
{
    public SampleApplicationTestBase()
    {
        var sampleOptions = GetRequiredService<IOptions<SampleOptions>>();
        sampleOptions.Value.Setting1 = "UPDATED_VALUE";
    }
}

But I still want to know if there is a way of doing it like in normal ASP.NET tests, like this: builder.UseSetting("Sample:Setting1", updatedValueForSetting1);

Thanks.

0

There are 0 best solutions below