question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert("{","x") throws System.FormatException

See original GitHub issue

Describe the bug

A clear and concise description of what the bug is. Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert("{","x") throws System.FormatException instead of AssertFailedException.

To Reproduce

StringAssert.Contains(":-{","x");

See: https://github.com/nonZero/StringAssert_Demo

Exceptions (if any)

Test method threw exception System.FormatException, but exception Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException was expected. Exc...

Test method threw exception System.FormatException, but exception Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException was expected. Exception message: System.FormatException: Input string was not in a correct format.
   at System.Text.ValueStringBuilder.ThrowFormatError()
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at StringAssert_Demo.UnitTest1.Test_StringAssert_DoesNotContain_WithCurly() in .../StringAssert_Demo/StringAssertUnitTest.cs:line 26

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.102
 Commit:    49861cb924

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.102/

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  6.0.102 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Evangelinkcommented, Jun 9, 2022

Nice catch @KalleOlaviNiemitalo! I will do a follow-up fix.

1reaction
KalleOlaviNiemitalocommented, Jun 9, 2022

That is an incomplete fix; the parameters array might not be empty. Consider StringAssert.Contains("{", "x", "message {0}", "param");.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - StringAssert.Contains("{", needle) throws System. ...
I am using C# with .NET Core and Microsoft.VisualStudio.TestTools.UnitTesting . When calling: StringAssert.Contains(my_text, my_needle);.
Read more >
Assert.ThrowsException Method
Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws AssertFailedException...
Read more >
Unit Testing Exceptions in C#
In this article we've gone over how to unit test our code that will throw exceptions in a deterministic way. We can either...
Read more >
问答- 腾讯云开发者社区-腾讯云
Test method MyTest threw exception: System.FormatException: Input string was not in a correct format. at System.Text.ValueStringBuilder.
Read more >
Most Complete MSTest Unit Testing Framework Cheat Sheet
Most complete MSTest Unit Testing Framework cheat sheet. All you need to to know- the most basic operations to the most advanced configurations....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found