ApiApprovalTests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using ApprovalTests;
  5. using ApprovalTests.Reporters;
  6. using PublicApiGenerator;
  7. using System;
  8. using System.Linq;
  9. using System.Reflection;
  10. using Xunit;
  11. namespace ReactiveTests.Tests.Api
  12. {
  13. [UseReporter(typeof(DiffReporter))]
  14. [IgnoreLineEndings(true)]
  15. public class ApiApprovalTests
  16. {
  17. [Fact]
  18. public void Core()
  19. {
  20. var publicApi = GeneratePublicApi(typeof(System.Reactive.Unit).Assembly);
  21. Approvals.Verify(publicApi);
  22. }
  23. [Fact]
  24. public void Aliases()
  25. {
  26. var publicApi = GeneratePublicApi(typeof(System.Reactive.Observable.Aliases.QueryLanguage).Assembly);
  27. Approvals.Verify(publicApi);
  28. }
  29. [Fact]
  30. public void Testing()
  31. {
  32. var publicApi = GeneratePublicApi(typeof(Microsoft.Reactive.Testing.TestScheduler).Assembly);
  33. Approvals.Verify(publicApi);
  34. }
  35. string GeneratePublicApi(Assembly assembly)
  36. {
  37. var namespacePrefixWhitelist = new[] { "System", "Microsoft" };
  38. return Filter(ApiGenerator.GeneratePublicApi(assembly, whitelistedNamespacePrefixes: namespacePrefixWhitelist));
  39. }
  40. static string Filter(string text)
  41. {
  42. return string.Join(Environment.NewLine, text.Split(new[]
  43. {
  44. Environment.NewLine
  45. }, StringSplitOptions.RemoveEmptyEntries)
  46. .Where(l => !l.StartsWith("[assembly: AssemblyVersion("))
  47. .Where(l => !l.StartsWith("[assembly: AssemblyFileVersion("))
  48. .Where(l => !l.StartsWith("[assembly: AssemblyInformationalVersion("))
  49. .Where(l => !l.StartsWith("[assembly: System.Reflection.AssemblyMetadataAttribute(\"CommitHash\""))
  50. .Where(l => !string.IsNullOrWhiteSpace(l))
  51. );
  52. }
  53. }
  54. }