Skip to content

Commit

Permalink
Merge branch 'release/0.75.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Apr 5, 2024
2 parents 895d17c + 5f01f03 commit dd5eb23
Show file tree
Hide file tree
Showing 36 changed files with 916 additions and 515 deletions.
43 changes: 0 additions & 43 deletions Source/ZoomNet.IntegrationTests/ConsoleUtils.cs

This file was deleted.

52 changes: 0 additions & 52 deletions Source/ZoomNet.IntegrationTests/NativeMethods.cs

This file was deleted.

56 changes: 38 additions & 18 deletions Source/ZoomNet.IntegrationTests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
using Logzio.DotNet.NLog;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Config;
using NLog.Extensions.Logging;
using NLog.Targets;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ZoomNet.IntegrationTests
{
public class Program
{
public static async Task<int> Main(string[] args)
public static async Task Main(string[] args)
{
//var serializerContext = GenerateAttributesForSerializerContext();

var services = new ServiceCollection();
ConfigureServices(services);
await using var serviceProvider = services.BuildServiceProvider();
var app = serviceProvider.GetService<TestsRunner>();
return await app.RunAsync().ConfigureAwait(false);
var builder = Host.CreateApplicationBuilder();
builder.Services.AddHostedService<TestsRunner>();

// Configure cancellation (this allows you to press CTRL+C or CTRL+Break to stop the integration tests)
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
cts.Cancel();
};

// Configure logging
builder.Logging.ClearProviders(); // Remove the built-in providers (which include the Console)
builder.Logging.AddNLog(GetNLogConfiguration()); // Add our desired custom providers (which include the Colored Console)

// Run the tests
var host = builder.Build();
await host.StartAsync(cts.Token).ConfigureAwait(false);

// Stop NLog (which has the desirable side-effect of flushing any pending logs)
LogManager.Shutdown();
}

private static string GenerateAttributesForSerializerContext()
Expand Down Expand Up @@ -59,17 +79,10 @@ private static string GenerateAttributesForSerializerContext()
var arrayAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttributeArray)).Select(t => t.JsonSerializeAttributeArray));
var nullableAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttributeNullable)).Select(t => t.JsonSerializeAttributeNullable));

var result = string.Join("\r\n\r\n", new[] { simpleAttributes, arrayAttributes, nullableAttributes });
var result = string.Join("\r\n\r\n", [simpleAttributes, arrayAttributes, nullableAttributes]);
return result;
}

private static void ConfigureServices(ServiceCollection services)
{
services
.AddLogging(loggingBuilder => loggingBuilder.AddNLog(GetNLogConfiguration()))
.AddTransient<TestsRunner>();
}

private static LoggingConfiguration GetNLogConfiguration()
{
// Configure logging
Expand All @@ -79,18 +92,25 @@ private static LoggingConfiguration GetNLogConfiguration()
var logzioToken = Environment.GetEnvironmentVariable("LOGZIO_TOKEN");
if (!string.IsNullOrEmpty(logzioToken))
{
var logzioTarget = new LogzioTarget { Token = logzioToken };
logzioTarget.ContextProperties.Add(new TargetPropertyWithContext("source", "ZoomNet_integration_tests"));
var logzioTarget = new LogzioTarget
{
Name = "Logzio",
Token = logzioToken,
LogzioType = "nlog",
JsonKeysCamelCase = true,
// ProxyAddress = "http://localhost:8888",
};
logzioTarget.ContextProperties.Add(new TargetPropertyWithContext("Source", "ZoomNet_integration_tests"));
logzioTarget.ContextProperties.Add(new TargetPropertyWithContext("ZoomNet-Version", ZoomNet.ZoomClient.Version));

nLogConfig.AddTarget("Logzio", logzioTarget);
nLogConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, "Logzio", "*");
nLogConfig.AddRule(NLog.LogLevel.Info, NLog.LogLevel.Fatal, logzioTarget, "*");
}

// Send logs to console
var consoleTarget = new ColoredConsoleTarget();
nLogConfig.AddTarget("ColoredConsole", consoleTarget);
nLogConfig.AddRule(NLog.LogLevel.Warn, NLog.LogLevel.Fatal, consoleTarget, "*");
nLogConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, consoleTarget, "*");
nLogConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, consoleTarget, "ZoomNet.ZoomWebSocketClient");

return nLogConfig;
Expand Down
22 changes: 4 additions & 18 deletions Source/ZoomNet.IntegrationTests/TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@ public TestSuite(IConnectionInfo connectionInfo, IWebProxy proxy, ILoggerFactory
FetchCurrentUserInfo = fetchCurrentUserInfo;
}

