diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseMigrationClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseMigrationClientTests.cs new file mode 100644 index 00000000..92696efe --- /dev/null +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseMigrationClientTests.cs @@ -0,0 +1,186 @@ +using System; +using System.Collections.Generic; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class EnterpriseMigrationClientTests + { + public class TheGetMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + client.GetStatus("fake", 69); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "orgs/fake/migrations/69")); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + await Assert.ThrowsAsync(() => client.GetStatus(null, 69)); + await Assert.ThrowsAsync(() => client.GetStatus("", 69)); + } + } + + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + client.GetMigrations("fake"); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "orgs/fake/migrations")); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + await Assert.ThrowsAsync(() => client.GetMigrations(null)); + await Assert.ThrowsAsync(() => client.GetMigrations("")); + } + } + + public class TheStartNewMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + var migrationRequest = new StartMigrationRequest(new List { "fake/repo" }); + + client.Start("fake", migrationRequest); + + connection.Received().Post( + Arg.Is(u => u.ToString() == "orgs/fake/migrations"), + migrationRequest); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + var migrationRequest = new StartMigrationRequest(new List { "fake/repo" }); + + await Assert.ThrowsAsync( + () => client.Start(null, migrationRequest)); + await Assert.ThrowsAsync( + () => client.Start("", migrationRequest)); + await Assert.ThrowsAsync( + () => client.Start("fake", null)); + } + + [Fact] + public void PassesRequestBody() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + var migrationRequest = new StartMigrationRequest(new List { "fake/repo" }); + + client.Start("fake", migrationRequest); + + connection.Received().Post( + Arg.Any(), + Arg.Is(m => + m.Repositories.Equals(migrationRequest.Repositories) && + m.LockRepositories == migrationRequest.LockRepositories && + m.ExcludeAttachments == migrationRequest.ExcludeAttachments)); + } + } + + public class TheGetArchiveMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + client.GetArchive("fake", 69); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "orgs/fake/migrations/69/archive")); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + await Assert.ThrowsAsync(() => client.GetArchive(null, 69)); + await Assert.ThrowsAsync(() => client.GetArchive("", 69)); + } + } + + public class TheDeleteArchiveMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + client.DeleteArchive("fake", 69); + + connection.Received().Delete( + Arg.Is(u => u.ToString() == "orgs/fake/migrations/69/archive")); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + await Assert.ThrowsAsync(() => client.DeleteArchive(null, 69)); + await Assert.ThrowsAsync(() => client.DeleteArchive("", 69)); + } + } + + public class TheUnlockRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + client.UnlockRepository("fake", 69, "repo"); + + connection.Received().Delete( + Arg.Is(u => u.ToString() == "orgs/fake/migrations/69/repos/repo/lock")); + } + + [Fact] + public async void EnsuresNonNullAndNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new EnterpriseMigrationsClient(connection); + + await Assert.ThrowsAsync(() => client.UnlockRepository(null, 69, "repo")); + await Assert.ThrowsAsync(() => client.UnlockRepository("", 69, "repo")); + await Assert.ThrowsAsync(() => client.UnlockRepository("fake", 69, null)); + await Assert.ThrowsAsync(() => client.UnlockRepository("fake", 69, "")); + } + } + } +} diff --git a/Octokit.Tests/Models/MigrationTests.cs b/Octokit.Tests/Models/MigrationTests.cs index 27904777..f94f7e4c 100644 --- a/Octokit.Tests/Models/MigrationTests.cs +++ b/Octokit.Tests/Models/MigrationTests.cs @@ -137,4 +137,32 @@ namespace Octokit.Tests.Models Assert.Equal(1296269, _migration.Repositories[0].Id); } } -} \ No newline at end of file + + public class StartMigrationTests + { + const string migrationRequestJson = @"{ + ""repositories"": [ + ""octocat/Hello-World"" + ], + ""lock_repositories"": true +}"; + + private static readonly StartMigrationRequest migrationRequest = new StartMigrationRequest(new List + { + "octocat/Hello-World" + }, true); + + [Fact] + public void CanBeDeserialized() + { + var serializer = new SimpleJsonSerializer(); + + var _migrationReuqest = serializer.Deserialize(migrationRequestJson); + + Assert.Equal("octokit/Hello-World", _migrationReuqest.Repositories[0]); + Assert.Equal(1, _migrationReuqest.Repositories.Count); + Assert.Equal(true, _migrationReuqest.LockRepositories); + } + + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 84d605d4..56d86993 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -87,6 +87,7 @@ +