From c9f7f45e92b80e833dd3e80aebdf866d67067142 Mon Sep 17 00:00:00 2001 From: Oskar Dudycz Date: Fri, 17 May 2024 14:10:29 +0200 Subject: [PATCH] Added example NuGet Package public API snapshot testing with PublicApiGenerator See: https://github.com/PublicApiGenerator/PublicApiGenerator --- .../EventsVersioning.Tests.csproj | 1 + .../SnapshotTesting/PackageSnapshotTests.cs | 15 ++++++ ...bly_has_no_public_api_changes.verified.txt | 46 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.cs create mode 100644 Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.my_assembly_has_no_public_api_changes.verified.txt diff --git a/Sample/EventsVersioning/EventsVersioning.Tests/EventsVersioning.Tests.csproj b/Sample/EventsVersioning/EventsVersioning.Tests/EventsVersioning.Tests.csproj index 7bc99881b..3c3092887 100644 --- a/Sample/EventsVersioning/EventsVersioning.Tests/EventsVersioning.Tests.csproj +++ b/Sample/EventsVersioning/EventsVersioning.Tests/EventsVersioning.Tests.csproj @@ -12,6 +12,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.cs b/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.cs new file mode 100644 index 000000000..38a451002 --- /dev/null +++ b/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.cs @@ -0,0 +1,15 @@ +using ECommerce.V1; +using PublicApiGenerator; + +namespace EventsVersioning.Tests.SnapshotTesting; + +public class PackageSnapshotTests +{ + [Fact] + public Task my_assembly_has_no_public_api_changes() + { + var publicApi = typeof(ShoppingCartOpened).Assembly.GeneratePublicApi(); + + return Verify(publicApi); + } +} diff --git a/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.my_assembly_has_no_public_api_changes.verified.txt b/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.my_assembly_has_no_public_api_changes.verified.txt new file mode 100644 index 000000000..eb08f133c --- /dev/null +++ b/Sample/EventsVersioning/EventsVersioning.Tests/SnapshotTesting/PackageSnapshotTests.my_assembly_has_no_public_api_changes.verified.txt @@ -0,0 +1,46 @@ +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName=".NET 8.0")] +namespace ECommerce.V1 +{ + public class PricedProductItem : System.IEquatable + { + public PricedProductItem(ECommerce.V1.ProductItem ProductItem, decimal UnitPrice) { } + public ECommerce.V1.ProductItem ProductItem { get; init; } + public decimal UnitPrice { get; init; } + } + public class ProductItem : System.IEquatable + { + public ProductItem(System.Guid ProductId, int Quantity) { } + public System.Guid ProductId { get; init; } + public int Quantity { get; init; } + } + public class ProductItemAddedToShoppingCart : System.IEquatable + { + public ProductItemAddedToShoppingCart(System.Guid ShoppingCartId, ECommerce.V1.PricedProductItem ProductItem) { } + public ECommerce.V1.PricedProductItem ProductItem { get; init; } + public System.Guid ShoppingCartId { get; init; } + } + public class ProductItemRemovedFromShoppingCart : System.IEquatable + { + public ProductItemRemovedFromShoppingCart(System.Guid ShoppingCartId, ECommerce.V1.PricedProductItem ProductItem) { } + public ECommerce.V1.PricedProductItem ProductItem { get; init; } + public System.Guid ShoppingCartId { get; init; } + } + public class ShoppingCartConfirmed : System.IEquatable + { + public ShoppingCartConfirmed(System.Guid ShoppingCartId, System.DateTime ConfirmedAt) { } + public System.DateTime ConfirmedAt { get; init; } + public System.Guid ShoppingCartId { get; init; } + } + public class ShoppingCartOpened : System.IEquatable + { + public ShoppingCartOpened(System.Guid ShoppingCartId, System.Guid ClientId) { } + public System.Guid ClientId { get; init; } + public System.Guid ShoppingCartId { get; init; } + } + public enum ShoppingCartStatus + { + Pending = 1, + Confirmed = 2, + Cancelled = 3, + } +} \ No newline at end of file