public virtual async Task<ResultCodes> RunTestsAsync()
public virtual async Task<ResultCodes> RunTestsAsync(CancellationToken cancellationToken)
{
// Configure cancellation
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
cts.Cancel();
};

// Configure ZoomNet client
var client = new ZoomClient(ConnectionInfo, Proxy, null, LoggerFactory.CreateLogger<ZoomClient>());

Expand All @@ -53,8 +45,8 @@ public virtual async Task<ResultCodes> RunTestsAsync()

if (FetchCurrentUserInfo)
{
currentUser = await client.Users.GetCurrentAsync(cts.Token).ConfigureAwait(false);
currentUserPermissions = await client.Users.GetCurrentPermissionsAsync(cts.Token).ConfigureAwait(false);
currentUser = await client.Users.GetCurrentAsync(cancellationToken).ConfigureAwait(false);
currentUserPermissions = await client.Users.GetCurrentPermissionsAsync(cancellationToken).ConfigureAwait(false);
Array.Sort(currentUserPermissions); // Sort permissions alphabetically for convenience
}

Expand All @@ -67,7 +59,7 @@ public virtual async Task<ResultCodes> RunTestsAsync()
try
{
var integrationTest = (IIntegrationTest)Activator.CreateInstance(testType);
await integrationTest.RunAsync(currentUser, currentUserPermissions, client, log, cts.Token).ConfigureAwait(false);
await integrationTest.RunAsync(currentUser, currentUserPermissions, client, log, cancellationToken).ConfigureAwait(false);
return (TestName: testType.Name, ResultCode: ResultCodes.Success, Message: SUCCESSFUL_TEST_MESSAGE);
}
catch (OperationCanceledException)
Expand Down Expand Up @@ -106,12 +98,6 @@ public virtual async Task<ResultCodes> RunTestsAsync()
await summary.WriteLineAsync("**************************************************").ConfigureAwait(false);
await Console.Out.WriteLineAsync(summary.ToString()).ConfigureAwait(false);

// Prompt user to press a key in order to allow reading the log in the console
var promptLog = new StringWriter();
await promptLog.WriteLineAsync("\n\n**************************************************").ConfigureAwait(false);
await promptLog.WriteLineAsync("Press any key to exit").ConfigureAwait(false);
ConsoleUtils.Prompt(promptLog.ToString());

// Return code indicating success/failure
var resultCode = ResultCodes.Success;
if (results.Any(result => result.ResultCode != ResultCodes.Success))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public WebSocketsTestSuite(IConnectionInfo connectionInfo, string subscriptionId
_subscriptionId = subscriptionId;
}

public override async Task<ResultCodes> RunTestsAsync()
public override async Task<ResultCodes> RunTestsAsync(CancellationToken cancellationToken)
{
var logger = base.LoggerFactory.CreateLogger<ZoomWebSocketClient>();
var eventProcessor = new Func<Event, CancellationToken, Task>(async (webhookEvent, cancellationToken) =>
Expand All @@ -27,18 +27,16 @@ public override async Task<ResultCodes> RunTestsAsync()
});

// Configure cancellation (this allows you to press CTRL+C or CTRL+Break to stop the websocket client)
var cts = new CancellationTokenSource();
var exitEvent = new ManualResetEvent(false);
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
cts.Cancel();
exitEvent.Set();
};

// Start the websocket client
using var client = new ZoomWebSocketClient(base.ConnectionInfo, _subscriptionId, eventProcessor, base.Proxy, logger);
await client.StartAsync(cts.Token).ConfigureAwait(false);
await client.StartAsync(cancellationToken).ConfigureAwait(false);
exitEvent.WaitOne();

