Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport tests into main project #2013

Merged
merged 1 commit into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}