Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure assertions with nested classes instead of regions (Part 2) #1900

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
371 changes: 189 additions & 182 deletions Tests/FluentAssertions.Specs/Primitives/GuidAssertionSpecs.cs
Expand Up @@ -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<XunitException>().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<XunitException>().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<XunitException>().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<ArgumentException>()
.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<XunitException>().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<XunitException>().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<ArgumentException>()
.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<XunitException>().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<XunitException>().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<ArgumentException>()
.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<XunitException>()
.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<XunitException>().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<ArgumentException>()
.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<XunitException>()
.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);
}
}
}
}