I'm trying to understand how to use the CreateProxy()
feature of Likeness<T>()
using two instances of a simple class.
public class Band
{
public string Strings { get; set; }
public string Brass { get; set; }
}
With the following test, I use a Fixture
to Create<T>
a Band
instance with values for the two string properties.
[Fact]
public void Equality_Behaves_As_Expected()
{
// arrange
var fixture = new Fixture();
fixture.Customize(new AutoMoqCustomization());
var original = fixture.Create<Band>();
// Brass something like --> "Brass65756b89-d9f3-42f8-88fc-ab6de5ae65cd"
// Strings something like --> "Strings7439fa1b-014d-4544-8428-baea66858940"
// act
var dupe = new Band {Brass = original.Brass,
Strings = original.Strings};
// Brass same as original's like --> "Brass65756b89-d9f3-42f8-88fc-ab6de5ae65cd"
// Strings same as original's like --> "Strings7439fa1b-014d-4544-8428-baea66858940"
I've tried many different assertions, but the crux of the matter seems to be that the CreateProxy
method is not populating the properties of Band
, so that even when I try to compare two instances of Band
with the same property values, the instance from the CreateProxy
method always has null values.
// assert
var likeness = dupe.AsSource().OfLikeness<Band>()
.Without(x => x.Brass).CreateProxy();
// Brass & String properties are null using dupe as source of likeness (!)
//var likeness = original.AsSource().OfLikeness<Band>()
// .Without(x => x.Brass).CreateProxy();
// Brass & String properties are null using original as source of likeness (!)
//Assert.True(likeness.Equals(original)); // Fails
//Assert.True(original.Equals(likeness)); // Fails
// below are using FluentAssertions assembly
//likeness.Should().Be(original); // Fails (null properties)
//original.Should().Be(likeness); // Fails (null properties)
//likeness.ShouldBeEquivalentTo(original); // Fails (null properties)
//original.ShouldBeEquivalentTo(likeness); // Fails (null properties)
}
I've gotta be doing something wrong, but I've read everything I can find on the Ploeh blog and SO, and can't find an example suitably simple enough to compare to what I'm doing. Any ideas?
Assert.True(likeness.Equals(original));
fail? The OP states that this line of code also fails. Shouldn't that pass? – Thenceforward