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

Tidying up DefineConstants #2538

Merged
merged 2 commits into from
Aug 12, 2022
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
7 changes: 0 additions & 7 deletions Octokit.Tests.Integration/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public static class Helper

static readonly Lazy<Credentials> _githubAppCredentials = new Lazy<Credentials>(() =>
{
// GitHubJwt nuget package only available for netstandard2.0+
#if GITHUBJWT_HELPER_AVAILABLE
var generator = new GitHubJwt.GitHubJwtFactory(
new GitHubJwt.FilePrivateKeySource(GitHubAppPemFile),
new GitHubJwt.GitHubJwtFactoryOptions
Expand All @@ -87,11 +85,6 @@ public static class Helper

var jwtToken = generator.CreateEncodedJwtToken();
return new Credentials(jwtToken, AuthenticationType.Bearer);
#else
// return null, which will cause the [GitHubAppTest]'s to not be discovered
return null;
#endif

});

static readonly Lazy<Uri> _customUrl = new Lazy<Uri>(() =>
Expand Down
21 changes: 7 additions & 14 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,28 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);GITHUBJWT_HELPER_AVAILABLE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Octokit.Tests\Helpers\AssertEx.cs" />
<EmbeddedResource Include="fixtures\hello-world.txt;fixtures\hello-world.zip" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<None Include="app.config" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Octokit\Octokit.csproj" />
<ProjectReference Include="..\Octokit.Reactive\Octokit.Reactive.csproj" />
<ProjectReference Include="..\Octokit.Tests\Octokit.Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="GitHubJwt" Version="0.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="GitHubJwt" Version="0.0.5" />
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
Expand Down
8 changes: 1 addition & 7 deletions Octokit.Tests/Fixtures/EmbeddedResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ public EmbeddedResource(Assembly assembly, string resourceName)

public string GetResourceAsString(Encoding encoding = null)
{
encoding = encoding ??
#if HAS_DEFAULT_ENCODING
Encoding.Default;
#else
// http://stackoverflow.com/questions/35929391/how-can-i-determine-the-default-encoding-in-a-portable-class-library
Encoding.GetEncoding(0);
#endif
encoding = encoding ?? Encoding.GetEncoding(0);

using (var sr = new StreamReader(GetResourceStream(), encoding))
{
Expand Down
33 changes: 1 addition & 32 deletions Octokit.Tests/Fixtures/Fixtures.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#if HAS_TYPEINFO
using System.Reflection;
#endif
using System.Reflection;

namespace Octokit.Tests
{
public static class Fixtures
{
#if HAS_TYPEINFO
public static EmbeddedResource AuthorizationsJson =
new EmbeddedResource(typeof(Fixtures).GetTypeInfo().Assembly, "Octokit.Tests.Fixtures.authorizations.json");

Expand All @@ -33,33 +30,5 @@ public static class Fixtures

public static EmbeddedResource ReleaseAssetJson =
new EmbeddedResource(typeof(Fixtures).GetTypeInfo().Assembly, "Octokit.Tests.Fixtures.release_asset.json");
#else
public static EmbeddedResource AuthorizationsJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.authorizations.json");

public static EmbeddedResource AuthorizationJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.authorization.json");

public static EmbeddedResource UserJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.user.json");

public static EmbeddedResource UserFullJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.user_full.json");

public static EmbeddedResource RepositoryJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.repository.json");

public static EmbeddedResource RepositoriesJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.repositories.json");

public static EmbeddedResource ReleasesJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.releases.json");

public static EmbeddedResource ReleaseJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.release.json");

public static EmbeddedResource ReleaseAssetJson =
new EmbeddedResource(typeof(Fixtures).Assembly, "Octokit.Tests.Fixtures.release_asset.json");
#endif
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Http/RateLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void CanPopulateObjectFromSerializedData()
};

var rateLimit = new RateLimit(headers);

var deserialized = BinaryFormatterExtensions.SerializeAndDeserializeObject(rateLimit);

Assert.Equal(100, deserialized.Limit);
Expand Down
4 changes: 0 additions & 4 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<PackageReference Include="NSubstitute" Version="4.4.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);NO_SERIALIZABLE;HAS_TYPEINFO</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
Expand Down
8 changes: 1 addition & 7 deletions Octokit.Tests/SelfTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if HAS_TYPEINFO
using System.Reflection;
#endif
using System.Reflection;
using Xunit;

/// <summary>
Expand All @@ -11,11 +9,7 @@ public class SelfTests
[Fact]
public void NoTestsUseAsyncVoid()
{
#if HAS_TYPEINFO
var errors = typeof(SelfTests).GetTypeInfo().Assembly.GetAsyncVoidMethodsList();
#else
var errors = typeof(SelfTests).Assembly.GetAsyncVoidMethodsList();
#endif
Assert.Equal("", errors);
}
}
6 changes: 0 additions & 6 deletions Octokit/Exceptions/AbuseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
using System.Security;
#endif

namespace Octokit
{
/// <summary>
/// Represents a subset of the HTTP 403 - Forbidden response returned from the API when the forbidden response is related to an abuse detection mechanism.
/// Contains the amount of seconds after which it's safe to retry the request.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class AbuseException : ForbiddenException
Expand Down Expand Up @@ -63,7 +59,6 @@ public override string Message
get { return ApiErrorMessageSafe ?? "Request Forbidden - Abuse Detection"; }
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of AbuseException
/// </summary>
Expand All @@ -86,6 +81,5 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
base.GetObjectData(info, context);
info.AddValue("RetryAfterSeconds", RetryAfterSeconds);
}
#endif
}
}
6 changes: 0 additions & 6 deletions Octokit/Exceptions/ApiException.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif
using System.Security;
using Octokit.Internal;

Expand All @@ -12,9 +10,7 @@ namespace Octokit
/// <summary>
/// Represents errors that occur from the GitHub API.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class ApiException : Exception
Expand Down Expand Up @@ -143,7 +139,6 @@ static ApiError GetApiErrorFromExceptionMessage(string responseContent)
return new ApiError(responseContent);
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of ApiException.
/// </summary>
Expand All @@ -170,7 +165,6 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
info.AddValue("HttpStatusCode", StatusCode);
info.AddValue("ApiError", ApiError);
}
#endif

