Sossenbinder
Sossenbinder
CC#
Created by Sossenbinder on 8/27/2023 in #help
❔ xUnit single setup and teardown
Hello, So, I'm currently in the progress of switching from NUnit to XUnit and I was wondering how I could achieve this behaviour: I have a test class containing around 10 integration tests. This class inherits from a base class which prepares test containers for this context. The goal would be: - Call the base classes constructor once, which prepares the testcontainer - For every test, call an initialize to start the container before the test, and a teardown to stop the container after the test - After all 10 tests ran, call a single teardown which makes sure the container is gone. With NUnit this was fairly easy, but I'm not entirely sure how to recreate this behaviour with xUnit, since it would create a new instance of the test class for every test, it also passes the testcontainer preparation logic for every invocation. There are ways around this with static fields / properties, but I don't feel like this is the clean approach here. Any advice?
11 replies
CC#
Created by Sossenbinder on 1/11/2023 in #help
❔ Configuring loglevel of injected ILogger
I'm attempting to configure the loglevel of a custom ILogger<T> through configuration. Is this easily possible? In my custom case I'm injecting an ILogger<DataHandledLoggingHandler> into my class, and would like to disable it in certain environments. What I assumed should work is to add a key "DataHandledLoggingHandler" to the Logging.LogLevel section of appsettings.json, to e.g. "Error". However, I still see Warnings in my log sink. I've also attempted the fully qualified name, including namespace, but still no luck. I do use Serilog with Seq and Console sink right now, but got it hooked up to ILogger through the Serilog.Extensions.Logging package.
3 replies