Skip to content

Commit

Permalink
bring tests from unrelated PR into this project (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftkey authored Sep 22, 2019
1 parent c78b3cf commit 7c31109
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@ internal static async Task<GpgKeyContext> CreateGpgKeyContext(this IObservableGi

return new GpgKeyContext(client.Connection, key);
}

internal static MaintenanceModeContext CreateMaintenanceModeContext(this IObservableGitHubClient client, bool enabled)
{
return new MaintenanceModeContext(client.Connection, enabled);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Octokit.Tests.Integration.Helpers;
using Xunit;

namespace Octokit.Tests.Integration
{
public class ObservableEnterpriseManagementConsoleTests
{
readonly IObservableGitHubClient _github;

public ObservableEnterpriseManagementConsoleTests()
{
_github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient());
}

[GitHubEnterpriseManagementConsoleTest]
public async Task CanGetMaintenanceMode()
{
var maintenance = await _github.Enterprise.ManagementConsole.GetMaintenanceMode(EnterpriseHelper.ManagementConsolePassword);

Assert.NotNull(maintenance);
}

[GitHubEnterpriseManagementConsoleTest]
public async Task CanSetMaintenanceModeOff()
{
using (_github.CreateMaintenanceModeContext(true))
{
// Set maintenance mode OFF now
var maintenance = await
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
new UpdateMaintenanceRequest(),
EnterpriseHelper.ManagementConsolePassword);

Assert.Equal(MaintenanceModeStatus.Off, maintenance.Status);
}
}

[GitHubEnterpriseManagementConsoleTest]
public async Task CanSetMaintenanceModeOnNow()
{
using (_github.CreateMaintenanceModeContext(false))
{
// Set maintenance mode ON now
var maintenance = await
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
new UpdateMaintenanceRequest(
new UpdateMaintenanceRequestDetails(true)),
EnterpriseHelper.ManagementConsolePassword);

Assert.Equal(MaintenanceModeStatus.On, maintenance.Status);
}
}

[GitHubEnterpriseManagementConsoleTest]
public async Task CanScheduleMaintenanceModeOnWithDateTime()
{
using (_github.CreateMaintenanceModeContext(false))
{
// Schedule maintenance mode ON in 5 minutes
var scheduledTime = DateTimeOffset.Now.AddMinutes(5);
var maintenance = await
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
new UpdateMaintenanceRequest(
new UpdateMaintenanceRequestDetails(true, scheduledTime)),
EnterpriseHelper.ManagementConsolePassword);

Assert.Equal(MaintenanceModeStatus.Scheduled, maintenance.Status);
}
}

[GitHubEnterpriseManagementConsoleTest]
public async Task CanScheduleMaintenanceModeOnWithPhrase()
{
using (_github.CreateMaintenanceModeContext(false))
{
// Schedule maintenance mode ON with phrase
var maintenance = await
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
new UpdateMaintenanceRequest(
new UpdateMaintenanceRequestDetails(true, "tomorrow at 5pm")),
EnterpriseHelper.ManagementConsolePassword);

Assert.Equal(MaintenanceModeStatus.Scheduled, maintenance.Status);
}
}
}
}

0 comments on commit 7c31109

Please sign in to comment.