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
ContainEquivalentOf on a DBNull.Value behave differently between Debug and Release #1781
Comments
I can reproduce it, but frankly, I'm flabbergasted... |
So for me, this fails in release builds: var sut = new Foo();
sut.Parameters.Should().ContainEquivalentOf(new SqlParameter("@inSettings", "FOOBAR")); If you try to run it through the debugger, it succeeds. But this also succeeds. var sut = new Foo();
sut.Parameters.Should().ContainEquivalentOf(new SqlParameter("@inSettings", "FOOBAR"));
Console.WriteLine("blah"); I've also tried to add this particular test to the Fluent Assertions codebase, but then it always succeeds. So something fishy happens in release builds that affects the The workaround is to assert only the relevant properties have a certain value, like this. sut.Parameters.Should().ContainEquivalentOf(new
{
ParameterName = "@inSettings",
SqlValue = new SqlString("FOOBAR")
}); Either way, I have no clue where this is coming from and how to fix it. I have never seen this in the 20 years I've been coding in .NET. |
[TestMethod]
public void Fails()
{
var parameters = new[] { null, "B" };
parameters.Should().ContainEquivalentOf("B");
}
If I change |
Hmm. Did you try adding some lines? Or attaching the debugger in release mode? |
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MSTestV2.Specs
{
[TestClass]
public class FrameworkSpecs
{
[TestMethod]
public void Fails()
{
var parameters = new[] { null, "B" };
parameters.Should().ContainEquivalentOf("B");
}
}
} So multiple things are going on.
Perhaps we shouldn't use After a five minutes googling here's a method that is labelled with "is not perfectly reliable". private static bool IsDebug()
{
return Assembly
.GetEntryAssembly()
.GetCustomAttributes(typeof(DebuggableAttribute), false)
.Cast<DebuggableAttribute>()
.Any(e => e.IsJITOptimizerDisabled);
} |
Description
Different results are being reported when using ContainEquivalentOf against an instance of SqlParameter with a DBNull.Value. When I run this in Debug build the test passes, when I switch to Release build it fails.
Complete minimal example reproducing the issue
Please consider the following
Expected behavior:
Debug and Release build should either both pass or fail, I'm not sure if the intention is to fail this or if it should pass, it would be nice if it did pass since it is consistent with the way parameter verification is done elsewhere.
Actual behavior:
Debug build passes while Release build fails
Versions
Additional Information
Please note that if I switch the order of the assertions and run the if statement before the DBNull assertion this will pass in both builds.
The text was updated successfully, but these errors were encountered: