Files
Discord.Net/test/Discord.Net.Tests.Integration/DiscordRestClientFixture.cs
Christopher Felegy 3c6b3765ab test: target the Process env-var scope
This allows the integration tests to be run on unix-based systems.
2019-09-08 11:27:20 -04:00

35 lines
1.1 KiB
C#

using Discord.Rest;
using System;
using Xunit;
namespace Discord
{
/// <summary>
/// Test fixture type for integration tests which sets up the client from
/// the token provided in environment variables.
/// </summary>
public class DiscordRestClientFixture : IDisposable
{
public DiscordRestClient Client { get; private set; }
public DiscordRestClientFixture()
{
var token = Environment.GetEnvironmentVariable("DNET_TEST_TOKEN", EnvironmentVariableTarget.Process);
if (string.IsNullOrWhiteSpace(token))
throw new Exception("The DNET_TEST_TOKEN environment variable was not provided.");
Client = new DiscordRestClient(new DiscordRestConfig()
{
LogLevel = LogSeverity.Debug,
DefaultRetryMode = RetryMode.AlwaysRetry
});
Client.LoginAsync(TokenType.Bot, token).Wait();
}
public void Dispose()
{
Client.LogoutAsync().Wait();
Client.Dispose();
}
}
}