diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index cf45649..2127d72 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -23,7 +23,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore - name: Build @@ -43,7 +43,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 10.0.x - name: dotnet pack run: dotnet pack --configuration Release --include-symbols --include-source /p:PackageVersion='${{ env.MAJOR_VERSION }}.${{ env.MINOR_VERSION }}.${{ env.PATCH_VERSION }}' -o nupkg FluentAssertions.BUnit - name: Push to NuGet Feed diff --git a/FluentAssertions.BUnit.Tests/AssertionExtensions/ElementShould.razor b/FluentAssertions.BUnit.Tests/AssertionExtensions/ElementShould.razor index 1d4394b..8fdc0bd 100644 --- a/FluentAssertions.BUnit.Tests/AssertionExtensions/ElementShould.razor +++ b/FluentAssertions.BUnit.Tests/AssertionExtensions/ElementShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -10,6 +10,6 @@ var elementAssertions = element.Should(); - elementAssertions.Should().BeOfType(); + elementAssertions.GetType().Should().Be(typeof(ElementAssertions)); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/AssertionExtensions/RenderedFragmentShould.razor b/FluentAssertions.BUnit.Tests/AssertionExtensions/RenderedFragmentShould.razor index 6176e31..ec0d0c5 100644 --- a/FluentAssertions.BUnit.Tests/AssertionExtensions/RenderedFragmentShould.razor +++ b/FluentAssertions.BUnit.Tests/AssertionExtensions/RenderedFragmentShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -9,6 +9,7 @@ var renderedFragmentAssertion = renderedFragment.Should(); - renderedFragmentAssertion.Should().BeOfType(); + renderedFragmentAssertion.GetType().IsGenericType.Should().BeTrue(); + renderedFragmentAssertion.GetType().GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/BUnitExtensions/AsElementShould.razor b/FluentAssertions.BUnit.Tests/BUnitExtensions/AsElementShould.razor index 4b75106..1fb3a4f 100644 --- a/FluentAssertions.BUnit.Tests/BUnitExtensions/AsElementShould.razor +++ b/FluentAssertions.BUnit.Tests/BUnitExtensions/AsElementShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { diff --git a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindAllByDataTestClassShould.razor b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindAllByDataTestClassShould.razor index 625cb41..e092936 100644 --- a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindAllByDataTestClassShould.razor +++ b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindAllByDataTestClassShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { diff --git a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestClassShould.razor b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestClassShould.razor index f578f6a..e486bba 100644 --- a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestClassShould.razor +++ b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestClassShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { diff --git a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestIdShould.razor b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestIdShould.razor index 2850347..b76a06d 100644 --- a/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestIdShould.razor +++ b/FluentAssertions.BUnit.Tests/BUnitExtensions/FindByDataTestIdShould.razor @@ -1,4 +1,4 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAltTextShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAltTextShould.razor index 8bd1135..e02af07 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAltTextShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAltTextShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { @@ -10,7 +10,7 @@ .AsElement() .Should().HaveAltText("Logo"); } - + [Fact] public void ReturnAndConstraint() { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveAltText("Logo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,9 +32,9 @@ .Should().HaveAltText("Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"alt\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"alt\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -40,9 +43,9 @@ .Should().HaveAltText("Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"alt\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"alt\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -51,9 +54,9 @@ .Should().HaveAltText("Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\", but found \"Log\"."); + .And.Message.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\", but found \"Log\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -62,6 +65,6 @@ .Should().HaveAltText("Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); + .And.Message.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAriaLabelShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAriaLabelShould.razor index 612b63d..d0c1353 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAriaLabelShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAriaLabelShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { @@ -10,7 +10,7 @@ .AsElement() .Should().HaveAriaLabel("Home Page"); } - + [Fact] public void ReturnAndConstraint() { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveAriaLabel("Home Page"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,9 +32,9 @@ .Should().HaveAriaLabel("Home Page"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"aria-label\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"aria-label\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -40,9 +43,9 @@ .Should().HaveAriaLabel("Home Page", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"aria-label\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"aria-label\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -51,9 +54,9 @@ .Should().HaveAriaLabel("Home Page"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"aria-label\" attribute to have value \"Home Page\", but found \"Home\"."); + .And.Message.Should().Be("Expected IElement \"aria-label\" attribute to have value \"Home Page\", but found \"Home\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -62,6 +65,6 @@ .Should().HaveAriaLabel("Home Page", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"aria-label\" attribute to have value \"Home Page\" because this is very important to Steve, but found \"Home\"."); + .And.Message.Should().Be("Expected IElement \"aria-label\" attribute to have value \"Home Page\" because this is very important to Steve, but found \"Home\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAttributeShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAttributeShould.razor index 2896147..b74c43a 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAttributeShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveAttributeShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { @@ -10,7 +10,7 @@ .AsElement() .Should().HaveAttribute("alt", "Logo"); } - + [Fact] public void ReturnAndConstraint() { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveAttribute("alt", "Logo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,9 +32,9 @@ .Should().HaveAttribute("alt", "Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"alt\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"alt\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -40,9 +43,9 @@ .Should().HaveAttribute("alt", "Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"alt\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"alt\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -51,9 +54,9 @@ .Should().HaveAttribute("alt", "Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\", but found \"Log\"."); + .And.Message.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\", but found \"Log\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -62,6 +65,6 @@ .Should().HaveAttribute("alt", "Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); + .And.Message.Should().Be("Expected IElement \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveChildMarkupShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveChildMarkupShould.razor index b5cfe38..029b30a 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveChildMarkupShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveChildMarkupShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed_WhenMatchingByString() { @@ -10,7 +10,7 @@ .AsElement() .Should().HaveChildMarkup("

Test

"); } - + [Fact] public void Succeed_WhenMatchingByRenderFragment() { @@ -18,7 +18,7 @@ .AsElement() .Should().HaveChildMarkup(@

Test

); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByString() { @@ -26,9 +26,12 @@ .AsElement() .Should().HaveChildMarkup("

Test

"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByRenderFragment() { @@ -36,20 +39,23 @@ .AsElement() .Should().HaveChildMarkup(@

Test

); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } - + [Fact] public void ThrowException_WhenChildMarkupIsNull_AndMatchingByString() { Action aut = () => Render(@) .AsElement() - .Should().HaveChildMarkup("

Test

");; + .Should().HaveChildMarkup("

Test

"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\", but found ."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\", but found ."); } - + [Fact] public void ThrowException_WhenChildMarkupIsNull_AndMatchingByRenderFragment() { @@ -58,20 +64,20 @@ .Should().HaveChildMarkup(@

Test

); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\", but found ."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\", but found ."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupIsNull_AndMatchingByString() { Action aut = () => Render(@) .AsElement() - .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve");; + .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupIsNull_AndMatchingByRenderFragment() { @@ -80,7 +86,7 @@ .Should().HaveChildMarkup(@

Test

, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found ."); } [Fact] @@ -88,12 +94,12 @@ { Action aut = () => Render(@) .AsElement() - .Should().HaveChildMarkup("

Test

");; + .Should().HaveChildMarkup("

Test

"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\", but found \"

Test

\"."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\", but found \"

Test

\"."); } - + [Fact] public void ThrowException_WhenChildMarkupDoesNotMatch_AndMatchingByRenderFragment() { @@ -102,20 +108,20 @@ .Should().HaveChildMarkup(@

Test

); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\", but found \"

Test

\"."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\", but found \"

Test

\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByString() { Action aut = () => Render(@) .AsElement() - .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve");; + .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByRenderFragment() { @@ -124,6 +130,6 @@ .Should().HaveChildMarkup(@

Test

, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); + .And.Message.Should().Be("Expected IElement to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveClassShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveClassShould.razor index a0023f0..e5a6818 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveClassShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveClassShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -21,7 +21,10 @@ .AsElement() .Should().HaveClass("btn"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -32,7 +35,7 @@ .Should().HaveClass("btn"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {empty} to contain \"btn\"."); + .And.Message.Should().Be("Expected Subject.ClassList {empty} to contain \"btn\"."); } [Fact] @@ -43,7 +46,7 @@ .Should().HaveClass("btn", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {empty} to contain \"btn\" because this is very important to Steve."); + .And.Message.Should().Be("Expected Subject.ClassList {empty} to contain \"btn\" because this is very important to Steve."); } [Fact] @@ -54,7 +57,7 @@ .Should().HaveClass("btn"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\"."); + .And.Message.Should().Be("Expected Subject.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\"."); } [Fact] @@ -65,6 +68,6 @@ .Should().HaveClass("btn", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\" because this is very important to Steve."); + .And.Message.Should().Be("Expected Subject.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestClassShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestClassShould.razor index 7a909c8..6e3e4c7 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestClassShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestClassShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveDataTestClass("magic-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveDataTestClass("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"data-test-class\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"data-test-class\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveDataTestClass("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"data-test-class\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"data-test-class\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveDataTestClass("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"data-test-class\" attribute to have value \"magic-button\", but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IElement \"data-test-class\" attribute to have value \"magic-button\", but found \"magic-btn\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveDataTestClass("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"data-test-class\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IElement \"data-test-class\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestIdShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestIdShould.razor index 9ef2a84..fdd843d 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestIdShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveDataTestIdShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveDataTestId("magic-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveDataTestId("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"data-test-id\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"data-test-id\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveDataTestId("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"data-test-id\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"data-test-id\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveDataTestId("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"data-test-id\" attribute to have value \"magic-button\", but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IElement \"data-test-id\" attribute to have value \"magic-button\", but found \"magic-btn\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveDataTestId("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"data-test-id\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IElement \"data-test-id\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveHrefShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveHrefShould.razor index 389b694..14172f4 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveHrefShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveHrefShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"href\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"href\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"href\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"href\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\", but found \"#\"."); + .And.Message.Should().Be("Expected IElement \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\", but found \"#\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\" because this is very important to Steve, but found \"#\"."); + .And.Message.Should().Be("Expected IElement \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\" because this is very important to Steve, but found \"#\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveIdShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveIdShould.razor index 2868df5..0713bb5 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveIdShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveIdShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveId("special-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveId("special-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"id\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"id\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveId("special-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"id\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"id\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveId("special-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"id\" attribute to have value \"special-button\", but found \"special-btn\"."); + .And.Message.Should().Be("Expected IElement \"id\" attribute to have value \"special-button\", but found \"special-btn\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveId("special-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"id\" attribute to have value \"special-button\" because this is very important to Steve, but found \"special-btn\"."); + .And.Message.Should().Be("Expected IElement \"id\" attribute to have value \"special-button\" because this is very important to Steve, but found \"special-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveMarkupShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveMarkupShould.razor index 1e1b00e..d8a8d50 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveMarkupShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveMarkupShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -26,7 +26,10 @@ .AsElement() .Should().HaveMarkup(""); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -36,7 +39,10 @@ .AsElement() .Should().HaveMarkup(@); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -47,7 +53,7 @@ .Should().HaveMarkup(""); aut.Should().Throw() - .And.UserMessage.Should().Be($"Expected IElement markup \"\", but found \"{Environment.NewLine}\"."); + .And.Message.Should().Be("Expected IElement markup \"\", but found \"\"."); } [Fact] @@ -58,7 +64,7 @@ .Should().HaveMarkup(@); aut.Should().Throw() - .And.UserMessage.Should().Be($"Expected IElement markup \"\", but found \"{Environment.NewLine}\"."); + .And.Message.Should().Be("Expected IElement markup \"\", but found \"\"."); } [Fact] @@ -69,7 +75,7 @@ .Should().HaveMarkup("", "this is very important to {0}", "Steve");; aut.Should().Throw() - .And.UserMessage.Should().Be($"Expected IElement markup \"\" because this is very important to Steve, but found \"{Environment.NewLine}\"."); + .And.Message.Should().Be("Expected IElement markup \"\" because this is very important to Steve, but found \"\"."); } [Fact] @@ -80,6 +86,6 @@ .Should().HaveMarkup(@, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be($"Expected IElement markup \"\" because this is very important to Steve, but found \"{Environment.NewLine}\"."); + .And.Message.Should().Be("Expected IElement markup \"\" because this is very important to Steve, but found \"\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveRelShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveRelShould.razor index a28df54..3ade7a2 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveRelShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveRelShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -22,7 +22,10 @@ .AsElement() .Should().HaveRel(expected); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -33,7 +36,7 @@ .Should().HaveRel("nofollow"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"rel\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"rel\", but found ."); } [Fact] @@ -44,7 +47,7 @@ .Should().HaveRel("nofollow", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"rel\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"rel\" because this is very important to Steve, but found ."); } [Fact] @@ -55,7 +58,7 @@ .Should().HaveRel("noopener"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"rel\" [{\"nofollow\"}] to contain \"noopener\"."); + .And.Message.Should().Be("Expected IElement \"rel\" [{\"nofollow\"}] to contain \"noopener\"."); } [Fact] @@ -66,6 +69,6 @@ .Should().HaveRel("noopener", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"rel\" [{\"nofollow\"}] to contain \"noopener\" because this is very important to Steve."); + .And.Message.Should().Be("Expected IElement \"rel\" [{\"nofollow\"}] to contain \"noopener\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveSrcShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveSrcShould.razor index 743acfc..ec5edb8 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveSrcShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveSrcShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveSrc("/logo.png"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveSrc("/logo.png"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"src\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"src\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveSrc("/logo.png", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"src\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"src\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveSrc("/logo.png"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"src\" attribute to have value \"/logo.png\", but found \"/loog.png\"."); + .And.Message.Should().Be("Expected IElement \"src\" attribute to have value \"/logo.png\", but found \"/loog.png\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveSrc("/logo.png", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"src\" attribute to have value \"/logo.png\" because this is very important to Steve, but found \"/loog.png\"."); + .And.Message.Should().Be("Expected IElement \"src\" attribute to have value \"/logo.png\" because this is very important to Steve, but found \"/loog.png\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTagShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTagShould.razor index c14c409..e23ad99 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTagShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTagShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { @@ -10,7 +10,7 @@ .AsElement() .Should().HaveTag("button"); } - + [Fact] public void ReturnAndConstraint() { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveTag("button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,9 +32,9 @@ .Should().HaveTag("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"tag\" to be \"button\", but found \"div\"."); + .And.Message.Should().Be("Expected IElement \"tag\" to be \"button\", but found \"div\"."); } - + [Fact] public void ThrowException_WhenTagNotMatchExpected_AndShouldIncludeBecauseMessage() { @@ -40,6 +43,6 @@ .Should().HaveTag("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"tag\" to be \"button\" because this is very important to Steve, but found \"div\"."); + .And.Message.Should().Be("Expected IElement \"tag\" to be \"button\" because this is very important to Steve, but found \"div\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTargetShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTargetShould.razor index 2b9158b..20a49e8 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTargetShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTargetShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveTarget("_blank"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveTarget("_blank"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"target\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"target\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveTarget("_blank", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"target\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"target\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveTarget("_blank"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"target\" attribute to have value \"_blank\", but found \"_self\"."); + .And.Message.Should().Be("Expected IElement \"target\" attribute to have value \"_blank\", but found \"_self\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveTarget("_blank", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"target\" attribute to have value \"_blank\" because this is very important to Steve, but found \"_self\"."); + .And.Message.Should().Be("Expected IElement \"target\" attribute to have value \"_blank\" because this is very important to Steve, but found \"_self\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTitleShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTitleShould.razor index 382f2ec..7eefa6b 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTitleShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTitleShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveTitle("GitHub Repo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveTitle("GitHub Repo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"title\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"title\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveTitle("GitHub Repo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"title\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"title\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveTitle("GitHub Repo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"title\" attribute to have value \"GitHub Repo\", but found \"GH Repo\"."); + .And.Message.Should().Be("Expected IElement \"title\" attribute to have value \"GitHub Repo\", but found \"GH Repo\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveTitle("GitHub Repo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"title\" attribute to have value \"GitHub Repo\" because this is very important to Steve, but found \"GH Repo\"."); + .And.Message.Should().Be("Expected IElement \"title\" attribute to have value \"GitHub Repo\" because this is very important to Steve, but found \"GH Repo\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTypeShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTypeShould.razor index 8e4b2b6..e8d2a36 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/HaveTypeShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -18,7 +18,10 @@ .AsElement() .Should().HaveType("button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -29,7 +32,7 @@ .Should().HaveType("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"type\", but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"type\", but found ."); } [Fact] @@ -40,7 +43,7 @@ .Should().HaveType("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement to have attribute \"type\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IElement to have attribute \"type\" because this is very important to Steve, but found ."); } [Fact] @@ -51,7 +54,7 @@ .Should().HaveType("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"type\" attribute to have value \"button\", but found \"reset\"."); + .And.Message.Should().Be("Expected IElement \"type\" attribute to have value \"button\", but found \"reset\"."); } [Fact] @@ -62,6 +65,6 @@ .Should().HaveType("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IElement \"type\" attribute to have value \"button\" because this is very important to Steve, but found \"reset\"."); + .And.Message.Should().Be("Expected IElement \"type\" attribute to have value \"button\" because this is very important to Steve, but found \"reset\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeAssignableToShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeAssignableToShould.razor index 98bf8e6..d27424b 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeAssignableToShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeAssignableToShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenAssignable() { @@ -10,7 +10,7 @@ .AsElement() .Should().BeAssignableTo(); } - + [Fact] public void ThrowExceptionWhenNotAssignable() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeNullShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeNullShould.razor index 346dde1..e11a3b2 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeNullShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeNullShould.razor @@ -1,16 +1,16 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenNull() { IElement e = null; - + e.Should().BeNull(); } - + [Fact] public void ThrowExceptionWhenNotNull() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeOfTypeShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeOfTypeShould.razor index b9223b0..01807ef 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeOfTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeOfTypeShould.razor @@ -1,24 +1,24 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenOfType() { var element = Render(@Logo) .AsElement(); - + element .Should().BeOfType(element.GetType()); } - + [Fact] public void ThrowExceptionWhenNotOfType() { Action aut = () => Render(@Logo) .AsElement() - .Should().BeOfType(); + .Should().BeOfType>(); aut.Should().Throw(); } diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeSameAsShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeSameAsShould.razor index 3a7ff7f..3909ad0 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeSameAsShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/BeSameAsShould.razor @@ -1,14 +1,14 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenComparingToSameReference() { var element = Render(@Logo) .AsElement(); - + element .Should().BeSameAs(element); } diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/MatchShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/MatchShould.razor index e5ab134..ab37734 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/MatchShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/MatchShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenMatches() { @@ -10,7 +10,7 @@ .AsElement() .Should().Match(e => e.Attributes["alt"].Value == "Logo"); } - + [Fact] public void ThrowExceptionWhenDoesNotMatch() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeAssignableToShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeAssignableToShould.razor index 8192e04..a79790a 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeAssignableToShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeAssignableToShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenAssignable() { @@ -10,7 +10,7 @@ .AsElement() .Should().NotBeAssignableTo(); } - + [Fact] public void ThrowExceptionWhenNotAssignable() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeNullShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeNullShould.razor index fcf3d2c..15a9cdd 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeNullShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeNullShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenNotNull() { @@ -10,7 +10,7 @@ .AsElement() .Should().NotBeNull(); } - + [Fact] public void ThrowExceptionWhenNull() { @@ -19,7 +19,7 @@ IElement element = null; element.Should().NotBeNull(); }; - + aut.Should().Throw(); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeOfTypeShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeOfTypeShould.razor index 6fab9e3..4e12787 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeOfTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeOfTypeShould.razor @@ -1,16 +1,16 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenOfType() { Render(@Logo) .AsElement() - .Should().NotBeOfType(); + .Should().NotBeOfType>(); } - + [Fact] public void ThrowExceptionWhenNotOfType() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeSameAsShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeSameAsShould.razor index 0590453..871014d 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeSameAsShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/NotBeSameAsShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenComparingToAnotherReference() { diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/Readme.md b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/Readme.md index fe4471f..0b5cfb1 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/Readme.md +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/Readme.md @@ -1,3 +1,3 @@ -> 💡 Note: The functionality that we test here we get from `RenderedFragmentAssertions` inheriting from `ReferenceTypeAssertions`. +> 💡 Note: The functionality that we test here we get from `RenderedFragmentAssertions` inheriting from `ReferenceTypeAssertions`. > > I decided to add some basic tests to explore their API and check it behaves as I expect. \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/SubjectShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/SubjectShould.razor index 1a0bc2e..150588e 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/SubjectShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/Inherited/SubjectShould.razor @@ -1,12 +1,12 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void BeSameAsRenderedFragment() { var element = Render(@Logo).AsElement(); - + var subject = element.Should().Subject; subject.Should().BeAssignableTo().And.BeSameAs(element); diff --git a/FluentAssertions.BUnit.Tests/ElementAssertions/NotHaveClassShould.razor b/FluentAssertions.BUnit.Tests/ElementAssertions/NotHaveClassShould.razor index 65cf72b..4d26089 100644 --- a/FluentAssertions.BUnit.Tests/ElementAssertions/NotHaveClassShould.razor +++ b/FluentAssertions.BUnit.Tests/ElementAssertions/NotHaveClassShould.razor @@ -1,5 +1,5 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { @@ -26,7 +26,10 @@ .AsElement() .Should().NotHaveClass("btn-large"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + constraintType.GetGenericArguments()[0].Should().BeSameAs(typeof(ElementAssertions)); } [Fact] @@ -37,7 +40,7 @@ .Should().NotHaveClass("btn-large"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\"."); + .And.Message.Should().Be("Expected Subject.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\"."); } [Fact] @@ -48,6 +51,6 @@ .Should().NotHaveClass("btn-large", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected Subject.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\" because this is very important to Steve."); + .And.Message.Should().Be("Expected Subject.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/FluentAssertions.BUnit.Tests.csproj b/FluentAssertions.BUnit.Tests/FluentAssertions.BUnit.Tests.csproj index 2b87646..5dea852 100644 --- a/FluentAssertions.BUnit.Tests/FluentAssertions.BUnit.Tests.csproj +++ b/FluentAssertions.BUnit.Tests/FluentAssertions.BUnit.Tests.csproj @@ -1,21 +1,20 @@ - + - net5.0 + net10.0 false - - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAltTextShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAltTextShould.razor similarity index 58% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAltTextShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAltTextShould.razor index 9b48eff..8b90e5b 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAltTextShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAltTextShould.razor @@ -1,22 +1,27 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Logo) .Should().HaveAltText("Logo"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Logo) .Should().HaveAltText("Logo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -26,9 +31,9 @@ .Should().HaveAltText("Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"alt\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"alt\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveAltText("Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"alt\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"alt\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveAltText("Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"alt\" attribute to have value \"Logo\", but found \"Log\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"alt\" attribute to have value \"Logo\", but found \"Log\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveAltText("Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAriaLabelShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAriaLabelShould.razor similarity index 58% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAriaLabelShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAriaLabelShould.razor index 26a966d..6d82f85 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAriaLabelShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAriaLabelShould.razor @@ -1,22 +1,27 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Link) .Should().HaveAriaLabel("Home Page"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Link) .Should().HaveAriaLabel("Home Page"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -26,9 +31,9 @@ .Should().HaveAriaLabel("Home Page"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"aria-label\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"aria-label\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveAriaLabel("Home Page", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"aria-label\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"aria-label\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveAriaLabel("Home Page"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"aria-label\" attribute to have value \"Home Page\", but found \"Home\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"aria-label\" attribute to have value \"Home Page\", but found \"Home\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveAriaLabel("Home Page", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"aria-label\" attribute to have value \"Home Page\" because this is very important to Steve, but found \"Home\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"aria-label\" attribute to have value \"Home Page\" because this is very important to Steve, but found \"Home\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAttributeShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAttributeShould.razor similarity index 59% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAttributeShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAttributeShould.razor index f1b6ed4..fc5120f 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveAttributeShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveAttributeShould.razor @@ -1,22 +1,27 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Logo) .Should().HaveAttribute("alt", "Logo"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Logo) .Should().HaveAttribute("alt", "Logo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -26,9 +31,9 @@ .Should().HaveAttribute("alt", "Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"alt\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"alt\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveAttribute("alt", "Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"alt\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"alt\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveAttribute("alt", "Logo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"alt\" attribute to have value \"Logo\", but found \"Log\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"alt\" attribute to have value \"Logo\", but found \"Log\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveAttribute("alt", "Logo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"alt\" attribute to have value \"Logo\" because this is very important to Steve, but found \"Log\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveChildMarkupShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveChildMarkupShould.razor similarity index 57% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveChildMarkupShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveChildMarkupShould.razor index e723e19..f54625f 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveChildMarkupShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveChildMarkupShould.razor @@ -1,50 +1,60 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed_WhenMatchingByString() { Render(@) .Should().HaveChildMarkup("

Test

"); } - + [Fact] public void Succeed_WhenMatchingByRenderFragment() { Render(@) .Should().HaveChildMarkup(@

Test

); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByString() { var andConstraint = Render(@) .Should().HaveChildMarkup("

Test

"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByRenderFragment() { var andConstraint = Render(@) .Should().HaveChildMarkup(@

Test

); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenChildMarkupIsNull_AndMatchingByString() { Action aut = () => Render(@) - .Should().HaveChildMarkup("

Test

");; + .Should().HaveChildMarkup("

Test

"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\", but found ."); } - + [Fact] public void ThrowException_WhenChildMarkupIsNull_AndMatchingByRenderFragment() { @@ -52,19 +62,19 @@ .Should().HaveChildMarkup(@

Test

); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\", but found ."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupIsNull_AndMatchingByString() { Action aut = () => Render(@) - .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve");; + .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupIsNull_AndMatchingByRenderFragment() { @@ -72,19 +82,19 @@ .Should().HaveChildMarkup(@

Test

, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\" because this is very important to Steve, but found ."); } [Fact] public void ThrowException_WhenChildMarkupDoesNotMatch_AndMatchingByString() { Action aut = () => Render(@) - .Should().HaveChildMarkup("

Test

");; + .Should().HaveChildMarkup("

Test

"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\", but found \"

Test

\"."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\", but found \"

Test

\"."); } - + [Fact] public void ThrowException_WhenChildMarkupDoesNotMatch_AndMatchingByRenderFragment() { @@ -92,19 +102,19 @@ .Should().HaveChildMarkup(@

Test

); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\", but found \"

Test

\"."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\", but found \"

Test

\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByString() { Action aut = () => Render(@) - .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve");; + .Should().HaveChildMarkup("

Test

", "this is very important to {0}", "Steve"); ; aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByRenderFragment() { @@ -112,6 +122,6 @@ .Should().HaveChildMarkup(@

Test

, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); + .And.Message.Should().Be("Expected IRenderedComponent to have child \"

Test

\" because this is very important to Steve, but found \"

Test

\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveClassShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveClassShould.razor similarity index 62% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveClassShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveClassShould.razor index 6bd201e..0e8253e 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveClassShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveClassShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Theory] [InlineData("btn")] [InlineData("big")] @@ -12,16 +12,21 @@ Render(@) .Should().HaveClass(expectedClass); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveClass("btn"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAnyClass() { @@ -29,9 +34,9 @@ .Should().HaveClass("btn"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {empty} to contain \"btn\"."); + .And.Message.Should().Be("Expected element.ClassList {empty} to contain \"btn\"."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAnyClass_AndShouldIncludeBecauseMessage() { @@ -39,9 +44,9 @@ .Should().HaveClass("btn", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {empty} to contain \"btn\" because this is very important to Steve."); + .And.Message.Should().Be("Expected element.ClassList {empty} to contain \"btn\" because this is very important to Steve."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -49,9 +54,9 @@ .Should().HaveClass("btn"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\"."); + .And.Message.Should().Be("Expected element.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -59,6 +64,6 @@ .Should().HaveClass("btn", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\" because this is very important to Steve."); + .And.Message.Should().Be("Expected element.ClassList {\"btt\", \"big\", \"cta\"} to contain \"btn\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestClassShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestClassShould.razor similarity index 59% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestClassShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestClassShould.razor index 8fd624c..a951563 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestClassShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestClassShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().HaveDataTestClass("magic-button"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveDataTestClass("magic-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveDataTestClass("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"data-test-class\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"data-test-class\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveDataTestClass("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"data-test-class\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"data-test-class\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveDataTestClass("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"data-test-class\" attribute to have value \"magic-button\", but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"data-test-class\" attribute to have value \"magic-button\", but found \"magic-btn\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveDataTestClass("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"data-test-class\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"data-test-class\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestIdShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestIdShould.razor similarity index 59% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestIdShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestIdShould.razor index 116ac47..a0cba01 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveDataTestIdShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveDataTestIdShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().HaveDataTestId("magic-button"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveDataTestId("magic-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveDataTestId("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"data-test-id\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"data-test-id\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveDataTestId("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"data-test-id\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"data-test-id\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveDataTestId("magic-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"data-test-id\" attribute to have value \"magic-button\", but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"data-test-id\" attribute to have value \"magic-button\", but found \"magic-btn\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveDataTestId("magic-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"data-test-id\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"data-test-id\" attribute to have value \"magic-button\" because this is very important to Steve, but found \"magic-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveHrefShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveHrefShould.razor similarity index 60% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveHrefShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveHrefShould.razor index 8ad5c09..2c5103c 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveHrefShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveHrefShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Link) .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Link) .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"href\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"href\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"href\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"href\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\", but found \"#\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\", but found \"#\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveHref("https://github.com/srpeirce/fluentassertions.bUnit", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\" because this is very important to Steve, but found \"#\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"href\" attribute to have value \"https://github.com/srpeirce/fluentassertions.bUnit\" because this is very important to Steve, but found \"#\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveIdShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveIdShould.razor similarity index 58% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveIdShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveIdShould.razor index c20b36b..354d7fc 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveIdShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveIdShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().HaveId("special-button"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveId("special-button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveId("special-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"id\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"id\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveId("special-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"id\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"id\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveId("special-button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"id\" attribute to have value \"special-button\", but found \"special-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"id\" attribute to have value \"special-button\", but found \"special-btn\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveId("special-button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"id\" attribute to have value \"special-button\" because this is very important to Steve, but found \"special-btn\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"id\" attribute to have value \"special-button\" because this is very important to Steve, but found \"special-btn\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveMarkupShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveMarkupShould.razor similarity index 55% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveMarkupShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveMarkupShould.razor index 65b0427..d99dfa8 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveMarkupShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveMarkupShould.razor @@ -1,38 +1,48 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed_WhenMatchingByString() { Render(@) .Should().HaveMarkup(""); } - + [Fact] public void Succeed_WhenMatchingByRenderFragment() { Render(@) .Should().HaveMarkup(@); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByString() { var andConstraint = Render(@) .Should().HaveMarkup(""); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ReturnAndConstraint_WhenMatchingByRenderFragment() { var andConstraint = Render(@) .Should().HaveMarkup(@); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -42,7 +52,7 @@ .Should().HaveMarkup(""); aut.Should().Throw() - .And.UserMessage.Should().BeEquivalentTo("Expected IRenderedFragment markup \"\", but found \"\"."); + .And.Message.Should().BeEquivalentTo("Expected IRenderedComponent markup \"\", but found \"\"."); } [Fact] @@ -52,19 +62,19 @@ .Should().HaveMarkup(@); aut.Should().Throw() - .And.UserMessage.Should().BeEquivalentTo("Expected IRenderedFragment markup \"\", but found \"\"."); + .And.Message.Should().BeEquivalentTo("Expected IRenderedComponent markup \"\", but found \"\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByString() { Action aut = () => Render(@) - .Should().HaveMarkup("", "this is very important to {0}", "Steve");; + .Should().HaveMarkup("", "this is very important to {0}", "Steve"); ; aut.Should().Throw() - .And.UserMessage.Should().BeEquivalentTo("Expected IRenderedFragment markup \"\" because this is very important to Steve, but found \"\"."); + .And.Message.Should().BeEquivalentTo("Expected IRenderedComponent markup \"\" because this is very important to Steve, but found \"\"."); } - + [Fact] public void ThrowException_AndIncludeBecauseMessage_WhenChildMarkupDoesNotMatch_AndMatchingByRenderFragment() { @@ -72,6 +82,6 @@ .Should().HaveMarkup(@, "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().BeEquivalentTo("Expected IRenderedFragment markup \"\" because this is very important to Steve, but found \"\"."); + .And.Message.Should().BeEquivalentTo("Expected IRenderedComponent markup \"\" because this is very important to Steve, but found \"\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveRelShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveRelShould.razor similarity index 61% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveRelShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveRelShould.razor index 6fc707a..7c3caf3 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveRelShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveRelShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Theory] [InlineData("nofollow")] [InlineData("noopener")] @@ -11,7 +11,7 @@ Render(@Link) .Should().HaveRel(expected); } - + [Theory] [InlineData("nofollow")] [InlineData("noopener")] @@ -20,9 +20,14 @@ var andConstraint = Render(@Link) .Should().HaveRel(expected); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -30,9 +35,9 @@ .Should().HaveRel("nofollow"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"rel\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"rel\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -40,9 +45,9 @@ .Should().HaveRel("nofollow", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"rel\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"rel\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -50,9 +55,9 @@ .Should().HaveRel("noopener"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"rel\" [{\"nofollow\"}] to contain \"noopener\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"rel\" [{\"nofollow\"}] to contain \"noopener\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -60,6 +65,6 @@ .Should().HaveRel("noopener", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"rel\" [{\"nofollow\"}] to contain \"noopener\" because this is very important to Steve."); + .And.Message.Should().Be("Expected IRenderedComponent \"rel\" [{\"nofollow\"}] to contain \"noopener\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveSrcShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveSrcShould.razor similarity index 57% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveSrcShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveSrcShould.razor index 5f89e36..9ad58aa 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveSrcShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveSrcShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Logo) .Should().HaveSrc("/logo.png"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Logo) .Should().HaveSrc("/logo.png"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveSrc("/logo.png"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"src\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"src\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveSrc("/logo.png", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"src\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"src\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveSrc("/logo.png"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"src\" attribute to have value \"/logo.png\", but found \"/loog.png\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"src\" attribute to have value \"/logo.png\", but found \"/loog.png\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveSrc("/logo.png", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"src\" attribute to have value \"/logo.png\" because this is very important to Steve, but found \"/loog.png\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"src\" attribute to have value \"/logo.png\" because this is very important to Steve, but found \"/loog.png\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTagShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTagShould.razor similarity index 54% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTagShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTagShould.razor index 9ab2c09..5a34acb 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTagShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTagShould.razor @@ -1,22 +1,27 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().HaveTag("button"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveTag("button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -26,9 +31,9 @@ .Should().HaveTag("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"tag\" to be \"button\", but found \"div\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"tag\" to be \"button\", but found \"div\"."); } - + [Fact] public void ThrowException_WhenTagNotMatchExpected_AndShouldIncludeBecauseMessage() { @@ -36,6 +41,6 @@ .Should().HaveTag("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"tag\" to be \"button\" because this is very important to Steve, but found \"div\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"tag\" to be \"button\" because this is very important to Steve, but found \"div\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTargetShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTargetShould.razor similarity index 55% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTargetShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTargetShould.razor index 523a28d..95f44e6 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTargetShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTargetShould.razor @@ -1,34 +1,39 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Link) .Should().HaveTarget("_blank"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Link) .Should().HaveTarget("_blank"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { - Action aut = () => Render(@Link) + Action aut = () => Render(@Link) .Should().HaveTarget("_blank"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"target\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"target\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveTarget("_blank", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"target\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"target\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveTarget("_blank"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"target\" attribute to have value \"_blank\", but found \"_self\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"target\" attribute to have value \"_blank\", but found \"_self\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveTarget("_blank", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"target\" attribute to have value \"_blank\" because this is very important to Steve, but found \"_self\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"target\" attribute to have value \"_blank\" because this is very important to Steve, but found \"_self\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTitleShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTitleShould.razor similarity index 58% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTitleShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTitleShould.razor index 6557c8e..42564e0 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTitleShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTitleShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@Link) .Should().HaveTitle("GitHub Repo"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@Link) .Should().HaveTitle("GitHub Repo"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveTitle("GitHub Repo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"title\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"title\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveTitle("GitHub Repo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"title\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"title\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveTitle("GitHub Repo"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"title\" attribute to have value \"GitHub Repo\", but found \"GH Repo\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"title\" attribute to have value \"GitHub Repo\", but found \"GH Repo\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveTitle("GitHub Repo", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"title\" attribute to have value \"GitHub Repo\" because this is very important to Steve, but found \"GH Repo\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"title\" attribute to have value \"GitHub Repo\" because this is very important to Steve, but found \"GH Repo\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTypeShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTypeShould.razor similarity index 58% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTypeShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTypeShould.razor index 50a51c6..adf4457 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/HaveTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/HaveTypeShould.razor @@ -1,24 +1,29 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().HaveType("button"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().HaveType("button"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute() { @@ -26,9 +31,9 @@ .Should().HaveType("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"type\", but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"type\", but found ."); } - + [Fact] public void ThrowException_WhenDoesNotHaveAttribute_AndShouldIncludeBecauseMessage() { @@ -36,9 +41,9 @@ .Should().HaveType("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment to have attribute \"type\" because this is very important to Steve, but found ."); + .And.Message.Should().Be("Expected IRenderedComponent to have attribute \"type\" because this is very important to Steve, but found ."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue() { @@ -46,9 +51,9 @@ .Should().HaveType("button"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"type\" attribute to have value \"button\", but found \"reset\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"type\" attribute to have value \"button\", but found \"reset\"."); } - + [Fact] public void ThrowException_WhenHasAttributeWithWrongValue_AndShouldIncludeBecauseMessage() { @@ -56,6 +61,6 @@ .Should().HaveType("button", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected IRenderedFragment \"type\" attribute to have value \"button\" because this is very important to Steve, but found \"reset\"."); + .And.Message.Should().Be("Expected IRenderedComponent \"type\" attribute to have value \"button\" because this is very important to Steve, but found \"reset\"."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeAssignableToShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeAssignableToShould.razor similarity index 91% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeAssignableToShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeAssignableToShould.razor index 41b3e3b..1bab8ac 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeAssignableToShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeAssignableToShould.razor @@ -1,15 +1,15 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenAssignable() { Render(@Logo) .Should().BeAssignableTo(); } - + [Fact] public void ThrowExceptionWhenNotAssignable() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeNullShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeNullShould.razor similarity index 73% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeNullShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeNullShould.razor index d5eeba4..9f34fa5 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeNullShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeNullShould.razor @@ -1,16 +1,16 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenNull() { - IRenderedFragment f = null; - + var f = (IRenderedComponent)null; + f.Should().BeNull(); } - + [Fact] public void ThrowExceptionWhenNotNull() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeOfTypeShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeOfTypeShould.razor similarity index 81% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeOfTypeShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeOfTypeShould.razor index 96a15e9..a33bce7 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeOfTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeOfTypeShould.razor @@ -1,22 +1,22 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenOfType() { var renderedFragment = Render(@Logo); - + renderedFragment .Should().BeOfType(renderedFragment.GetType()); } - + [Fact] public void ThrowExceptionWhenNotOfType() { Action aut = () => Render(@Logo) - .Should().BeOfType(); + .Should().BeOfType(); aut.Should().Throw(); } diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeSameAsShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeSameAsShould.razor similarity index 92% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeSameAsShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeSameAsShould.razor index cc69de9..90c9ce0 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/BeSameAsShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/BeSameAsShould.razor @@ -1,13 +1,13 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenComparingToSameReference() { var renderedFragment = Render(@Logo); - + renderedFragment .Should().BeSameAs(renderedFragment); } diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/MatchShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/MatchShould.razor similarity index 92% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/MatchShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/MatchShould.razor index 1dd7b10..3235d44 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/MatchShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/MatchShould.razor @@ -1,15 +1,15 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenMatches() { Render(@Logo) .Should().Match(rf => rf.Markup.Contains("img")); } - + [Fact] public void ThrowExceptionWhenDoesNotMatch() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeAssignableToShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeAssignableToShould.razor similarity index 91% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeAssignableToShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeAssignableToShould.razor index 9844221..9487a9f 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeAssignableToShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeAssignableToShould.razor @@ -1,15 +1,15 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenAssignable() { Render(@Logo) .Should().NotBeAssignableTo(); } - + [Fact] public void ThrowExceptionWhenNotAssignable() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeNullShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeNullShould.razor similarity index 75% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeNullShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeNullShould.razor index 59d546c..27e41dc 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeNullShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeNullShould.razor @@ -1,24 +1,24 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenNotNull() { Render(@Logo) .Should().NotBeNull(); } - + [Fact] public void ThrowExceptionWhenNull() { Action aut = () => { - IRenderedFragment f = null; + var f = (IRenderedComponent)null; f.Should().NotBeNull(); }; - + aut.Should().Throw(); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeOfTypeShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeOfTypeShould.razor similarity index 82% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeOfTypeShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeOfTypeShould.razor index ebabba6..e4ce3fc 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeOfTypeShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeOfTypeShould.razor @@ -1,15 +1,15 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenOfType() { Render(@Logo) - .Should().NotBeOfType(); + .Should().NotBeOfType(); } - + [Fact] public void ThrowExceptionWhenNotOfType() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeSameAsShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeSameAsShould.razor similarity index 94% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeSameAsShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeSameAsShould.razor index bcd23bc..e2225e1 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/NotBeSameAsShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/NotBeSameAsShould.razor @@ -1,8 +1,8 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void SucceedWhenComparingToAnotherReference() { diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/Readme.md b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/Readme.md similarity index 81% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/Readme.md rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/Readme.md index fe4471f..4e5d3e4 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/Readme.md +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/Readme.md @@ -1,3 +1,3 @@ -> 💡 Note: The functionality that we test here we get from `RenderedFragmentAssertions` inheriting from `ReferenceTypeAssertions`. +> 💡 Note: The functionality that we test here we get from `RenderedFragmentAssertions` inheriting from `ReferenceTypeAssertions, TAssertions>`. > > I decided to add some basic tests to explore their API and check it behaves as I expect. \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/SubjectShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/SubjectShould.razor similarity index 60% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/SubjectShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/SubjectShould.razor index 6e06d20..ba6ddb3 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/Inherited/SubjectShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/Inherited/SubjectShould.razor @@ -1,14 +1,14 @@ -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void BeSameAsRenderedFragment() { var renderedFragment = Render(@Logo); - + var subject = renderedFragment.Should().Subject; - subject.Should().BeAssignableTo().And.BeSameAs(renderedFragment); + subject.Should().BeAssignableTo(renderedFragment.GetType()).And.BeSameAs(renderedFragment); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/NotHaveClassShould.razor b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/NotHaveClassShould.razor similarity index 59% rename from FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/NotHaveClassShould.razor rename to FluentAssertions.BUnit.Tests/RenderedComponentAssertions/NotHaveClassShould.razor index 7a6c8c2..5e3f410 100644 --- a/FluentAssertions.BUnit.Tests/RenderedFragmentAssertions/NotHaveClassShould.razor +++ b/FluentAssertions.BUnit.Tests/RenderedComponentAssertions/NotHaveClassShould.razor @@ -1,29 +1,34 @@ @using Xunit.Sdk -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { - + [Fact] public void Succeed() { Render(@) .Should().NotHaveClass("btn-large"); } - + [Fact] public void Succeed_WhenNoClassInMarkup() { Render(@) .Should().NotHaveClass("btn-large"); } - + [Fact] public void ReturnAndConstraint() { var andConstraint = Render(@) .Should().NotHaveClass("btn-large"); - andConstraint.Should().BeOfType>(); + var constraintType = andConstraint.GetType(); + constraintType.IsGenericType.Should().BeTrue(); + constraintType.GetGenericTypeDefinition().Should().Be(typeof(AndConstraint<>)); + var assertionType = constraintType.GetGenericArguments()[0]; + assertionType.IsGenericType.Should().BeTrue(); + assertionType.GetGenericTypeDefinition().Should().Be(typeof(RenderedFragmentAssertions<>)); } [Fact] @@ -33,9 +38,9 @@ .Should().NotHaveClass("btn-large"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\"."); + .And.Message.Should().Be("Expected element.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\"."); } - + [Fact] public void ThrowException_WhenClassIsFound_AndShouldIncludeBecauseMessage() { @@ -43,6 +48,6 @@ .Should().NotHaveClass("btn-large", "this is very important to {0}", "Steve"); aut.Should().Throw() - .And.UserMessage.Should().Be("Expected element.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\" because this is very important to Steve."); + .And.Message.Should().Be("Expected element.ClassList {\"btn\", \"btn-large\", \"big\", \"cta\"} to not contain \"btn-large\" because this is very important to Steve."); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit.Tests/_Imports.razor b/FluentAssertions.BUnit.Tests/_Imports.razor index 170e53b..2c5c624 100644 --- a/FluentAssertions.BUnit.Tests/_Imports.razor +++ b/FluentAssertions.BUnit.Tests/_Imports.razor @@ -1,4 +1,4 @@ -@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Web @using Microsoft.JSInterop @using Microsoft.Extensions.DependencyInjection diff --git a/FluentAssertions.BUnit/AssertionExtensions.cs b/FluentAssertions.BUnit/AssertionExtensions.cs index 1ff706d..9d60318 100644 --- a/FluentAssertions.BUnit/AssertionExtensions.cs +++ b/FluentAssertions.BUnit/AssertionExtensions.cs @@ -1,18 +1,18 @@ using AngleSharp.Dom; using Bunit; -namespace FluentAssertions.BUnit +namespace FluentAssertions.BUnit; + +public static class AssertionExtensions { - public static class AssertionExtensions + public static RenderedFragmentAssertions Should(this IRenderedComponent actualValue) + where TComponent : Microsoft.AspNetCore.Components.IComponent + { + return new RenderedFragmentAssertions(actualValue); + } + + public static ElementAssertions Should(this IElement actualValue) { - public static RenderedFragmentAssertions Should(this IRenderedFragment actualValue) - { - return new RenderedFragmentAssertions(actualValue); - } - - public static ElementAssertions Should(this IElement actualValue) - { - return new ElementAssertions(actualValue); - } + return new ElementAssertions(actualValue); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit/BUnitExtensions.cs b/FluentAssertions.BUnit/BUnitExtensions.cs index 2af0383..dea5220 100644 --- a/FluentAssertions.BUnit/BUnitExtensions.cs +++ b/FluentAssertions.BUnit/BUnitExtensions.cs @@ -1,21 +1,25 @@ -using AngleSharp.Dom; +using System.Collections.Generic; +using AngleSharp.Dom; using Bunit; -namespace FluentAssertions.BUnit +namespace FluentAssertions.BUnit; + +public static class BUnitExtensions { - public static class BUnitExtensions - { - public static IElement FindByDataTestId(this IRenderedFragment component, string dataTestId) - => component.Find($"[data-test-id='{dataTestId}']"); - - public static IElement FindByDataTestClass(this IRenderedFragment component, string dataTestClass) - => component.Find($"[data-test-class='{dataTestClass}']"); + public static IElement FindByDataTestId(this IRenderedComponent component, string dataTestId) + where TComponent : Microsoft.AspNetCore.Components.IComponent + => component.Find($"[data-test-id='{dataTestId}']"); + + public static IElement FindByDataTestClass(this IRenderedComponent component, string dataTestClass) + where TComponent : Microsoft.AspNetCore.Components.IComponent + => component.Find($"[data-test-class='{dataTestClass}']"); - public static IRefreshableElementCollection FindAllByDataTestClass(this IRenderedFragment component, - string dataTestClass) - => component.FindAll($"[data-test-class='{dataTestClass}']"); + public static IReadOnlyList FindAllByDataTestClass(this IRenderedComponent component, + string dataTestClass) + where TComponent : Microsoft.AspNetCore.Components.IComponent + => component.FindAll($"[data-test-class='{dataTestClass}']"); - public static IElement AsElement(this IRenderedFragment component) - => component.Nodes.QuerySelector("*"); - } + public static IElement AsElement(this IRenderedComponent component) + where TComponent : Microsoft.AspNetCore.Components.IComponent + => component.Nodes.QuerySelector("*"); } \ No newline at end of file diff --git a/FluentAssertions.BUnit/ElementAssertions.cs b/FluentAssertions.BUnit/ElementAssertions.cs index 5c3dda8..0ad2d74 100644 --- a/FluentAssertions.BUnit/ElementAssertions.cs +++ b/FluentAssertions.BUnit/ElementAssertions.cs @@ -1,114 +1,50 @@ -using System; -using System.Linq; +using System.Text.RegularExpressions; using AngleSharp.Dom; using Bunit; using FluentAssertions.Execution; using FluentAssertions.Primitives; using Microsoft.AspNetCore.Components; +using System; +using System.Linq; + +namespace FluentAssertions.BUnit; -namespace FluentAssertions.BUnit +/// +/// Contains a number of methods to assert that an is in the expected state. +/// +/// +/// Initializes a new instance of the class. +/// +public class ElementAssertions(IElement value) : ElementAssertions(value) { +} + +public class ElementAssertions(IElement value) : ReferenceTypeAssertions(value) + where TAssertions : ElementAssertions +{ + private readonly BunitContext _testContext = new BunitContext(); + /// - /// Contains a number of methods to assert that a is in the expected state. + /// Returns the type of the subject the assertion applies on. /// - public class ElementAssertions : ElementAssertions - { - /// - /// Initializes a new instance of the class. - /// - public ElementAssertions(IElement value) - : base(value) - { - } - } + protected override string Identifier => "IElement"; - public class ElementAssertions : ReferenceTypeAssertions - where TAssertions : ElementAssertions + public AndConstraint HaveChildMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) { - private readonly TestContext _testContext; - - /// - /// Returns the type of the subject the assertion applies on. - /// - protected override string Identifier => "IRenderedFragment"; - - public ElementAssertions(IElement value) - : base(value) - { - _testContext = new TestContext(); - } - - public AndConstraint HaveChildMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) - { - var child = Subject.FirstChild; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(child is not null) - .FailWith("Expected {context:IElement} to have child {0}{reason}, but found .", _testContext.Render(expected).Markup); - - if (success) - { - bool doesMarkupMatch; - - try - { - child!.MarkupMatches(expected); - doesMarkupMatch = true; - } - catch - { - doesMarkupMatch = false; - } - - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IElement} to have child {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, child!.ToMarkup().TrimStart()); - } - - return new AndConstraint((TAssertions)this); - } - - public AndConstraint HaveChildMarkup(string expected, string because = "", params object[] becauseArgs) - { - var child = Subject.FirstChild; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(child is not null) - .FailWith("Expected {context:IElement} to have child {0}{reason}, but found .", expected); - - if (success) - { - bool doesMarkupMatch; - - try - { - child!.MarkupMatches(expected); - doesMarkupMatch = true; - } - catch - { - doesMarkupMatch = false; - } - - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IElement} to have child {0}{reason}, but found {1}.", expected, child!.ToMarkup().TrimStart()); - } - - return new AndConstraint((TAssertions)this); - } - - public AndConstraint HaveMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) + var child = Subject.FirstChild; + + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(child is not null) + .FailWith("Expected {context:IElement} to have child {0}{reason}, but found .", _testContext.Render(expected).Markup); + + if (success) { bool doesMarkupMatch; - + try { - Subject.MarkupMatches(expected); + child!.MarkupMatches(expected); doesMarkupMatch = true; } catch @@ -119,17 +55,28 @@ public AndConstraint HaveMarkup(RenderFragment expected, string bec Execute.Assertion .BecauseOf(because, becauseArgs) .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IElement} markup {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, Subject.ToMarkup()); - return new AndConstraint((TAssertions)this); + .FailWith("Expected {context:IElement} to have child {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, child is IElement childElement ? Regex.Replace(childElement.OuterHtml ?? "", @">\s+<", "><").Trim() : child?.ToString() ?? ""); } - - public AndConstraint HaveMarkup(string expected, string because = "", params object[] becauseArgs) + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveChildMarkup(string expected, string because = "", params object[] becauseArgs) + { + var child = Subject.FirstChild; + + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(child is not null) + .FailWith("Expected {context:IElement} to have child {0}{reason}, but found .", expected); + + if (success) { bool doesMarkupMatch; - + try { - Subject.MarkupMatches(expected); + child!.MarkupMatches(expected); doesMarkupMatch = true; } catch @@ -140,107 +87,150 @@ public AndConstraint HaveMarkup(string expected, string because = " Execute.Assertion .BecauseOf(because, becauseArgs) .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IElement} markup {0}{reason}, but found {1}.", expected, Subject.ToMarkup()); - - return new AndConstraint((TAssertions)this); + .FailWith("Expected {context:IElement} to have child {0}{reason}, but found {1}.", expected, child is IElement childElement ? Regex.Replace(childElement.OuterHtml ?? "", @">\s+<", "><").Trim() : child?.ToString() ?? ""); } - - public AndConstraint NotHaveClass(string expected, string because = "", params object[] becauseArgs) + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) + { + bool doesMarkupMatch; + + try { - Subject.ClassList.Should().NotContain(expected, because, becauseArgs); - - return new AndConstraint((TAssertions)this); + Subject.MarkupMatches(expected); + doesMarkupMatch = true; } - - public AndConstraint HaveClass(string expected, string because = "", params object[] becauseArgs) + catch { - Subject.ClassList.Should().Contain(expected, because, becauseArgs); - - return new AndConstraint((TAssertions)this); + doesMarkupMatch = false; } - public AndConstraint HaveRel(string expected, string because = "", params object[] becauseArgs) + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(doesMarkupMatch) + .FailWith("Expected {context:IElement} markup {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, Regex.Replace(Subject.OuterHtml, @">\s+<", "><").Trim()); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveMarkup(string expected, string because = "", params object[] becauseArgs) + { + bool doesMarkupMatch; + + try { - var attribute = Subject.Attributes["rel"]; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute is not null) - .FailWith("Expected {context:IElement} to have attribute {0}{reason}, but found .", "rel"); + Subject.MarkupMatches(expected); + doesMarkupMatch = true; + } + catch + { + doesMarkupMatch = false; + } - if (success) - { - var collection = attribute!.Value.Split(" ").ToList(); - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute!.Value.Split(" ").Contains(expected)) - .FailWith("Expected {context:IElement} {0} [{1}] to contain {2}{reason}.", "rel", collection, expected); - } + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(doesMarkupMatch) + .FailWith("Expected {context:IElement} markup {0}{reason}, but found {1}.", expected, Regex.Replace(Subject.OuterHtml, @">\s+<", "><").Trim()); + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint NotHaveClass(string expected, string because = "", params object[] becauseArgs) + { + Subject.ClassList.Should().NotContain(expected, because, becauseArgs); - return new AndConstraint((TAssertions)this); - } + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveClass(string expected, string because = "", params object[] becauseArgs) + { + Subject.ClassList.Should().Contain(expected, because, becauseArgs); - public AndConstraint HaveTag(string expected, string because = "", params object[] becauseArgs) + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveRel(string expected, string because = "", params object[] becauseArgs) + { + var attribute = Subject.Attributes["rel"]; + + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(attribute is not null) + .FailWith("Expected {context:IElement} to have attribute {0}{reason}, but found .", "rel"); + + if (success) { - var tag = Subject.LocalName; - + var collection = attribute!.Value.Split(" ").ToList(); Execute.Assertion .BecauseOf(because, becauseArgs) - .ForCondition(tag.Equals(expected, StringComparison.InvariantCulture)) - .FailWith("Expected {context:IElement} {0} to be {1}{reason}, but found {2}.", "tag", expected, tag); - - return new AndConstraint((TAssertions)this); + .ForCondition(attribute!.Value.Split(" ").Contains(expected)) + .FailWith("Expected {context:IElement} {0} [{1}] to contain {2}{reason}.", "rel", collection, expected); } + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveTag(string expected, string because = "", params object[] becauseArgs) + { + var tag = Subject.LocalName; - public AndConstraint HaveAltText(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("alt", expected, because, becauseArgs); - - public AndConstraint HaveAriaLabel(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("aria-label", expected, because, becauseArgs); - - public AndConstraint HaveDataTestClass(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("data-test-class", expected, because, becauseArgs); - - public AndConstraint HaveDataTestId(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("data-test-id", expected, because, becauseArgs); - - public AndConstraint HaveHref(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("href", expected, because, becauseArgs); - - public AndConstraint HaveId(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("id", expected, because, becauseArgs); - - public AndConstraint HaveSrc(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("src", expected, because, becauseArgs); - - public AndConstraint HaveTarget(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("target", expected, because, becauseArgs); + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(tag.Equals(expected, StringComparison.InvariantCulture)) + .FailWith("Expected {context:IElement} {0} to be {1}{reason}, but found {2}.", "tag", expected, tag); - public AndConstraint HaveTitle(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("title", expected, because, becauseArgs); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveAltText(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("alt", expected, because, becauseArgs); + + public AndConstraint HaveAriaLabel(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("aria-label", expected, because, becauseArgs); + + public AndConstraint HaveDataTestClass(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("data-test-class", expected, because, becauseArgs); + + public AndConstraint HaveDataTestId(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("data-test-id", expected, because, becauseArgs); + + public AndConstraint HaveHref(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("href", expected, because, becauseArgs); + + public AndConstraint HaveId(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("id", expected, because, becauseArgs); + + public AndConstraint HaveSrc(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("src", expected, because, becauseArgs); + + public AndConstraint HaveTarget(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("target", expected, because, becauseArgs); + + public AndConstraint HaveTitle(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("title", expected, because, becauseArgs); + + public AndConstraint HaveType(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("type", expected, because, becauseArgs); + + public AndConstraint HaveAttribute(string attributeName, string expectedValue, string because = "", params object[] becauseArgs) + { + var attribute = Subject.Attributes[attributeName]; - public AndConstraint HaveType(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("type", expected, because, becauseArgs); + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(attribute is not null) + .FailWith("Expected {context:IElement} to have attribute {0}{reason}, but found .", attributeName); - public AndConstraint HaveAttribute(string attributeName, string expectedValue, string because = "", params object[] becauseArgs) + if (success) { - var attribute = Subject.Attributes[attributeName]; - - bool success = Execute.Assertion + Execute.Assertion .BecauseOf(because, becauseArgs) - .ForCondition(attribute is not null) - .FailWith("Expected {context:IElement} to have attribute {0}{reason}, but found .", attributeName); - - if (success) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute!.Value == expectedValue) - .FailWith("Expected {context:IElement} {0} attribute to have value {1}{reason}" + - ", but found {2}.", attributeName, expectedValue, attribute.Value); - } - - return new AndConstraint((TAssertions)this); + .ForCondition(attribute!.Value == expectedValue) + .FailWith("Expected {context:IElement} {0} attribute to have value {1}{reason}" + + ", but found {2}.", attributeName, expectedValue, attribute.Value); } + + return new AndConstraint((TAssertions)this); } } \ No newline at end of file diff --git a/FluentAssertions.BUnit/FluentAssertions.BUnit.csproj b/FluentAssertions.BUnit/FluentAssertions.BUnit.csproj index 24caea2..d2bd501 100644 --- a/FluentAssertions.BUnit/FluentAssertions.BUnit.csproj +++ b/FluentAssertions.BUnit/FluentAssertions.BUnit.csproj @@ -1,7 +1,7 @@ - net5.0 + net10.0 enable Blazor;BUnit;FluentAssertions @@ -15,9 +15,9 @@ - - - + + + diff --git a/FluentAssertions.BUnit/RenderedFragmentAssertions.cs b/FluentAssertions.BUnit/RenderedFragmentAssertions.cs index ac091f0..83b96aa 100644 --- a/FluentAssertions.BUnit/RenderedFragmentAssertions.cs +++ b/FluentAssertions.BUnit/RenderedFragmentAssertions.cs @@ -1,115 +1,53 @@ using System; using System.Linq; +using System.Text.RegularExpressions; +using AngleSharp.Dom; using Bunit; using FluentAssertions.Execution; using FluentAssertions.Primitives; using Microsoft.AspNetCore.Components; -namespace FluentAssertions.BUnit +namespace FluentAssertions.BUnit; + +/// +/// Contains a number of methods to assert that a is in the expected state. +/// +/// +/// Initializes a new instance of the class. +/// +public class RenderedFragmentAssertions(IRenderedComponent value) : RenderedFragmentAssertions, TComponent>(value) + where TComponent : IComponent +{ +} + +public class RenderedFragmentAssertions(IRenderedComponent value) : ReferenceTypeAssertions, TAssertions>(value) + where TAssertions : RenderedFragmentAssertions + where TComponent : IComponent { + private readonly BunitContext _testContext = new BunitContext(); + /// - /// Contains a number of methods to assert that a is in the expected state. + /// Returns the type of the subject the assertion applies on. /// - public class RenderedFragmentAssertions : RenderedFragmentAssertions - { - /// - /// Initializes a new instance of the class. - /// - public RenderedFragmentAssertions(IRenderedFragment value) - : base(value) - { - } - } + protected override string Identifier => "IRenderedComponent"; - public class RenderedFragmentAssertions : ReferenceTypeAssertions - where TAssertions : RenderedFragmentAssertions + public AndConstraint HaveChildMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) { - private readonly TestContext _testContext; - - /// - /// Returns the type of the subject the assertion applies on. - /// - protected override string Identifier => "IRenderedFragment"; - - public RenderedFragmentAssertions(IRenderedFragment value) - : base(value) - { - _testContext = new TestContext(); - } + var element = Subject.AsElement(); + var child = element.FirstChild; - public AndConstraint HaveChildMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) - { - var element = Subject.AsElement(); - var child = element.FirstChild; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(child is not null) - .FailWith("Expected {context:IRenderedFragment} to have child {0}{reason}, but found .", _testContext.Render(expected).Markup); + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(child is not null) + .FailWith("Expected {context:IRenderedComponent} to have child {0}{reason}, but found .", _testContext.Render(expected).Markup); - if (success) - { - bool doesMarkupMatch; - - try - { - child!.MarkupMatches(expected); - doesMarkupMatch = true; - } - catch - { - doesMarkupMatch = false; - } - - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IRenderedFragment} to have child {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, child!.ToMarkup().TrimStart()); - } - - return new AndConstraint((TAssertions)this); - } - - public AndConstraint HaveChildMarkup(string expected, string because = "", params object[] becauseArgs) - { - var element = Subject.AsElement(); - var child = element.FirstChild; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(child is not null) - .FailWith("Expected {context:IRenderedFragment} to have child {0}{reason}, but found .", expected); - - if (success) - { - bool doesMarkupMatch; - - try - { - child!.MarkupMatches(expected); - doesMarkupMatch = true; - } - catch - { - doesMarkupMatch = false; - } - - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IRenderedFragment} to have child {0}{reason}, but found {1}.", expected, child!.ToMarkup().TrimStart()); - } - - return new AndConstraint((TAssertions)this); - } - - public AndConstraint HaveMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) + if (success) { bool doesMarkupMatch; - + try { - Subject.MarkupMatches(expected); + child!.MarkupMatches(expected); doesMarkupMatch = true; } catch @@ -120,17 +58,29 @@ public AndConstraint HaveMarkup(RenderFragment expected, string bec Execute.Assertion .BecauseOf(because, becauseArgs) .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IRenderedFragment} markup {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, Subject.Markup); - return new AndConstraint((TAssertions)this); + .FailWith("Expected {context:IRenderedComponent} to have child {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, child is IElement childElement ? Regex.Replace(childElement.OuterHtml ?? "", @">\s+<", "><").Trim() : child?.ToString() ?? ""); } + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveChildMarkup(string expected, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + var child = element.FirstChild; - public AndConstraint HaveMarkup(string expected, string because = "", params object[] becauseArgs) + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(child is not null) + .FailWith("Expected {context:IRenderedComponent} to have child {0}{reason}, but found .", expected); + + if (success) { bool doesMarkupMatch; - + try { - Subject.MarkupMatches(expected); + child!.MarkupMatches(expected); doesMarkupMatch = true; } catch @@ -141,112 +91,155 @@ public AndConstraint HaveMarkup(string expected, string because = " Execute.Assertion .BecauseOf(because, becauseArgs) .ForCondition(doesMarkupMatch) - .FailWith("Expected {context:IRenderedFragment} markup {0}{reason}, but found {1}.", expected, Subject.Markup); - - return new AndConstraint((TAssertions)this); + .FailWith("Expected {context:IRenderedComponent} to have child {0}{reason}, but found {1}.", expected, child is IElement childElement ? Regex.Replace(childElement.OuterHtml ?? "", @">\s+<", "><").Trim() : child?.ToString() ?? ""); } - - public AndConstraint NotHaveClass(string expected, string because = "", params object[] becauseArgs) + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveMarkup(RenderFragment expected, string because = "", params object[] becauseArgs) + { + bool doesMarkupMatch; + + try { - var element = Subject.AsElement(); - element.ClassList.Should().NotContain(expected, because, becauseArgs); - - return new AndConstraint((TAssertions)this); + Subject.MarkupMatches(expected); + doesMarkupMatch = true; } - - public AndConstraint HaveClass(string expected, string because = "", params object[] becauseArgs) + catch { - var element = Subject.AsElement(); - element.ClassList.Should().Contain(expected, because, becauseArgs); - - return new AndConstraint((TAssertions)this); + doesMarkupMatch = false; } - public AndConstraint HaveRel(string expected, string because = "", params object[] becauseArgs) + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(doesMarkupMatch) + .FailWith("Expected {context:IRenderedComponent} markup {0}{reason}, but found {1}.", _testContext.Render(expected).Markup, Subject.Markup); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveMarkup(string expected, string because = "", params object[] becauseArgs) + { + bool doesMarkupMatch; + + try { - var element = Subject.AsElement(); - var attribute = element.Attributes["rel"]; - - bool success = Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute is not null) - .FailWith("Expected {context:IRenderedFragment} to have attribute {0}{reason}, but found .", "rel"); - - if (success) - { - var collection = attribute!.Value.Split(" ").ToList(); - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute!.Value.Split(" ").Contains(expected)) - .FailWith("Expected {context:IRenderedFragment} {0} [{1}] to contain {2}{reason}.", "rel", collection, expected); - } - - return new AndConstraint((TAssertions)this); + Subject.MarkupMatches(expected); + doesMarkupMatch = true; } - - public AndConstraint HaveTag(string expected, string because = "", params object[] becauseArgs) + catch { - var element = Subject.AsElement(); - var tag = element.LocalName; - - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(tag.Equals(expected, StringComparison.InvariantCulture)) - .FailWith("Expected {context:IRenderedFragment} {0} to be {1}{reason}, but found {2}.", "tag", expected, tag); - - return new AndConstraint((TAssertions)this); + doesMarkupMatch = false; } - - public AndConstraint HaveAltText(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("alt", expected, because, becauseArgs); - public AndConstraint HaveAriaLabel(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("aria-label", expected, because, becauseArgs); - - public AndConstraint HaveDataTestClass(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("data-test-class", expected, because, becauseArgs); - - public AndConstraint HaveDataTestId(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("data-test-id", expected, because, becauseArgs); + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(doesMarkupMatch) + .FailWith("Expected {context:IRenderedComponent} markup {0}{reason}, but found {1}.", expected, Subject.Markup); + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint NotHaveClass(string expected, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + element.ClassList.Should().NotContain(expected, because, becauseArgs); - public AndConstraint HaveHref(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("href", expected, because, becauseArgs); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveClass(string expected, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + element.ClassList.Should().Contain(expected, because, becauseArgs); - public AndConstraint HaveId(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("id", expected, because, becauseArgs); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveRel(string expected, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + var attribute = element.Attributes["rel"]; - public AndConstraint HaveSrc(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("src", expected, because, becauseArgs); + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(attribute is not null) + .FailWith("Expected {context:IRenderedComponent} to have attribute {0}{reason}, but found .", "rel"); + + if (success) + { + var collection = attribute!.Value.Split(" ").ToList(); + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(attribute!.Value.Split(" ").Contains(expected)) + .FailWith("Expected {context:IRenderedComponent} {0} [{1}] to contain {2}{reason}.", "rel", collection, expected); + } + + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveTag(string expected, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + var tag = element.LocalName; - public AndConstraint HaveTarget(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("target", expected, because, becauseArgs); + Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(tag.Equals(expected, StringComparison.InvariantCulture)) + .FailWith("Expected {context:IRenderedComponent} {0} to be {1}{reason}, but found {2}.", "tag", expected, tag); - public AndConstraint HaveTitle(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("title", expected, because, becauseArgs); + return new AndConstraint((TAssertions)this); + } + + public AndConstraint HaveAltText(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("alt", expected, because, becauseArgs); + + public AndConstraint HaveAriaLabel(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("aria-label", expected, because, becauseArgs); + + public AndConstraint HaveDataTestClass(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("data-test-class", expected, because, becauseArgs); + + public AndConstraint HaveDataTestId(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("data-test-id", expected, because, becauseArgs); + + public AndConstraint HaveHref(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("href", expected, because, becauseArgs); + + public AndConstraint HaveId(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("id", expected, because, becauseArgs); + + public AndConstraint HaveSrc(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("src", expected, because, becauseArgs); + + public AndConstraint HaveTarget(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("target", expected, because, becauseArgs); + + public AndConstraint HaveTitle(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("title", expected, because, becauseArgs); + + public AndConstraint HaveType(string expected, string because = "", params object[] becauseArgs) + => HaveAttribute("type", expected, because, becauseArgs); + + public AndConstraint HaveAttribute(string attributeName, string expectedValue, string because = "", params object[] becauseArgs) + { + var element = Subject.AsElement(); + var attribute = element.Attributes[attributeName]; - public AndConstraint HaveType(string expected, string because = "", params object[] becauseArgs) - => HaveAttribute("type", expected, because, becauseArgs); + bool success = Execute.Assertion + .BecauseOf(because, becauseArgs) + .ForCondition(attribute is not null) + .FailWith("Expected {context:IRenderedComponent} to have attribute {0}{reason}, but found .", attributeName); - public AndConstraint HaveAttribute(string attributeName, string expectedValue, string because = "", params object[] becauseArgs) + if (success) { - var element = Subject.AsElement(); - var attribute = element.Attributes[attributeName]; - - bool success = Execute.Assertion + Execute.Assertion .BecauseOf(because, becauseArgs) - .ForCondition(attribute is not null) - .FailWith("Expected {context:IRenderedFragment} to have attribute {0}{reason}, but found .", attributeName); - - if (success) - { - Execute.Assertion - .BecauseOf(because, becauseArgs) - .ForCondition(attribute!.Value == expectedValue) - .FailWith("Expected {context:IRenderedFragment} {0} attribute to have value {1}{reason}" + - ", but found {2}.", attributeName, expectedValue, attribute.Value); - } - - return new AndConstraint((TAssertions)this); + .ForCondition(attribute!.Value == expectedValue) + .FailWith("Expected {context:IRenderedComponent} {0} attribute to have value {1}{reason}" + + ", but found {2}.", attributeName, expectedValue, attribute.Value); } + + return new AndConstraint((TAssertions)this); } } \ No newline at end of file