Код: Выделить всё
public ApiWorkerTests()
{
_mockLogger = new Mock();
_mockDbService = new Mock();
_mockApiService = new Mock();
_mockConfig = new Mock();
_mockConfig.Setup(c => c[$"Authentication:CompanyKey"]).Returns("SomeKey");
_mockConfig.Setup(c => c[$"Authentication:VehicleKey"]).Returns("SomeKey");
_mockConfig.Setup(c => c["Interval"]).Returns("00:00:10");
}
[Fact]
public void ApiWorker_Initialization()
{
// Arrange & Act
var worker = new ApiWorker(_mockApiService.Object, _mockLogger.Object, _mockConfig.Object, _mockDbService.Object);
// Assert
Assert.NotNull(worker);
}
Код: Выделить всё
public ApiWorker(IApiService apiService, ILogger logger, IConfiguration config, IDatabaseService db)
{
_apiService = apiService;
_logger = logger;
_db = db;
_companyKey = config[$"Authentication:CompanyKey"] ?? throw new Exception("Company ID cannot be null");
_vehicleKey = config[$"Authentication:VehicleKey"] ?? throw new Exception("Vehicle ID cannot be null");
_config = config;
SetInterval();
}
private void SetInterval()
{
var intervalString = _config.GetValue("Interval");
// Conversion to DateTime
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -using-moq