Question

I'm porting my tests to AutoFixture 2.0, and I've run in to some strange behavior that I can neither explain nor fix. This simple test is failing for me:

var autoFixtures = new Fixture();
var file = autoFixtures.Build<File>()
                       .With(f => f.Name, "bleh.txt")
                       .CreateAnonymous();

Assert.That(file.Name, Is.EqualTo("bleh.txt"));  // Fail?!

The test succeeds if I change Name to another property of File, which leads me to think that I have some sort of customization present for Name that wasn't working when I was using AutoFixture 1.0. I've scoured my code, though, and I can't find anything like that.

Enabling tracing doesn't seem to help much.

autoFixtures.Behaviors.Add(new TracingBehavior());

displays, among other stuff:

Requested: System.String Name
    Requested: Ploeh.AutoFixture.Kernel.SeededRequest
    Created: Ploeh.AutoFixture.Kernel.NoSpecimen
  Requested: Ploeh.AutoFixture.Kernel.SeededRequest
    Requested: System.String
    Created: Ploeh.AutoFixture.Kernel.NoSpecimen
    Requested: System.String
    Created: 8a022fda-fa4e-49b7-b0c2-285fef765386
  Created: Name8a022fda-fa4e-49b7-b0c2-285fef765386
Created: Name8a022fda-fa4e-49b7-b0c2-285fef765386

FWIW, Name is declared as a virtual property of File's base class, and then overridden in File as such:

public abstract class Item
{
    public virtual string Name { get; set; }
    ...
}

public class File : Item
{
    public override string Name { get; set; }
    ...
}

If anyone has any ideas on something I might try, or somewhere I might have inadvertently customized the behavior of the Name property, I would be most appreciative!

Was it helpful?

Solution

You just found a bug in AutoFixture 2.0. I have now resolved it and pushed the changes to the repository (changeset 3efe812aecd1), so if you download the latest source and compile it, it should work.

In case you are interested, it was related to a virtual property being overridden by a child class - apparently not something I do very often.

Sorry about the bug. Please let me know if the issue hasn't been resolved, or if you have other questions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top