/// <summary>
/// Get the inner error message from the API response
Expand Down
6 changes: 0 additions & 6 deletions Octokit/Exceptions/ApiValidationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif

namespace Octokit
{
/// <summary>
/// Represents a HTTP 422 - Unprocessable Entity response returned from the API.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class ApiValidationException : ApiException
Expand Down Expand Up @@ -60,7 +56,6 @@ public override string Message
get { return ApiErrorMessageSafe ?? "Validation Failed"; }
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of ApiValidationException
/// </summary>
Expand All @@ -76,6 +71,5 @@ protected ApiValidationException(SerializationInfo info, StreamingContext contex
: base(info, context)
{
}
#endif
}
}
6 changes: 0 additions & 6 deletions Octokit/Exceptions/AuthorizationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif

namespace Octokit
{
/// <summary>
/// Represents a HTTP 401 - Unauthorized response returned from the API.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class AuthorizationException : ApiException
Expand Down Expand Up @@ -51,7 +47,6 @@ public AuthorizationException(HttpStatusCode httpStatusCode, Exception innerExce
{
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of AuthorizationException.
/// </summary>
Expand All @@ -67,6 +62,5 @@ protected AuthorizationException(SerializationInfo info, StreamingContext contex
: base(info, context)
{
}
#endif
}
}
6 changes: 0 additions & 6 deletions Octokit/Exceptions/ForbiddenException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif

namespace Octokit
{
/// <summary>
/// Represents a HTTP 403 - Forbidden response returned from the API.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class ForbiddenException : ApiException
Expand Down Expand Up @@ -43,7 +39,6 @@ public override string Message
get { return ApiErrorMessageSafe ?? "Request Forbidden"; }
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of ForbiddenException
/// </summary>
Expand All @@ -59,6 +54,5 @@ protected ForbiddenException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
}
6 changes: 0 additions & 6 deletions Octokit/Exceptions/InvalidGitIgnoreTemplateException.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;
#if !NO_SERIALIZABLE
using System.Runtime.Serialization;
#endif

namespace Octokit
{
/// <summary>
/// Represents a HTTP 403 - Forbidden response returned from the API.
/// </summary>
#if !NO_SERIALIZABLE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class InvalidGitIgnoreTemplateException : ApiValidationException
Expand All @@ -38,7 +34,6 @@ public override string Message
}
}

#if !NO_SERIALIZABLE
/// <summary>
/// Constructs an instance of InvalidGitignoreTemplateException
/// </summary>
Expand All @@ -53,6 +48,5 @@ public override string Message
protected InvalidGitIgnoreTemplateException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
#endif
}
}
Loading