Skip to content

Commit

Permalink
Merge pull request #1909 from IT-VBFK/structure-assertions-with-neste…
Browse files Browse the repository at this point in the history
…d-classes-instead-of-regions-5

Structure assertions with nested classes instead of regions (Part 5)
  • Loading branch information
dennisdoomen committed Apr 24, 2022
2 parents 68f41b9 + d96b587 commit fb4edca
Show file tree
Hide file tree
Showing 30 changed files with 11,205 additions and 11,294 deletions.
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
}
}

0 comments on commit fb4edca

Please sign in to comment.