Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heemskerkerik/ab0531f45bf61f97fd14 to your computer and use it in GitHub Desktop.
Save heemskerkerik/ab0531f45bf61f97fd14 to your computer and use it in GitHub Desktop.
Failing test for FluentAssertions (tested with 4.1.1, but seen in earlier versions as well). When explicitly using Including(), another property with a similar name is also matched, and the match subsequently fails.
using FluentAssertions;
using Xunit;
// ReSharper disable InconsistentNaming
namespace FluentAssertionsBugProof
{
public class ShouldBeEquivalentToTest
{
[Fact]
public void ShouldBeEquivalent_NoInheritance_SimilarPropertyNames_DoesNotThrow()
{
var x = new TestNoInheritance
{
DeclaredType = LocalOtherType.NonDefault,
Type = LocalType.NonDefault,
};
x.ShouldBeEquivalentTo(new TestNoInheritance
{
DeclaredType = LocalOtherType.NonDefault,
},
config => config.Including(o => o.DeclaredType));
}
[Fact]
public void ShouldBeEquivalent_NoInheritance_DifferentPropertyNames_DoesNotThrow()
{
var x = new TestNoInheritanceDifferentNames
{
DeclaredType = LocalOtherType.NonDefault,
InheritedType = LocalType.NonDefault,
};
x.ShouldBeEquivalentTo(new TestNoInheritanceDifferentNames
{
DeclaredType = LocalOtherType.NonDefault,
},
config => config.Including(o => o.DeclaredType));
}
}
public class TestNoInheritance
{
public LocalType Type { get; set; }
public LocalOtherType DeclaredType { get; set; }
}
public class TestNoInheritanceDifferentNames
{
public LocalType InheritedType { get; set; }
public LocalOtherType DeclaredType { get; set; }
}
public enum LocalOtherType: byte
{
Default,
NonDefault,
}
public enum LocalType: byte
{
Default,
NonDefault,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment