Skip to content

Commit

Permalink
Fix API Tests (#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Nov 22, 2023
1 parent dd1e6b3 commit 45a92af
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 1,295 deletions.
@@ -0,0 +1,33 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.AndroidSupport")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Winforms")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Wpf")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.XamForms")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
namespace ReactiveUI.Fody.Helpers
{
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class ObservableAsPropertyAttribute : System.Attribute
{
public ObservableAsPropertyAttribute() { }
}
public static class ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveAttribute : System.Attribute
{
public ReactiveAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveDependencyAttribute : System.Attribute
{
public ReactiveDependencyAttribute(string targetName) { }
public string Target { get; }
public string? TargetProperty { get; set; }
}
}
@@ -0,0 +1,33 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.AndroidSupport")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Tests")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Winforms")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.Wpf")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ReactiveUI.XamForms")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName=".NET Framework 4.7.2")]
namespace ReactiveUI.Fody.Helpers
{
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class ObservableAsPropertyAttribute : System.Attribute
{
public ObservableAsPropertyAttribute() { }
}
public static class ObservableAsPropertyExtensions
{
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
public static ReactiveUI.ObservableAsPropertyHelper<TRet> ToPropertyEx<TObj, TRet>(this System.IObservable<TRet> item, TObj source, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue, bool deferSubscription = false, System.Reactive.Concurrency.IScheduler? scheduler = null)
where TObj : ReactiveUI.ReactiveObject { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveAttribute : System.Attribute
{
public ReactiveAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class ReactiveDependencyAttribute : System.Attribute
{
public ReactiveDependencyAttribute(string targetName) { }
public string Target { get; }
public string? TargetProperty { get; set; }
}
}
13 changes: 8 additions & 5 deletions src/ReactiveUI.Fody.Tests/API/ApiApprovalTests.cs
Expand Up @@ -4,9 +4,10 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

using System.Threading.Tasks;
using ReactiveUI.Fody.Helpers;

using ReactiveUI.Tests;
using VerifyXunit;
using Xunit;

namespace ReactiveUI.Fody.Tests.API;
Expand All @@ -18,11 +19,13 @@ namespace ReactiveUI.Fody.Tests.API;
/// for version changing reasons.
/// </summary>
[ExcludeFromCodeCoverage]
public class ApiApprovalTests : ApiApprovalBase
[UsesVerify]
public class ApiApprovalTests
{
/// <summary>
/// Checks the version API.
/// </summary>
/// <returns>A task to monitor the process.</returns>
[Fact]
public void ReactiveUIFody() => CheckApproval(typeof(ReactiveAttribute).Assembly);
}
public Task ReactiveUIFody() => typeof(ReactiveAttribute).Assembly.CheckApproval(["ReactiveUI"]);
}
Expand Up @@ -8,40 +8,32 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

using PublicApiGenerator;

using VerifyTests;

using VerifyXunit;

namespace ReactiveUI.Tests;

/// <summary>
/// Tests for API approvals.
/// A helper for doing API approvals.
/// </summary>
[ExcludeFromCodeCoverage]
#pragma warning disable CA1050 // Declare types in namespaces
#pragma warning disable RCS1110 // Declare type inside namespace.
public abstract class ApiApprovalBase
#pragma warning restore RCS1110 // Declare type inside namespace.
#pragma warning restore CA1050 // Declare types in namespaces
[UsesVerify]
public static class ApiExtensions
{
/// <summary>
/// Checks the assembly to detect the public API. Generates a received/approved version of the API.
/// Checks to make sure the API is approved.
/// </summary>
/// <param name="assembly">The assembly to check.</param>
/// <param name="filePath">Auto populated file path.</param>
/// <returns>A task to monitor the progress.</returns>
protected static Task CheckApproval(Assembly assembly, [CallerFilePath]string? filePath = null)
/// <param name="assembly">The assembly that is being checked.</param>
/// <param name="namespaces">The namespaces.</param>
/// <param name="filePath">The caller file path.</param>
/// <returns>
/// A Task.
/// </returns>
public static async Task CheckApproval(this Assembly assembly, string[] namespaces, [CallerFilePath] string filePath = "")
{
if (filePath is null)
{
return Task.CompletedTask;
}

var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = ["ReactiveUI"] };
var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = namespaces };
var apiText = assembly.GeneratePublicApi(generatorOptions);
var verifySettings = new VerifySettings();
return Verifier.Verify(apiText, verifySettings, filePath)
var result = await Verifier.Verify(apiText, null, filePath)
.UniqueForRuntimeAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
Expand Down

0 comments on commit 45a92af

Please sign in to comment.