From efacbaee792974f841c7669619088df44835faf7 Mon Sep 17 00:00:00 2001 From: Davyd McColl Date: Wed, 23 Oct 2024 08:58:04 +0200 Subject: [PATCH] :white_check_mark: enforce correct namespacing for imported PB code via tests --- .../TestPeanutButterProperlyImported.cs | 25 ++++++++++++++++++ .../GlobalUsings.cs | 2 ++ .../TestActionResultMatchers.cs | 1 - .../TestControllerMatchers.cs | 1 - .../TestHttpResponseMessageMatchers.cs | 1 - .../TestPeanutButterProperlyImported.cs | 26 +++++++++++++++++++ .../TestPeanutButterProperlyImported.cs | 26 +++++++++++++++++++ src/PeanutButter | 2 +- 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/NExpect.Matchers.AspNetCore.Tests/TestPeanutButterProperlyImported.cs create mode 100644 src/NExpect.Matchers.AspNetMvc.Tests/GlobalUsings.cs create mode 100644 src/NExpect.Matchers.AspNetMvc.Tests/TestPeanutButterProperlyImported.cs create mode 100644 src/NExpect.Tests/TestPeanutButterProperlyImported.cs diff --git a/src/NExpect.Matchers.AspNetCore.Tests/TestPeanutButterProperlyImported.cs b/src/NExpect.Matchers.AspNetCore.Tests/TestPeanutButterProperlyImported.cs new file mode 100644 index 00000000..f7d0541b --- /dev/null +++ b/src/NExpect.Matchers.AspNetCore.Tests/TestPeanutButterProperlyImported.cs @@ -0,0 +1,25 @@ +using System.Linq; +using PeanutButter.Utils; + +namespace NExpect.Matchers.AspNet.Tests; + +[TestFixture] +public class TestPeanutButterProperlyImported +{ + [TestCase("PeanutButter.")] + public void ShouldNotExportNamespaceStartingWith_( + string prefix + ) + { + // Arrange + // Act + var invalid = typeof(Expectations) + .GetAssembly() + .GetTypes() + .Where(t => t.Namespace?.StartsWith(prefix) ?? false) + .ToArray(); + // Assert + Expect(invalid) + .To.Be.Empty(); + } +} \ No newline at end of file diff --git a/src/NExpect.Matchers.AspNetMvc.Tests/GlobalUsings.cs b/src/NExpect.Matchers.AspNetMvc.Tests/GlobalUsings.cs new file mode 100644 index 00000000..2b32db80 --- /dev/null +++ b/src/NExpect.Matchers.AspNetMvc.Tests/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using NExpect; +global using static NExpect.Expectations; \ No newline at end of file diff --git a/src/NExpect.Matchers.AspNetMvc.Tests/TestActionResultMatchers.cs b/src/NExpect.Matchers.AspNetMvc.Tests/TestActionResultMatchers.cs index 783dbbfd..f59d28df 100644 --- a/src/NExpect.Matchers.AspNetMvc.Tests/TestActionResultMatchers.cs +++ b/src/NExpect.Matchers.AspNetMvc.Tests/TestActionResultMatchers.cs @@ -3,7 +3,6 @@ using static PeanutButter.RandomGenerators.RandomValueGen; using NExpect.Exceptions; using PeanutButter.Utils; -using static NExpect.Expectations; namespace NExpect.Matchers.AspNetMvc.Tests; diff --git a/src/NExpect.Matchers.AspNetMvc.Tests/TestControllerMatchers.cs b/src/NExpect.Matchers.AspNetMvc.Tests/TestControllerMatchers.cs index 129dc046..0d36b658 100644 --- a/src/NExpect.Matchers.AspNetMvc.Tests/TestControllerMatchers.cs +++ b/src/NExpect.Matchers.AspNetMvc.Tests/TestControllerMatchers.cs @@ -2,7 +2,6 @@ using System.Web.Mvc; using NExpect.Exceptions; using NUnit.Framework; -using static NExpect.Expectations; namespace NExpect.Matchers.AspNetMvc.Tests; diff --git a/src/NExpect.Matchers.AspNetMvc.Tests/TestHttpResponseMessageMatchers.cs b/src/NExpect.Matchers.AspNetMvc.Tests/TestHttpResponseMessageMatchers.cs index 1b3ca38c..c304a59b 100644 --- a/src/NExpect.Matchers.AspNetMvc.Tests/TestHttpResponseMessageMatchers.cs +++ b/src/NExpect.Matchers.AspNetMvc.Tests/TestHttpResponseMessageMatchers.cs @@ -2,7 +2,6 @@ using NExpect.Exceptions; using NUnit.Framework; using static PeanutButter.RandomGenerators.RandomValueGen; -using static NExpect.Expectations; namespace NExpect.Matchers.AspNetMvc.Tests; diff --git a/src/NExpect.Matchers.AspNetMvc.Tests/TestPeanutButterProperlyImported.cs b/src/NExpect.Matchers.AspNetMvc.Tests/TestPeanutButterProperlyImported.cs new file mode 100644 index 00000000..ae072eb0 --- /dev/null +++ b/src/NExpect.Matchers.AspNetMvc.Tests/TestPeanutButterProperlyImported.cs @@ -0,0 +1,26 @@ +using System.Linq; +using NUnit.Framework; +using PeanutButter.Utils; + +namespace NExpect.Matchers.AspNetMvc.Tests; + +[TestFixture] +public class TestPeanutButterProperlyImported +{ + [TestCase("PeanutButter.")] + public void ShouldNotExportNamespaceStartingWith_( + string prefix + ) + { + // Arrange + // Act + var invalid = typeof(Expectations) + .GetAssembly() + .GetTypes() + .Where(t => t.Namespace?.StartsWith(prefix) ?? false) + .ToArray(); + // Assert + Expect(invalid) + .To.Be.Empty(); + } +} \ No newline at end of file diff --git a/src/NExpect.Tests/TestPeanutButterProperlyImported.cs b/src/NExpect.Tests/TestPeanutButterProperlyImported.cs new file mode 100644 index 00000000..881aa614 --- /dev/null +++ b/src/NExpect.Tests/TestPeanutButterProperlyImported.cs @@ -0,0 +1,26 @@ +using System.Linq; +using NUnit.Framework; +using PeanutButter.Utils; + +namespace NExpect.Tests; + +[TestFixture] +public class TestPeanutButterProperlyImported +{ + [TestCase("PeanutButter.")] + public void ShouldNotExportNamespaceStartingWith_( + string prefix + ) + { + // Arrange + // Act + var invalid = typeof(Expectations) + .GetAssembly() + .GetTypes() + .Where(t => t.Namespace?.StartsWith(prefix) ?? false) + .ToArray(); + // Assert + Expect(invalid) + .To.Be.Empty(); + } +} \ No newline at end of file diff --git a/src/PeanutButter b/src/PeanutButter index 2b32c78c..ebc7a4c8 160000 --- a/src/PeanutButter +++ b/src/PeanutButter @@ -1 +1 @@ -Subproject commit 2b32c78cc8e781743181c1df92cab937fdbf75c8 +Subproject commit ebc7a4c8de1d1d51c331565a2f02b0d3a01683c3