Skip to content

Commit

Permalink
Merge branch 'enh-sans-mono' of https://github.com/OctopusDeploy/Octo…
Browse files Browse the repository at this point in the history
…pusClients into enh-sans-mono
  • Loading branch information
MJRichardson committed Jul 31, 2017
2 parents 129815a + 89a8b0f commit 2c35d6b
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 3 deletions.
105 changes: 105 additions & 0 deletions source/Octopus.Client.Tests/Conventions/ClientConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,113 @@ public void MostSyncRepositoriesThatGetResourcesShouldImplementIPaginate()
}
#endif

[Test]
public void AsyncRepositoriesThatImplementCreateShouldAlsoImplementModify()
{
var ignored = new []
{
typeof(IDeploymentRepository).GetTypeInfo(),
typeof(ITaskRepository).GetTypeInfo()
};

var createsResources = AsyncRepositoryInterfaceTypes
.Except(ignored)
.Where(t => t.AsType().IsAssignableToGenericType(typeof(ICreate<>)))
.ToArray();

var alsoImplementsModify = createsResources
.Where(t => t.GetInterfaces().Any(i => i.IsClosedTypeOf(typeof(IModify<>))))
.ToArray();

var missingModify = createsResources.Except(alsoImplementsModify).ToArray();

if (missingModify.Any())
{
Assert.Fail($"Repositories that implement ICreate<IResource> should usually implement IModify<IResource>.{Environment.NewLine}{missingModify.Select(t => t.Name).NewLineSeperate()}");
}
}

#if SYNC_CLIENT
[Test]
public void SyncRepositoriesThatImplementCreateShouldAlsoImplementModify()
{
var ignored = new[]
{
typeof(Sync.IDeploymentRepository).GetTypeInfo(),
typeof(Sync.ITaskRepository).GetTypeInfo()
};

var createsResources = SyncRepositoryInterfaceTypes
.Except(ignored)
.Where(t => t.AsType().IsAssignableToGenericType(typeof(ICreate<>)))
.ToArray();

var alsoImplementsModify = createsResources
.Where(t => t.GetInterfaces().Any(i => i.IsClosedTypeOf(typeof(IModify<>))))
.ToArray();

var missingModify = createsResources.Except(alsoImplementsModify).ToArray();

if (missingModify.Any())
{
Assert.Fail($"Repositories that implement ICreate<IResource> should usually implement IModify<IResource>.{Environment.NewLine}{missingModify.Select(t => t.Name).NewLineSeperate()}");
}
}
#endif

[Test]
public void AsyncRepositoriesThatImplementCreateShouldAlsoImplementDelete()
{
var ignored = new[]
{
typeof(IDeploymentRepository).GetTypeInfo(),
typeof(ITaskRepository).GetTypeInfo()
};

var createsResources = AsyncRepositoryInterfaceTypes
.Except(ignored)
.Where(t => t.AsType().IsAssignableToGenericType(typeof(ICreate<>)))
.ToArray();

var alsoImplementsDelete = createsResources
.Where(t => t.GetInterfaces().Any(i => i.IsClosedTypeOf(typeof(IDelete<>))))
.ToArray();

var missingDelete = createsResources.Except(alsoImplementsDelete).ToArray();

if (missingDelete.Any())
{
Assert.Fail($"Repositories that implement ICreate<IResource> should usually implement IDelete<IResource>.{Environment.NewLine}{missingDelete.Select(t => t.Name).NewLineSeperate()}");
}
}

#if SYNC_CLIENT
[Test]
public void SyncRepositoriesThatImplementCreateShouldAlsoImplementDelete()
{
var ignored = new[]
{
typeof(Sync.IDeploymentRepository).GetTypeInfo(),
typeof(Sync.ITaskRepository).GetTypeInfo()
};

var createsResources = SyncRepositoryInterfaceTypes
.Except(ignored)
.Where(t => t.AsType().IsAssignableToGenericType(typeof(ICreate<>)))
.ToArray();

var alsoImplementsDelete = createsResources
.Where(t => t.GetInterfaces().Any(i => i.IsClosedTypeOf(typeof(IDelete<>))))
.ToArray();

var missingDelete = createsResources.Except(alsoImplementsDelete).ToArray();

if (missingDelete.Any())
{
Assert.Fail($"Repositories that implement ICreate<IResource> should usually implement IDelete<IResource>.{Environment.NewLine}{missingDelete.Select(t => t.Name).NewLineSeperate()}");
}
}
#endif

