From ee621f9bd5442af9d8314f703035eb65966630aa Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger Date: Mon, 18 Apr 2022 17:46:33 +0200 Subject: [PATCH] Seperate all `Guid` assertions into nested classes --- .../Primitives/GuidAssertionSpecs.cs | 371 +++++++++--------- 1 file changed, 189 insertions(+), 182 deletions(-) diff --git a/Tests/FluentAssertions.Specs/Primitives/GuidAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Primitives/GuidAssertionSpecs.cs index c86ae89170..486dafa84f 100644 --- a/Tests/FluentAssertions.Specs/Primitives/GuidAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Primitives/GuidAssertionSpecs.cs @@ -6,201 +6,208 @@ namespace FluentAssertions.Specs.Primitives { public class GuidAssertionSpecs { - #region BeEmpty / NotBeEmpty - - [Fact] - public void Should_succeed_when_asserting_empty_guid_is_empty() - { - // Arrange - Guid guid = Guid.Empty; - - // Act / Assert - guid.Should().BeEmpty(); - } - - [Fact] - public void Should_fail_when_asserting_non_empty_guid_is_empty() - { - // Arrange - var guid = new Guid("12345678-1234-1234-1234-123456789012"); - - // Act - Action act = () => guid.Should().BeEmpty("because we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw().WithMessage( - "Expected Guid to be empty because we want to test the failure message, but found {12345678-1234-1234-1234-123456789012}."); - } - - [Fact] - public void Should_succeed_when_asserting_non_empty_guid_is_not_empty() - { - // Arrange - var guid = new Guid("12345678-1234-1234-1234-123456789012"); - - // Act - Action act = () => guid.Should().NotBeEmpty(); - - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void Should_fail_when_asserting_empty_guid_is_not_empty() - { - // Act - Action act = () => Guid.Empty.Should().NotBeEmpty("because we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw().WithMessage( - "Did not expect Guid.Empty to be empty because we want to test the failure message."); - } - - #endregion - - #region Be / NotBe - - [Fact] - public void Should_succeed_when_asserting_guid_equals_the_same_guid() - { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => guid.Should().Be(sameGuid); - - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void Should_succeed_when_asserting_guid_equals_the_same_guid_in_string_format() - { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => guid.Should().Be("11111111-aaaa-bbbb-cccc-999999999999"); - - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void Should_fail_when_asserting_guid_equals_a_different_guid() - { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); - - // Act - Action act = () => guid.Should().Be(differentGuid, "because we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw().WithMessage( - "Expected Guid to be {55555555-ffff-eeee-dddd-444444444444} because we want to test the failure message, but found {11111111-aaaa-bbbb-cccc-999999999999}."); - } - - [Fact] - public void Should_throw_when_asserting_guid_equals_a_string_that_is_not_a_valid_guid() - { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => guid.Should().Be(string.Empty, "we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw() - .WithParameterName("expected"); - } - - [Fact] - public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid() - { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); - - // Act - Action act = () => - guid.Should().NotBe(differentGuid); - - // Assert - act.Should().NotThrow(); - } - - [Fact] - public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid() + public class BeEmpty { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => guid.Should().NotBe(sameGuid, "because we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw().WithMessage( - "Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} because we want to test the failure message."); + [Fact] + public void Should_succeed_when_asserting_empty_guid_is_empty() + { + // Arrange + Guid guid = Guid.Empty; + + // Act / Assert + guid.Should().BeEmpty(); + } + + [Fact] + public void Should_fail_when_asserting_non_empty_guid_is_empty() + { + // Arrange + var guid = new Guid("12345678-1234-1234-1234-123456789012"); + + // Act + Action act = () => guid.Should().BeEmpty("because we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw().WithMessage( + "Expected Guid to be empty because we want to test the failure message, but found {12345678-1234-1234-1234-123456789012}."); + } } - [Fact] - public void Should_throw_when_asserting_guid_does_not_equal_a_string_that_is_not_a_valid_guid() + public class NotBeEmpty { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => guid.Should().NotBe(string.Empty, "we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw() - .WithParameterName("unexpected"); + [Fact] + public void Should_succeed_when_asserting_non_empty_guid_is_not_empty() + { + // Arrange + var guid = new Guid("12345678-1234-1234-1234-123456789012"); + + // Act + Action act = () => guid.Should().NotBeEmpty(); + + // Assert + act.Should().NotThrow(); + } + + [Fact] + public void Should_fail_when_asserting_empty_guid_is_not_empty() + { + // Act + Action act = () => Guid.Empty.Should().NotBeEmpty("because we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw().WithMessage( + "Did not expect Guid.Empty to be empty because we want to test the failure message."); + } } - [Fact] - public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid_in_string_format() + public class Be { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => - guid.Should().NotBe("55555555-ffff-eeee-dddd-444444444444"); - - // Assert - act.Should().NotThrow(); + [Fact] + public void Should_succeed_when_asserting_guid_equals_the_same_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => guid.Should().Be(sameGuid); + + // Assert + act.Should().NotThrow(); + } + + [Fact] + public void Should_succeed_when_asserting_guid_equals_the_same_guid_in_string_format() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => guid.Should().Be("11111111-aaaa-bbbb-cccc-999999999999"); + + // Assert + act.Should().NotThrow(); + } + + [Fact] + public void Should_fail_when_asserting_guid_equals_a_different_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); + + // Act + Action act = () => guid.Should().Be(differentGuid, "because we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw().WithMessage( + "Expected Guid to be {55555555-ffff-eeee-dddd-444444444444} because we want to test the failure message, but found {11111111-aaaa-bbbb-cccc-999999999999}."); + } + + [Fact] + public void Should_throw_when_asserting_guid_equals_a_string_that_is_not_a_valid_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => guid.Should().Be(string.Empty, "we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw() + .WithParameterName("expected"); + } } - [Fact] - public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid_in_string_format() + public class NotBe { - // Arrange - var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); - - // Act - Action act = () => - guid.Should().NotBe("11111111-aaaa-bbbb-cccc-999999999999", "we want to test the failure {0}", "message"); - - // Assert - act.Should().Throw() - .WithMessage("Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} *failure message*."); + [Fact] + public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444"); + + // Act + Action act = () => + guid.Should().NotBe(differentGuid); + + // Assert + act.Should().NotThrow(); + } + + [Fact] + public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => guid.Should().NotBe(sameGuid, "because we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw().WithMessage( + "Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} because we want to test the failure message."); + } + + [Fact] + public void Should_throw_when_asserting_guid_does_not_equal_a_string_that_is_not_a_valid_guid() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => guid.Should().NotBe(string.Empty, "we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw() + .WithParameterName("unexpected"); + } + + [Fact] + public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid_in_string_format() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => + guid.Should().NotBe("55555555-ffff-eeee-dddd-444444444444"); + + // Assert + act.Should().NotThrow(); + } + + [Fact] + public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid_in_string_format() + { + // Arrange + var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999"); + + // Act + Action act = () => + guid.Should().NotBe("11111111-aaaa-bbbb-cccc-999999999999", "we want to test the failure {0}", "message"); + + // Assert + act.Should().Throw() + .WithMessage("Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} *failure message*."); + } } - #endregion - - [Fact] - public void Should_support_chaining_constraints_with_and() + public class ChainingConstraint { - // Arrange - Guid guid = Guid.NewGuid(); - - // Act / Assert - guid.Should() - .NotBeEmpty() - .And.Be(guid); + [Fact] + public void Should_support_chaining_constraints_with_and() + { + // Arrange + Guid guid = Guid.NewGuid(); + + // Act / Assert + guid.Should() + .NotBeEmpty() + .And.Be(guid); + } } } }