Escape brackets in execution time failures by Briaoeuidhtns · Pull Request #1994 · fluentassertions/fluentassertions · GitHub
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Src/FluentAssertions/Specialized/ExecutionTimeAssertions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions.Extensions;
Expand Down Expand Up @@ -85,6 +86,20 @@ public void When_action_runs_indefinitely_it_should_be_stopped_and_throw_if_ther
act.Should().Throw<XunitException>().WithMessage(
"*action should be less than or equal to 100ms, but it required more than*");
}

[Fact]
public void Actions_with_brackets_fail_with_correctly_formatted_message()
{
// Arrange
var subject = new List<object>();

// Act
Action act = () => subject.ExecutionTimeOf(s => s.AddRange(new object[] { })).Should().BeLessOrEqualTo(1.Nanoseconds());

// Assert
act.Should().ThrowExactly<XunitException>()
.Which.Message.Should().Contain("{}").And.NotContain("{0}");
}
}

public class BeLessThan
Expand Down Expand Up @@ -189,6 +204,20 @@ public void When_action_runs_indefinitely_it_should_be_stopped_and_throw_if_ther
act.Should().Throw<XunitException>().WithMessage(
"*action should be less than 100ms, but it required more than*");
}

[Fact]
public void Actions_with_brackets_fail_with_correctly_formatted_message()
{
// Arrange
var subject = new List<object>();

// Act
Action act = () => subject.ExecutionTimeOf(s => s.AddRange(new object[] { })).Should().BeLessThan(1.Nanoseconds());

// Assert
act.Should().ThrowExactly<XunitException>()
.Which.Message.Should().Contain("{}").And.NotContain("{0}");
}
}

public class BeGreaterThanOrEqualTo
Expand Down Expand Up @@ -265,6 +294,20 @@ public void When_action_runs_indefinitely_it_should_be_stopped_and_not_throw_if_
// Assert
act.Should().NotThrow<XunitException>();
}

[Fact]
public void Actions_with_brackets_fail_with_correctly_formatted_message()
{
// Arrange
var subject = new List<object>();

// Act
Action act = () => subject.ExecutionTimeOf(s => s.AddRange(new object[] { })).Should().BeGreaterThanOrEqualTo(1.Days());

// Assert
act.Should().ThrowExactly<XunitException>()
.Which.Message.Should().Contain("{}").And.NotContain("{0}");
}
}

public class BeGreaterThan
Expand Down Expand Up @@ -341,6 +384,20 @@ public void When_action_runs_indefinitely_it_should_be_stopped_and_not_throw_if_
// Assert
act.Should().NotThrow<XunitException>();
}

[Fact]
public void Actions_with_brackets_fail_with_correctly_formatted_message()
{
// Arrange
var subject = new List<object>();

// Act
Action act = () => subject.ExecutionTimeOf(s => s.AddRange(new object[] { })).Should().BeGreaterThan(1.Days());

// Assert
act.Should().ThrowExactly<XunitException>()
.Which.Message.Should().Contain("{}").And.NotContain("{0}");
}
}

public class BeCloseTo
Expand Down Expand Up @@ -437,6 +494,21 @@ public void When_action_runs_indefinitely_it_should_be_stopped_and_throw_if_ther
act.Should().Throw<XunitException>().WithMessage(
"*action should be within 50ms from 100ms, but it required*");
}

[Fact]
public void Actions_with_brackets_fail_with_correctly_formatted_message()
{
// Arrange
var subject = new List<object>();

// Act
Action act = () => subject.ExecutionTimeOf(s => s.AddRange(new object[] { }))
.Should().BeCloseTo(1.Days(), 50.Milliseconds());

// Assert
act.Should().ThrowExactly<XunitException>()
.Which.Message.Should().Contain("{}").And.NotContain("{0}");
}
}

public class ExecutingTime
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md