#if HAS_BEST_CONVENTIONAL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Octopus.Client.Tests.Conventions
{
public class RepositorySymetryConventions
public class RepositorySymmetryConventions
{
[Test]
public void IOctopusAsyncRepositoryExposesTheSamePropertiesAsIOctopusRepository()
Expand Down Expand Up @@ -102,6 +102,45 @@ public void AllSyncRepositoriesShouldHaveEquivalentSignaturesToTheAsyncRepositor

}

[TestCaseSource(nameof(AsyncRepositories))]
public void AllAsyncRepositoriesShouldImplementEquivalentInterfacesToTheSyncRepositories(Type asyncRepository)
{
var syncRepository = typeof(IOctopusAsyncRepository).Assembly
.GetExportedTypes()
.FirstOrDefault(t => t.Name == asyncRepository.Name && !t.Namespace.EndsWith("Async"));

if (syncRepository == null)
Assert.Fail("Sync repository not found");

var asyncInterfaces = asyncRepository.GetInterfaces().Select(i => i.ToString().Replace(i.Namespace, string.Empty).TrimStart('.')).ToArray();
var syncInterfaces = syncRepository.GetInterfaces().Select(i => i.ToString().Replace(i.Namespace, string.Empty).TrimStart('.')).ToArray();

var missing = syncInterfaces.Except(asyncInterfaces).ToArray();

if (missing.Any())
Assert.Fail($"The following interfaces are implemented on the sync {syncRepository.Name} but not on the async one:\r\n{missing.NewLineSeperate()}");
}

[TestCaseSource(nameof(SyncRepositories))]
public void AllSyncRepositoriesShouldImplementEquivalentInterfacesToTheAsyncRepositories(Type syncRepository)
{
var asyncRepository = typeof(IOctopusAsyncRepository).Assembly
.GetExportedTypes()
.FirstOrDefault(t => t.Name == syncRepository.Name && t.Namespace.EndsWith("Async"));

if (asyncRepository == null)
Assert.Fail("Async repository not found");

var asyncInterfaces = asyncRepository.GetInterfaces().Select(i => i.ToString().Replace(i.Namespace, string.Empty).TrimStart('.')).ToArray();
var syncInterfaces = syncRepository.GetInterfaces().Select(i => i.ToString().Replace(i.Namespace, string.Empty).TrimStart('.')).ToArray();

var missing = asyncInterfaces.Except(syncInterfaces).ToArray();

if (missing.Any())
Assert.Fail($"The following interfaces are implemented on the async {asyncRepository.Name} but not on the sync one:\r\n{missing.NewLineSeperate()}");

}

bool IsEquivalentReturnType(Type asyncType, Type syncType)
{
if (asyncType.Name == syncType.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3927,6 +3927,7 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IGet<UserRoleResource>
Octopus.Client.Repositories.Async.ICreate<UserRoleResource>
Octopus.Client.Repositories.Async.IModify<UserRoleResource>
Octopus.Client.Repositories.Async.IDelete<UserRoleResource>
{
}
interface IVariableSetRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4332,6 +4332,7 @@ Octopus.Client.Repositories
Octopus.Client.Repositories.IGet<UserRoleResource>
Octopus.Client.Repositories.ICreate<UserRoleResource>
Octopus.Client.Repositories.IModify<UserRoleResource>
Octopus.Client.Repositories.IDelete<UserRoleResource>
{
}
interface IVariableSetRepository
Expand Down Expand Up @@ -4778,6 +4779,7 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IGet<UserRoleResource>
Octopus.Client.Repositories.Async.ICreate<UserRoleResource>
Octopus.Client.Repositories.Async.IModify<UserRoleResource>
Octopus.Client.Repositories.Async.IDelete<UserRoleResource>
{
}
interface IVariableSetRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Octopus.Client.Repositories.Async
{
public interface IUserRolesRepository : IFindByName<UserRoleResource>, IGet<UserRoleResource>, ICreate<UserRoleResource>, IModify<UserRoleResource>
public interface IUserRolesRepository : IFindByName<UserRoleResource>, IGet<UserRoleResource>, ICreate<UserRoleResource>, IModify<UserRoleResource>, IDelete<UserRoleResource>
{
}

Expand Down
2 changes: 1 addition & 1 deletion source/Octopus.Client/Repositories/UserRolesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Octopus.Client.Repositories
{
public interface IUserRolesRepository : IFindByName<UserRoleResource>, IGet<UserRoleResource>, ICreate<UserRoleResource>, IModify<UserRoleResource>
public interface IUserRolesRepository : IFindByName<UserRoleResource>, IGet<UserRoleResource>, ICreate<UserRoleResource>, IModify<UserRoleResource>, IDelete<UserRoleResource>
{
}

Expand Down

0 comments on commit 2c35d6b

Please sign in to comment.