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 5) #1909

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
1,526 changes: 759 additions & 767 deletions Tests/FluentAssertions.Specs/Types/MethodBaseAssertionSpecs.cs

Large diffs are not rendered by default.

1,190 changes: 592 additions & 598 deletions Tests/FluentAssertions.Specs/Types/MethodInfoAssertionSpecs.cs

Large diffs are not rendered by default.

790 changes: 391 additions & 399 deletions Tests/FluentAssertions.Specs/Types/MethodInfoSelectorAssertionSpecs.cs

Large diffs are not rendered by default.

1,606 changes: 796 additions & 810 deletions Tests/FluentAssertions.Specs/Types/PropertyInfoAssertionSpecs.cs

Large diffs are not rendered by default.

535 changes: 264 additions & 271 deletions Tests/FluentAssertions.Specs/Types/PropertyInfoSelectorAssertionSpecs.cs

Large diffs are not rendered by default.

396 changes: 197 additions & 199 deletions Tests/FluentAssertions.Specs/Types/TypeAssertionSpecs.Be.cs

Large diffs are not rendered by default.

264 changes: 131 additions & 133 deletions Tests/FluentAssertions.Specs/Types/TypeAssertionSpecs.BeAbstract.cs
Expand Up @@ -9,143 +9,141 @@ namespace FluentAssertions.Specs.Types
/// </content>
public partial class TypeAssertionSpecs
{
#region BeAbstract

[Fact]
public void When_type_is_abstract_it_succeeds()
{
// Arrange / Act / Assert
typeof(Abstract).Should().BeAbstract();
}

[Theory]
[InlineData(typeof(ClassWithoutMembers), "Expected type *.ClassWithoutMembers to be abstract.")]
[InlineData(typeof(Sealed), "Expected type *.Sealed to be abstract.")]
[InlineData(typeof(Static), "Expected type *.Static to be abstract.")]
public void When_type_is_not_abstract_it_fails(Type type, string exceptionMessage)
public class BeAbstract
{
// Act
Action act = () => type.Should().BeAbstract();

// Assert
act.Should().Throw<XunitException>()
.WithMessage(exceptionMessage);
[Fact]
public void When_type_is_abstract_it_succeeds()
{
// Arrange / Act / Assert
typeof(Abstract).Should().BeAbstract();
}

[Theory]
[InlineData(typeof(ClassWithoutMembers), "Expected type *.ClassWithoutMembers to be abstract.")]
[InlineData(typeof(Sealed), "Expected type *.Sealed to be abstract.")]
[InlineData(typeof(Static), "Expected type *.Static to be abstract.")]
public void When_type_is_not_abstract_it_fails(Type type, string exceptionMessage)
{
// Act
Action act = () => type.Should().BeAbstract();

// Assert
act.Should().Throw<XunitException>()
.WithMessage(exceptionMessage);
}

[Fact]
public void When_type_is_not_abstract_it_fails_with_a_meaningful_message()
{
// Arrange
var type = typeof(ClassWithoutMembers);

// Act
Action act = () => type.Should().BeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.ClassWithoutMembers to be abstract *failure message*.");
}

[Theory]
[InlineData(typeof(IDummyInterface), "*.IDummyInterface must be a class.")]
[InlineData(typeof(Struct), "*.Struct must be a class.")]
[InlineData(typeof(ExampleDelegate), "*.ExampleDelegate must be a class.")]
public void When_type_is_not_valid_for_BeAbstract_it_throws_exception(Type type, string exceptionMessage)
{
// Act
Action act = () => type.Should().BeAbstract();

// Assert
act.Should().Throw<InvalidOperationException>()
.WithMessage(exceptionMessage);
}

[Fact]
public void When_subject_is_null_be_abstract_should_fail()
{
// Arrange
Type type = null;

// Act
Action act = () =>
type.Should().BeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type to be abstract *failure message*, but type is <null>.");
}
}

[Fact]
public void When_type_is_not_abstract_it_fails_with_a_meaningful_message()
{
// Arrange
var type = typeof(ClassWithoutMembers);

// Act
Action act = () => type.Should().BeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.ClassWithoutMembers to be abstract *failure message*.");
}

[Theory]
[InlineData(typeof(IDummyInterface), "*.IDummyInterface must be a class.")]
[InlineData(typeof(Struct), "*.Struct must be a class.")]
[InlineData(typeof(ExampleDelegate), "*.ExampleDelegate must be a class.")]
public void When_type_is_not_valid_for_BeAbstract_it_throws_exception(Type type, string exceptionMessage)
{
// Act
Action act = () => type.Should().BeAbstract();

// Assert
act.Should().Throw<InvalidOperationException>()
.WithMessage(exceptionMessage);
}

[Fact]
public void When_subject_is_null_be_abstract_should_fail()
{
// Arrange
Type type = null;

// Act
Action act = () =>
type.Should().BeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type to be abstract *failure message*, but type is <null>.");
}

#endregion

#region NotBeAbstract

[Theory]
[InlineData(typeof(ClassWithoutMembers))]
[InlineData(typeof(Sealed))]
[InlineData(typeof(Static))]
public void When_type_is_not_abstract_it_succeeds(Type type)
public class NotBeAbstract
{
// Arrange / Act / Assert
type.Should().NotBeAbstract();
[Theory]
[InlineData(typeof(ClassWithoutMembers))]
[InlineData(typeof(Sealed))]
[InlineData(typeof(Static))]
public void When_type_is_not_abstract_it_succeeds(Type type)
{
// Arrange / Act / Assert
type.Should().NotBeAbstract();
}

[Fact]
public void When_type_is_abstract_it_fails()
{
// Arrange
var type = typeof(Abstract);

// Act
Action act = () => type.Should().NotBeAbstract();

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.Abstract not to be abstract.");
}

[Fact]
public void When_type_is_abstract_it_fails_with_a_meaningful_message()
{
// Arrange
var type = typeof(Abstract);

// Act
Action act = () => type.Should().NotBeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.Abstract not to be abstract *failure message*.");
}

[Theory]
[InlineData(typeof(IDummyInterface), "*.IDummyInterface must be a class.")]
[InlineData(typeof(Struct), "*.Struct must be a class.")]
[InlineData(typeof(ExampleDelegate), "*.ExampleDelegate must be a class.")]
public void When_type_is_not_valid_for_NotBeAbstract_it_throws_exception(Type type, string exceptionMessage)
{
// Act
Action act = () => type.Should().NotBeAbstract();

// Assert
act.Should().Throw<InvalidOperationException>()
.WithMessage(exceptionMessage);
}

[Fact]
public void When_subject_is_null_not_be_abstract_should_fail()
{
// Arrange
Type type = null;

// Act
Action act = () =>
type.Should().NotBeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type not to be abstract *failure message*, but type is <null>.");
}
}

[Fact]
public void When_type_is_abstract_it_fails()
{
// Arrange
var type = typeof(Abstract);

// Act
Action act = () => type.Should().NotBeAbstract();

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.Abstract not to be abstract.");
}

[Fact]
public void When_type_is_abstract_it_fails_with_a_meaningful_message()
{
// Arrange
var type = typeof(Abstract);

// Act
Action act = () => type.Should().NotBeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type *.Abstract not to be abstract *failure message*.");
}

[Theory]
[InlineData(typeof(IDummyInterface), "*.IDummyInterface must be a class.")]
[InlineData(typeof(Struct), "*.Struct must be a class.")]
[InlineData(typeof(ExampleDelegate), "*.ExampleDelegate must be a class.")]
public void When_type_is_not_valid_for_NotBeAbstract_it_throws_exception(Type type, string exceptionMessage)
{
// Act
Action act = () => type.Should().NotBeAbstract();

// Assert
act.Should().Throw<InvalidOperationException>()
.WithMessage(exceptionMessage);
}

[Fact]
public void When_subject_is_null_not_be_abstract_should_fail()
{
// Arrange
Type type = null;

// Act
Action act = () =>
type.Should().NotBeAbstract("we want to test the failure {0}", "message");

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected type not to be abstract *failure message*, but type is <null>.");
}

#endregion
}
}