return ResultCodes.Success;
Expand Down
10 changes: 5 additions & 5 deletions Source/ZoomNet.IntegrationTests/Tests/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ public async Task RunAsync(User myUser, string[] myPermissions, IZoomClient clie
{
await client.Chat.DeleteChannelAsync(oldChannel.Id, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Channel {oldChannel.Id} deleted").ConfigureAwait(false);
await Task.Delay(250, cancellationToken).ConfigureAwait(false); // Brief pause to ensure Zoom has time to catch up
await Task.Delay(1000, cancellationToken).ConfigureAwait(false); // Brief pause to ensure Zoom has time to catch up
});
await Task.WhenAll(cleanUpTasks).ConfigureAwait(false);

// CREATE A NEW CHANNEL
var channel = await client.Chat.CreateAccountChannelAsync(myUser.Id, "ZoomNet Integration Testing: new channel", ChatChannelType.Public, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Account channel \"{channel.Name}\" created (Id={channel.Id}").ConfigureAwait(false);

// UPDATE THE CHANNEL
await client.Chat.UpdateAccountChannelAsync(myUser.Id, channel.Id, "ZoomNet Integration Testing: updated channel", cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Account channel \"{channel.Id}\" updated").ConfigureAwait(false);

// RETRIEVE THE CHANNEL
channel = await client.Chat.GetAccountChannelAsync(myUser.Id, channel.Id, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Account channel \"{channel.Id}\" retrieved").ConfigureAwait(false);

// UPDATE THE CHANNEL
await client.Chat.UpdateAccountChannelAsync(myUser.Id, channel.Id, "ZoomNet Integration Testing: updated channel", channel.Settings, channel.Type, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Account channel \"{channel.Id}\" updated").ConfigureAwait(false);

// RETRIEVE THE CHANNEL MEMBERS
var paginatedMembers = await client.Chat.GetAccountChannelMembersAsync(myUser.Id, channel.Id, 10, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Account channel \"{channel.Id}\" has {paginatedMembers.TotalRecords} members").ConfigureAwait(false);
Expand Down
13 changes: 6 additions & 7 deletions Source/ZoomNet.IntegrationTests/Tests/Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ public async Task RunAsync(User myUser, string[] myPermissions, IZoomClient clie

await log.WriteLineAsync("\n***** CONTACTS *****\n").ConfigureAwait(false);

// GET THE CONTACTS FOR THIS USER
var paginatedInternalContacts = await client.Contacts.GetAllAsync(ContactType.Internal, 50, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"There are {paginatedInternalContacts.TotalRecords} internal contacts for user {myUser.Id}").ConfigureAwait(false);

var paginatedExternalContacts = await client.Contacts.GetAllAsync(ContactType.External, 50, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"There are {paginatedExternalContacts.TotalRecords} external contacts for user {myUser.Id}").ConfigureAwait(false);

var paginatedSearchedContacts = await client.Contacts.SearchAsync("zzz", true, 1, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"Found {paginatedSearchedContacts.TotalRecords} contacts").ConfigureAwait(false);

var contact = await client.Contacts.GetAsync(myUser.Id, true, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"{contact.EmailAddress} is {contact.PresenceStatus}").ConfigureAwait(false);

var paginatedInternalContacts = await client.Contacts.GetAllAsync(ContactType.Internal, 50, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"There are {paginatedInternalContacts.TotalRecords} internal contacts for user {myUser.Id}").ConfigureAwait(false);

var paginatedExternalContacts = await client.Contacts.GetAllAsync(ContactType.External, 50, null, cancellationToken).ConfigureAwait(false);
await log.WriteLineAsync($"There are {paginatedExternalContacts.TotalRecords} external contacts for user {myUser.Id}").ConfigureAwait(false);
}
}
}
18 changes: 9 additions & 9 deletions Source/ZoomNet.IntegrationTests/TestsRunner.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using ZoomNet.IntegrationTests.TestSuites;

namespace ZoomNet.IntegrationTests
{
internal class TestsRunner
internal class TestsRunner : IHostedService
{
private enum TestType
{
Expand All @@ -31,7 +33,7 @@ public TestsRunner(ILoggerFactory loggerFactory)
_loggerFactory = loggerFactory;
}

public async Task<int> RunAsync()
public async Task StartAsync(CancellationToken cancellationToken)
{
// -----------------------------------------------------------------------------
// Do you want to proxy requests through a tool such as Fiddler? Very useful for debugging.
Expand All @@ -47,10 +49,6 @@ public async Task<int> RunAsync()
var connectionType = ConnectionType.OAuthServerToServer;
// -----------------------------------------------------------------------------

// Ensure the Console is tall enough and centered on the screen
if (OperatingSystem.IsWindows()) Console.WindowHeight = Math.Min(60, Console.LargestWindowHeight);
ConsoleUtils.CenterConsole();

// Configure the proxy if desired
var proxy = useProxy ? new WebProxy($"http://localhost:{proxyPort}") : null;

Expand All @@ -59,10 +57,12 @@ public async Task<int> RunAsync()
var testSuite = GetTestSuite(connectionInfo, testType, proxy, _loggerFactory);

// Run the tests
var resultCode = await testSuite.RunTestsAsync().ConfigureAwait(false);
await testSuite.RunTestsAsync(cancellationToken).ConfigureAwait(false);
}

// Return result
return (int)resultCode;
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

private static IConnectionInfo GetConnectionInfo(ConnectionType connectionType)
Expand Down
10 changes: 8 additions & 2 deletions Source/ZoomNet.IntegrationTests/ZoomNet.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@

<ItemGroup>
<PackageReference Include="Logzio.DotNet.NLog" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />

<!-- This is a workaround for the problem described here: https://github.com/logzio/logzio-dotnet/issues/72 -->
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit dd5eb23

Please sign in to comment.