Skip to content

Commit

Permalink
Avoid quoting newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed May 9, 2023
1 parent 664b9a5 commit 61a6c4d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 49 deletions.
12 changes: 6 additions & 6 deletions Src/FluentAssertions/ObjectAssertionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public static class ObjectAssertionsExtensions
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:{1}{1}{2}.",
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:"
+ Environment.NewLine + Environment.NewLine + "{1}.",
assertions.Subject,
Environment.NewLine,
exc.Message);
}

Expand Down Expand Up @@ -133,9 +133,9 @@ public static class ObjectAssertionsExtensions
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:{1}{1}{2}.",
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:"
+ Environment.NewLine + Environment.NewLine + "{1}.",
assertions.Subject,
Environment.NewLine,
exc.Message);
}

Expand Down Expand Up @@ -213,9 +213,9 @@ private static object CreateCloneUsingDataContractSerializer(object subject)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:{1}{1}{2}.",
.FailWith("Expected {0} to be serializable{reason}, but serialization failed with:"
+ Environment.NewLine + Environment.NewLine + "{1}.",
assertions.Subject,
Environment.NewLine,
exc.Message);
}

Expand Down
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Specialized/AsyncFunctionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ public AsyncFunctionAssertions(Func<TTask> subject, IExtractExceptions extractor
.FailWith("but no exception was thrown.")
.Then
.ForCondition(expectedExceptions.Any())
.FailWith("but found <{0}>: {1}{2}.",
.FailWith("but found <{0}>:" + Environment.NewLine + "{1}.",
exception?.GetType(),
Environment.NewLine,
exception)
.Then
.ClearExpectation();
Expand Down
3 changes: 1 addition & 2 deletions Src/FluentAssertions/Specialized/DelegateAssertionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ private protected DelegateAssertionsBase(TDelegate @delegate, IExtractExceptions
.FailWith("but no exception was thrown.")
.Then
.ForCondition(expectedExceptions.Any())
.FailWith("but found <{0}>: {1}{2}.",
.FailWith("but found <{0}>:" + Environment.NewLine + "{1}.",
exception?.GetType(),
Environment.NewLine,
exception)
.Then
.ClearExpectation();
Expand Down
5 changes: 3 additions & 2 deletions Src/FluentAssertions/Specialized/ExceptionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ public ExceptionAssertions(IEnumerable<TException> exceptions)
Execute.Assertion
.ForCondition(condition(SingleSubject))
.BecauseOf(because, becauseArgs)
.FailWith("Expected exception where {0}{reason}, but the condition was not met by:{1}{1}{2}.",
exceptionExpression, Environment.NewLine, Subject);
.FailWith("Expected exception where {0}{reason}, but the condition was not met by:"
+ Environment.NewLine + Environment.NewLine + "{1}.",
exceptionExpression, Subject);

return this;
}
Expand Down
20 changes: 12 additions & 8 deletions Src/FluentAssertions/Streams/StreamAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ public AndConstraint<TAssertions> HavePosition(long expected, string because = "
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected the position of {context:stream} to be {0}{reason}, but it failed with:{1}{2}",
expected, Environment.NewLine, exception.Message);
.FailWith("Expected the position of {context:stream} to be {0}{reason}, but it failed with:"
+ Environment.NewLine + "{1}",
expected, exception.Message);

return new AndConstraint<TAssertions>((TAssertions)this);
}
Expand Down Expand Up @@ -280,8 +281,9 @@ public AndConstraint<TAssertions> NotHavePosition(long unexpected, string becaus
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected the position of {context:stream} not to be {0}{reason}, but it failed with:{1}{2}",
unexpected, Environment.NewLine, exception.Message);
.FailWith("Expected the position of {context:stream} not to be {0}{reason}, but it failed with:"
+ Environment.NewLine + "{1}",
unexpected, exception.Message);

return new AndConstraint<TAssertions>((TAssertions)this);
}
Expand Down Expand Up @@ -328,8 +330,9 @@ public AndConstraint<TAssertions> HaveLength(long expected, string because = "",
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected the length of {context:stream} to be {0}{reason}, but it failed with:{1}{2}",
expected, Environment.NewLine, exception.Message);
.FailWith("Expected the length of {context:stream} to be {0}{reason}, but it failed with:"
+ Environment.NewLine + "{1}",
expected, exception.Message);

return new AndConstraint<TAssertions>((TAssertions)this);
}
Expand Down Expand Up @@ -376,8 +379,9 @@ public AndConstraint<TAssertions> NotHaveLength(long unexpected, string because
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected the length of {context:stream} not to be {0}{reason}, but it failed with:{1}{2}",
unexpected, Environment.NewLine, exception.Message);
.FailWith("Expected the length of {context:stream} not to be {0}{reason}, but it failed with:"
+ Environment.NewLine + "{1}",
unexpected, exception.Message);

