From 91e553e5decd2c30570c9e27385838b308423c4d Mon Sep 17 00:00:00 2001 From: Andreas Gruenwald Date: Wed, 13 Oct 2021 14:37:56 +0200 Subject: [PATCH] test: Add test to verify the assembly's public API surface --- .../Cake.GitHubReleases.Test.csproj | 4 +- ...t_have_unapproved_API_changes.verified.txt | 74 +++++++++++++++++++ .../PublicApiApproval.cs | 26 +++++++ .../Cake.GitHubReleases.csproj | 3 +- src/Cake.GitHubReleases/Nullable.cs | 2 +- 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 src/Cake.GitHubReleases.Test/PublicApiApproval.Assembly_does_not_have_unapproved_API_changes.verified.txt create mode 100644 src/Cake.GitHubReleases.Test/PublicApiApproval.cs diff --git a/src/Cake.GitHubReleases.Test/Cake.GitHubReleases.Test.csproj b/src/Cake.GitHubReleases.Test/Cake.GitHubReleases.Test.csproj index 7ec8aac..891d10a 100644 --- a/src/Cake.GitHubReleases.Test/Cake.GitHubReleases.Test.csproj +++ b/src/Cake.GitHubReleases.Test/Cake.GitHubReleases.Test.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -10,9 +10,11 @@ + + diff --git a/src/Cake.GitHubReleases.Test/PublicApiApproval.Assembly_does_not_have_unapproved_API_changes.verified.txt b/src/Cake.GitHubReleases.Test/PublicApiApproval.Assembly_does_not_have_unapproved_API_changes.verified.txt new file mode 100644 index 0000000..d850ef0 --- /dev/null +++ b/src/Cake.GitHubReleases.Test/PublicApiApproval.Assembly_does_not_have_unapproved_API_changes.verified.txt @@ -0,0 +1,74 @@ +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Cake.GitHubReleases.Test")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")] +namespace Cake.GitHubReleases +{ + public class AmbiguousTagNameException : Cake.GitHubReleases.GitHubReleaseException + { + public AmbiguousTagNameException(string message) { } + } + public sealed class AssetConflictException : Cake.GitHubReleases.GitHubReleaseException + { + public AssetConflictException(string message) { } + } + public sealed class GitHubRelease + { + public GitHubRelease(int id, string htmlUrl, string tagName, string targetCommitish, string name, string body, bool draft, bool prerelease, System.DateTime createdAt, System.DateTime? publishedAt) { } + public System.Collections.Generic.IReadOnlyList Assets { get; } + public string Body { get; } + public System.DateTime CreatedAt { get; } + public bool Draft { get; } + public string HtmlUrl { get; } + public int Id { get; } + public string Name { get; } + public bool Prerelease { get; } + public System.DateTime? PublishedAt { get; } + public string TagName { get; } + public string TargetCommitish { get; } + } + [Cake.Core.Annotations.CakeAliasCategory("GitHubRelease")] + public static class GitHubReleaseAliases + { + [Cake.Core.Annotations.CakeMethodAlias] + public static System.Threading.Tasks.Task GitHubReleaseCreateAsync(this Cake.Core.ICakeContext context, Cake.GitHubReleases.GitHubReleaseCreateSettings settings) { } + } + public sealed class GitHubReleaseAsset + { + public GitHubReleaseAsset(int id, string name, long size, string contentType, string browserDownloadUrl) { } + public string BrowserDownloadUrl { get; } + public string ContentType { get; } + public int Id { get; } + public string Name { get; } + public long Size { get; } + } + public sealed class GitHubReleaseCreateSettings : Cake.GitHubReleases.GitHubSettings + { + public GitHubReleaseCreateSettings(string repositoryOwner, string repositoryName, string tagName) { } + public System.Collections.Generic.IList Assets { get; set; } + public string? Body { get; set; } + public bool Draft { get; set; } + public string? Name { get; set; } + public bool Overwrite { get; set; } + public bool Prerelease { get; set; } + public string TagName { get; } + public string? TargetCommitish { get; set; } + } + public abstract class GitHubReleaseException : System.Exception + { + protected GitHubReleaseException() { } + protected GitHubReleaseException(string message) { } + protected GitHubReleaseException(string message, System.Exception innerException) { } + } + public abstract class GitHubSettings + { + protected GitHubSettings(string repositoryOwner, string repositoryName) { } + public string? AccessToken { get; set; } + public string HostName { get; set; } + public string RepositoryName { get; set; } + public string RepositoryOwner { get; set; } + } + public class ReleaseExistsException : Cake.GitHubReleases.GitHubReleaseException + { + public ReleaseExistsException(string message) { } + } +} \ No newline at end of file diff --git a/src/Cake.GitHubReleases.Test/PublicApiApproval.cs b/src/Cake.GitHubReleases.Test/PublicApiApproval.cs new file mode 100644 index 0000000..c4cd789 --- /dev/null +++ b/src/Cake.GitHubReleases.Test/PublicApiApproval.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using PublicApiGenerator; +using VerifyXunit; +using Xunit; + +namespace Cake.GitHubReleases.Test +{ + [Trait("Category", "SkipWhenLiveUnitTesting")] + [UsesVerify] + public class PublicApiApproval + { + [Fact] + public Task Assembly_does_not_have_unapproved_API_changes() + { + // ARRANGE + var assembly = typeof(GitHubReleaseAliases).Assembly; + + // ACT + var publicApi = ApiGenerator.GeneratePublicApi(assembly, options: null); + + // ASSERT + return Verifier.Verify(publicApi); + } + } + +} diff --git a/src/Cake.GitHubReleases/Cake.GitHubReleases.csproj b/src/Cake.GitHubReleases/Cake.GitHubReleases.csproj index fd587b4..f84fa8a 100644 --- a/src/Cake.GitHubReleases/Cake.GitHubReleases.csproj +++ b/src/Cake.GitHubReleases/Cake.GitHubReleases.csproj @@ -1,7 +1,8 @@ - + netstandard2.0 + false diff --git a/src/Cake.GitHubReleases/Nullable.cs b/src/Cake.GitHubReleases/Nullable.cs index 0125f5e..6a806e0 100644 --- a/src/Cake.GitHubReleases/Nullable.cs +++ b/src/Cake.GitHubReleases/Nullable.cs @@ -12,7 +12,7 @@ internal sealed class AllowNullAttribute : Attribute [ExcludeFromCodeCoverage] [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - public sealed class NotNullWhenAttribute : Attribute + internal sealed class NotNullWhenAttribute : Attribute { public bool ReturnValue { get; }