This repository has been archived on 2025-05-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
novaloop.paymoapi/tests/DependencyFactory.cs

35 lines
1.3 KiB
C#

using System;
using System.Net.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Novaloop.PaymoApi.Extensions;
using Novaloop.PaymoApi.Shared;
namespace Novaloop.PaymoApi.Tests
{
public static class DependencyFactory
{
public static ApiClient GeneratePaymoApiClient()
{
return new ApiClient(new HttpClient(new LoggingHandler(new HttpClientHandler(), new NullLogger<LoggingHandler>())) {BaseAddress = new Uri("https://app.paymoapp.com/")});
}
public static IOptions<ApiOptions> GenerateOptions()
{
var paymoToken = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.tests.json", true, true)
.AddEnvironmentVariables()
.Build()
.GetSection("PaymoApiIntegrationTests:PaymoTestProjectToken").Value;
if (string.IsNullOrWhiteSpace(paymoToken))
{
throw new ArgumentException("Please set the environment variable 'PAYMOAPIINTEGRATIONTESTS__PAYMOTESTPROJECTTOKEN' with the token of your paymo test-project. Look inside Bitwarden if you work @ Novaloop.");
}
return Options.Create(new ApiOptions {ApiToken = paymoToken});
}
}
}