return new AndConstraint<TAssertions>((TAssertions)this);
}
Expand Down
40 changes: 14 additions & 26 deletions Src/FluentAssertions/Types/TypeSelectorAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ public AndConstraint<TypeSelectorAssertions> BeDecoratedWith<TAttribute>(string
.ForCondition(!typesWithoutAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be decorated with {0}{reason}," +
" but the attribute was not found on the following types:{1}{2}.",
" but the attribute was not found on the following types:" + Environment.NewLine + "{1}.",
typeof(TAttribute),
Environment.NewLine,
GetDescriptionsFor(typesWithoutAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -92,10 +91,9 @@ public AndConstraint<TypeSelectorAssertions> BeDecoratedWith<TAttribute>(string
.ForCondition(!typesWithoutMatchingAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be decorated with {0} that matches {1}{reason}," +
" but no matching attribute was found on the following types:{2}{3}.",
" but no matching attribute was found on the following types:" + Environment.NewLine + "{2}.",
typeof(TAttribute),
isMatchingAttributePredicate,
Environment.NewLine,
GetDescriptionsFor(typesWithoutMatchingAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -123,9 +121,8 @@ public AndConstraint<TypeSelectorAssertions> BeDecoratedWith<TAttribute>(string
.ForCondition(!typesWithoutAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be decorated with or inherit {0}{reason}," +
" but the attribute was not found on the following types:{1}{2}.",
" but the attribute was not found on the following types:" + Environment.NewLine + "{1}.",
typeof(TAttribute),
Environment.NewLine,
GetDescriptionsFor(typesWithoutAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -160,10 +157,9 @@ public AndConstraint<TypeSelectorAssertions> BeDecoratedWith<TAttribute>(string
.ForCondition(!typesWithoutMatchingAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be decorated with or inherit {0} that matches {1}{reason}," +
" but no matching attribute was found on the following types:{2}{3}.",
" but no matching attribute was found on the following types:" + Environment.NewLine + "{2}.",
typeof(TAttribute),
isMatchingAttributePredicate,
Environment.NewLine,
GetDescriptionsFor(typesWithoutMatchingAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand All @@ -190,9 +186,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeDecoratedWith<TAttribute>(stri
.ForCondition(!typesWithAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to not be decorated with {0}{reason}," +
" but the attribute was found on the following types:{1}{2}.",
" but the attribute was found on the following types:" + Environment.NewLine + "{1}.",
typeof(TAttribute),
Environment.NewLine,
GetDescriptionsFor(typesWithAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -227,10 +222,9 @@ public AndConstraint<TypeSelectorAssertions> NotBeDecoratedWith<TAttribute>(stri
.ForCondition(!typesWithMatchingAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to not be decorated with {0} that matches {1}{reason}," +
" but a matching attribute was found on the following types:{2}{3}.",
" but a matching attribute was found on the following types:" + Environment.NewLine + "{2}.",
typeof(TAttribute),
isMatchingAttributePredicate,
Environment.NewLine,
GetDescriptionsFor(typesWithMatchingAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -258,9 +252,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeDecoratedWith<TAttribute>(stri
.ForCondition(!typesWithAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to not be decorated with or inherit {0}{reason}," +
" but the attribute was found on the following types:{1}{2}.",
" but the attribute was found on the following types:" + Environment.NewLine + "{1}.",
typeof(TAttribute),
Environment.NewLine,
GetDescriptionsFor(typesWithAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -295,10 +288,9 @@ public AndConstraint<TypeSelectorAssertions> NotBeDecoratedWith<TAttribute>(stri
.ForCondition(!typesWithMatchingAttribute.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to not be decorated with or inherit {0} that matches {1}{reason}," +
" but a matching attribute was found on the following types:{2}{3}.",
" but a matching attribute was found on the following types:" + Environment.NewLine + "{2}.",
typeof(TAttribute),
isMatchingAttributePredicate,
Environment.NewLine,
GetDescriptionsFor(typesWithMatchingAttribute));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand All @@ -320,7 +312,7 @@ public AndConstraint<TypeSelectorAssertions> BeSealed(string because = "", param

Execute.Assertion.ForCondition(!notSealedTypes.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be sealed{reason}, but the following types are not:{0}{1}.", Environment.NewLine,
.FailWith("Expected all types to be sealed{reason}, but the following types are not:" + Environment.NewLine + "{0}.",
GetDescriptionsFor(notSealedTypes));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand All @@ -342,7 +334,7 @@ public AndConstraint<TypeSelectorAssertions> NotBeSealed(string because = "", pa

Execute.Assertion.ForCondition(!sealedTypes.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types not to be sealed{reason}, but the following types are:{0}{1}.", Environment.NewLine,
.FailWith("Expected all types not to be sealed{reason}, but the following types are:" + Environment.NewLine + "{0}.",
GetDescriptionsFor(sealedTypes));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -372,9 +364,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeSealed(string because = "", pa
.ForCondition(!typesNotInNamespace.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected all types to be in namespace {0}{reason}," +
" but the following types are in a different namespace:{1}{2}.",
" but the following types are in a different namespace:" + Environment.NewLine + "{1}.",
@namespace,
Environment.NewLine,
GetDescriptionsFor(typesNotInNamespace));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -404,9 +395,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeSealed(string because = "", pa
.ForCondition(!typesInNamespace.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected no types to be in namespace {0}{reason}," +
" but the following types are in the namespace:{1}{2}.",
" but the following types are in the namespace:" + Environment.NewLine + "{1}.",
@namespace,
Environment.NewLine,
GetDescriptionsFor(typesInNamespace));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -436,9 +426,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeSealed(string because = "", pa
.ForCondition(!typesNotUnderNamespace.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected the namespaces of all types to start with {0}{reason}," +
" but the namespaces of the following types do not start with it:{1}{2}.",
" but the namespaces of the following types do not start with it:" + Environment.NewLine + "{1}.",
@namespace,
Environment.NewLine,
GetDescriptionsFor(typesNotUnderNamespace));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down Expand Up @@ -469,9 +458,8 @@ public AndConstraint<TypeSelectorAssertions> NotBeSealed(string because = "", pa
.ForCondition(!typesUnderNamespace.Any())
.BecauseOf(because, becauseArgs)
.FailWith("Expected the namespaces of all types to not start with {0}{reason}," +
" but the namespaces of the following types start with it:{1}{2}.",
" but the namespaces of the following types start with it:" + Environment.NewLine + "{1}.",
@namespace,
Environment.NewLine,
GetDescriptionsFor(typesUnderNamespace));

return new AndConstraint<TypeSelectorAssertions>(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task When_task_throws_unexpected_exception_it_should_fail()
// Assert
await action.Should().ThrowAsync<XunitException>().WithMessage(
"Expected a <System.InvalidOperationException> to be thrown,"
+ " but found <System.NotSupportedException>: *foo*");
+ " but found <System.NotSupportedException>:*foo*");
}

[Fact]
Expand Down Expand Up @@ -440,7 +440,7 @@ public async Task When_task_throws_unexpected_exception_it_should_fail()
// Assert
await action.Should().ThrowAsync<XunitException>().WithMessage(
"Expected a <System.InvalidOperationException> to be thrown within 100ms,"
+ " but found <System.NotSupportedException>: *foo*");
+ " but found <System.NotSupportedException>:*foo*");
}

[Fact]
Expand All @@ -462,7 +462,7 @@ public async Task When_task_throws_unexpected_exception_asynchronous_it_should_f
// Assert
await action.Should().ThrowAsync<XunitException>().WithMessage(
"Expected a <System.InvalidOperationException> to be thrown within 1s,"
+ " but found <System.NotSupportedException>: *foo*");
+ " but found <System.NotSupportedException>:*foo*");
}
}

Expand Down

0 comments on commit 61a6c4d

Please sign in to comment.