This project is read-only.
3
Vote

Default conventions are overiding object properties set by a Datasource

description

This issue is related to last commit (f8e6ff56736c). I hope that the posted unit test is self-explanatory

[TestFixture]
public class WhenDefaultConventionsAreConfiguredAndAnObjectTypeIsConfiguredToBeConstructedWithADataSource
{
    private IGenerationSession session;

    [SetUp]
    public void Setup()
    {
        session = AutoPocoContainer.Configure(x =>
        {
            x.Conventions(c => c.UseDefaultConventions());
            x.Include<SimpleObject>().ConstructWith<SimpleObjectSource>();
        })
        .CreateSession();
    }

    [Test]
    public void ShouldRetrieveAObjectThatHasBeenSetupByTheSource()
    {
        SimpleObject simpleObject = session.Single<SimpleObject>().Get();
        Assert.That(simpleObject.SimpleProperty, Is.EqualTo("Set by source"));
    }

    [Test]
    public void ShouldNotApplyTheDefaultStrinConventionOnStringProperties()
    {
        SimpleObject simpleObject = session.Single<SimpleObject>().Get();
        Assert.That(simpleObject.SimpleProperty, Is.Not.EqualTo(string.Empty));
    }
}

public class SimpleObjectSource : IDatasource<SimpleObject>
{
    public object Next(IGenerationContext context)
    {
        return new SimpleObject {SimpleProperty = "Set by source"};
    }
}

public class SimpleObject
{
    public string SimpleProperty { get; set; }
}

comments

robashton wrote Feb 3, 2011 at 1:29 PM

Oh hell - okay, I'll sort this out :-)

robashton wrote Feb 3, 2011 at 4:01 PM

Okay, after looking into this I think it's a matter for discussion as I don't know what the required fix might be.

In this situation you have a factory creating the object, does this mean you want all post-creation actions discarded because it is assumed the factory has created it in its final state? Some other people might disagree with that and they might want the conventions applied as well.

Thoughts on the best way to achieve a satisfactory conclusion?

jenrom wrote Feb 6, 2011 at 7:26 PM

I totaly agree that this is a topic that needs to be discussed.

I think it would be better to provide an option in the conventions API that would define if a given property/field should be overriden by the convention. I've created a fork with a simple(hacky) solution related to this issue - http://autopoco.codeplex.com/SourceControl/network/Forks/jenrom/ConfiguringOverridesInConventions/changeset/changes/415ba3fde0be, maybe you will find it helpful

mickdelaney wrote Aug 9, 2011 at 3:55 PM

whats the story with this???

is there a known way to always use a custom convention over a default one?