Search And Destroy

Look out honey, ’cause I’m using technology!

Archive for the ‘QuickGenerate’ Category

QuickGenerate 0.5 Coming Soon

Posted by kilfour on January 13, 2012

And I reckon I’m going to move to 1.0 pretty quickly right after that.

I promised that stability was going to be a feature, and actually I think it allready is.
I’ve been using QG extensively in production over the last year (there’s three or four projects I’m currently involved with that are using it, and I know of quite a few others).

Some ‘known issues’ have popped up though.
If you know you’re way around the lib there’s always a way to work around it, but recently I’ve been able to tear myself away from the Haskell compiler (and, I must admit, ‘Dwarf Fortress’) for long enough to start adressing these issues in a more fundamental manner.

One breaking change, unfortunately, was neccesary :

As of yesterday, relations are no longer bidirectional.
This means that if you define (f.i.) a OneToMany relation between a ‘Parent’ class and a ‘Child’ class, a Parent instance will no longer be automatically generated if you ask the generator for a Child instance.
There is now a ManyToOne method for just this case.

Believe me, It simplifies matters. Not only in quickgenerate, but for quickgenerate users (i.e. the client code) aswell.
All kinds of circular misery is now easily avoided.

As it really didn’t take me that long to update a production project with about two thousands tests, where about a quarter of them relied on this feature, and it actually simplified a lot of the code, I do believe it is worth the change.

I don’t think it will affect too many users as I’m probably the only one generating entire domains with just the one generator.
You can still do that if you want to though, you only need a couple of extra lines of code now.
You can combine the OneToMany with a similar ManyToOne, infinite recursion will be avoided, and you get the same behaviour that was there before, including all the problems that come with it.

So, once again, for those of you that are impacted, I’m sorry, but it needed to be done.

Also on the list for the 0.5 release.
– better support for inheritance.
– better support for the generation of constructor parameters and the ability to choose between different constructors.

Both features are now available through the ‘StartingValue’ method but a more intuitive API would be desirable.

There’s also a request for backing field generation, but I’m still hoping I can pull this off without taking a dependency hit to an external library.

In the meantime I’ve added a QuickGenerate.NHibernate.Testing.Sample project to the solution, as it seems that this is what most people are using it for these days.
Any issues that pop up while you’re trying to do this, just send me a failing test/use-case (and/or patch) and I’ll definitely look into it.
It’s still quite a simple example.
I’m using sqlite to demonstrate possibilities and, well, sqlite is … limited.
Feel (very) free to get involved in this part of the code ;-) .
And if anybody feels like contributing an E.F./AutoMapper/LLBGen/Ditto/whatever example, please do.
The AutoMapper example is on my todo list as you might have gathered from a previous post.

Specific Generator requests are also, as always, still welcome.

F.i. a ‘ShortGenerator’ was added recently and someone suggested a generator based on Regex expressions.
But seeing as how I hate RegEx with a passion (*), I’m going to leave that one as an exercise for some of the more masochistic devs out there ;-) .

(*) : have a look at Parsec for a decent, and really, only slightly more verbose, alternative.

On a sidenote :
– Once I’ve reached the QG 1.0 milestone, I promise I will give QuickDotNetCheck some much needed love.
I’d really like to clean up all of the QG tests and replace them with QDNC tests, but, … small steps, …

Posted in QuickGenerate | Leave a Comment »

On QuickGenerate Versioning

Posted by kilfour on July 26, 2011

QuickGenerate 0.5 aims at having a stable implementation.
QuickGenerate 1.0 aims at having a stable interface.

Feel free to get involved ;-) .

Posted in QuickGenerate, Rants | Leave a Comment »

QuickGenerate 0.4.6 Released

Posted by kilfour on June 28, 2011

Available here.

With :

GeneratorOptions.Range

public class CustomizeTypeLongRangeTests
{
    private readonly DomainGenerator domainGenerator =
        new DomainGenerator()
            .With<SomethingToGenerate>(g => g.Range(e => e.MyProperty, 3, 10));

    [Fact]
    public void GeneratorIsApplied()
    {
        10.Times(
            () =>
                {
                    var something = domainGenerator.One<SomethingToGenerate>();
                    Assert.True(something.MyProperty <= 10);
                    Assert.True(something.MyProperty >= 3);
                });
    }

    public class SomethingToGenerate
    {
        public long MyProperty { get; set; }
    }
}

Renamed DefaultValue to StartingValue
Sorry, breaking change this one.

First version of the EntityGenerator.
Which is sugar for the domain generator, eliminating the need for the generic type parameter.
It has most of the features the domain generator posesses.
F.i. :

public class IntRangeTests
{
    private readonly EntityGenerator<SomethingToGenerate> generator =
        new EntityGenerator<SomethingToGenerate>()
            .Range(e => e.MyProperty, 3, 10);

    [Fact]
    public void GeneratorIsApplied()
    {
        10.Times(
            () =>
                {
                    var something = generator.One();
                    Assert.True(something.MyProperty <= 10);
                    Assert.True(something.MyProperty >= 3);
                });
    }

    public class SomethingToGenerate
    {
        public int MyProperty { get; set; }
    }
}

Posted in QuickGenerate | Leave a Comment »

QuickGenerate 0.4.5 Released

Posted by kilfour on May 10, 2011

Again available here.

With amongst other things :

Automatic enum generation :

public class EnumTests
{
    [Fact]
    public void GeneratorIsApplied()
    {
        var generator = new DomainGenerator();
                
        var first = false;
        var second = false;
        var third = false;

        100.Times(
            () =>
                {
                    var something = generator.One<SomethingToGenerate>();
                    first = first || something.Property == AnEnum.First;
                    second = second || something.Property == AnEnum.Second;
                    third = third || something.Property == AnEnum.Third;
                });

        Assert.True(first);
        Assert.True(second);
        Assert.True(third);
    }

    public enum AnEnum
    {
        First,
        Second,
        Third,
    }

    public struct SomethingToGenerate
    {
        public AnEnum Property { get; set; }
    }
}

‘Polymorphic’ Ignore :

public class CustomizeTypeIgnoreInheritedTests
{
    [Fact]
    public void DerivedPropertyIsIgnored()
    {
        var something =
            new DomainGenerator()
                .With(42)
                .With<SomethingToGenerate>(opt => opt.Ignore(e => e.PropertyToBeIgnored))
                .One<SomethingDerivedToGenerate>();

        Assert.Equal(0, something.PropertyToBeIgnored);

    }

    public class SomethingToGenerate
    {
        public int PropertyToBeIgnored { get; set; }
    }

    public class SomethingDerivedToGenerate : SomethingToGenerate { }
}

Posted in QuickGenerate | Leave a Comment »

QuickGenerate 0.4.4 Released

Posted by kilfour on April 22, 2011

In a different place.

This one’s about moving to github mostly.

Squashed out a (small) bug here and there.
0.4.3. was already pretty stable.
The, much downloaded, 0.4.2. unfortunately contains a hell of a nasty bug :-( .

New features :
GeneratorOptions.Counter() : supplying starting value and step size :

public class CustomizeTypeLongCounterTests
{
    [Fact]
    public void SimpleAppend()
    {
        var domainGenerator =
            new DomainGenerator()
                .With<SomethingToGenerate>(g => g.Counter(e => e.MyProperty));

        Assert.Equal(1, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(2, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(3, domainGenerator.One<SomethingToGenerate>().MyProperty);
    }

    [Fact]
    public void SupplyingStartingValue()
    {
        var domainGenerator =
            new DomainGenerator()
                .With<SomethingToGenerate>(g => g.Counter(e => e.MyProperty, 5));

        Assert.Equal(5, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(6, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(7, domainGenerator.One<SomethingToGenerate>().MyProperty);
    }

    [Fact]
    public void SupplyingStartingValueAndStep()
    {
        var domainGenerator =
            new DomainGenerator()
                .With<SomethingToGenerate>(g => g.Counter(e => e.MyProperty, 5, 2));

        Assert.Equal(5, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(7, domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal(9, domainGenerator.One<SomethingToGenerate>().MyProperty);
    }

    public class SomethingToGenerate
    {
        public long MyProperty { get; set; }
    }
}

Components :
public class ComponentsTests
{
    private readonly DomainGenerator domainGenerator;

    public ComponentsTests()
    {
        domainGenerator =
            new DomainGenerator()
                .Component<SomeComponent>()
                .With(42);
    }

    [Fact]
    public void GeneratorIsApplied()
    {
        Assert.Equal(42, domainGenerator.One<SomethingToGenerate>().One.Answer);
        Assert.Equal(42, domainGenerator.One<SomethingToGenerate>().Two.Answer);
        Assert.Equal(42, domainGenerator.One<SomethingElseToGenerate>().Three.Answer);
    }

    public class SomethingToGenerate
    {
        public SomeComponent One { get; set; }
        public SomeComponent Two { get; set; }
    }

    public class SomethingElseToGenerate
    {
        public SomeComponent Three { get; set; }
    }

    public class SomeComponent
    {
        public int Answer { get; set; }
    }
}

As promised, the project on google code is up for deletion.

Posted in QuickGenerate | Leave a Comment »

QuickGenerate moved to GitHub

Posted by kilfour on April 20, 2011

Which is here.

A move not made, solely in order to be one of the cool kids on the block.

First of all, I’m currently using Agatha at work and it is hosted on GitHub so I really needed to know how to get the latest version ;-) .

But also, it is an invitation : “Go forth, and fork at will, … “.

Seeing as how I’ve never been in favour of looking back, the google code project will be deleted as soon as there’s a new release.

Posted in QuickGenerate | Leave a Comment »

QuickGenerate 0.4.3 Released

Posted by kilfour on March 25, 2011

This one’s about letting go mostly.

Changes :
– Removed redundant Entity(), Entities() DomainGenerator methods.
– Removed Generate.LikeSo().
– Removed the GeneratorRepository and everything related. I.e GeneratorFor, BaseGenerator, EmbeddedGenerator, … (*).
– Removed DomainGenerator.ManyToMany(…).
– Removed generatorOptions.Recurse(…).
– Removed EntityGenerator.
– Moved da furniture ’round.
– Added generatorOptions.Counter(entity => entity.Property) for both int’s and long’s with some overloads.

Please feel free to post any issues on google code or in the quicknet mailing list.

The latter excepts suggestions, ideas, patches, … and all, … aswell ;-) .

(*) : GeneratorRepository, go get your gun. Anything you can do the DomainGenerator can do better.

Posted in QuickGenerate | Leave a Comment »

QuickGenerate 0.4.2 Released

Posted by kilfour on March 20, 2011

– Ironed out some bugs.

– Added some more sugar, f.i. Maybe.Do :

new DomainGenerator()
     .ForEach<Employee>(employee => Maybe.Do(() => managers.PickOne().AddSubordinate(employee)))
     .Many<Employee>(20)

– Shorthand for some of the more common generator usage. F.i., this :

generator
    .With<Address>(options => options.For(address => address.Street, new StringGenerator(1, 100)))
    .With<Address>(options => options.For(address => address.City, new StringGenerator(1, 100)))
    .With<Address>(options => options.For(address => address.Country, new StringGenerator(1, 100)));

Can now also be written as :
generator
    .With<Address>(options => options.Length(address => address.Street, 1, 100))
    .With<Address>(options => options.Length(address => address.City, 1, 100))
    .With<Address>(options => options.Length(address => address.Country,1, 100));

- Took out the ‘Automatic’ relations generation, as it was quite unpredictable.

Find it here.

Posted in QuickGenerate | Leave a Comment »

My Favourite QuickGenerate Feature

Posted by kilfour on February 26, 2011

public class CustomizeTypePluggableFunctionsTests
{
    private readonly DomainGenerator domainGenerator;

    public CustomizeTypePluggableFunctionsTests()
    {
        domainGenerator =
            new DomainGenerator()
                .Entity<SomethingToGenerate>()
                .With<SomethingToGenerate>(
                    g => g.For(
                        e => e.MyProperty,
                        0, val => ++val,
                        val => string.Format("SomeString{0}", val)));
    }

    [Fact]
    public void Works()
    {
        Assert.Equal("SomeString1", domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal("SomeString2", domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal("SomeString3", domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal("SomeString4", domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal("SomeString5", domainGenerator.One<SomethingToGenerate>().MyProperty);
        Assert.Equal("SomeString6", domainGenerator.One<SomethingToGenerate>().MyProperty);
    }

    public class SomethingToGenerate
    {
        public string MyProperty { get; set; }
    }
}

A shorthand for this particular, but very common, usage of the PluggableFunction feature is on it’s way ;-) .

Posted in My Favourite, QuickGenerate | Leave a Comment »

QuickGenerate 0.4.1 Released

Posted by kilfour on February 26, 2011

As always, find it here.

This one is pretty much quickgenerate 0.4 plus the first draft of the DomainGenerator.

Even though the DomainGenerator was aimed at removing duplicate code, it does not deliver on that promise on all occasions.

It is however, tested far more extensively than the (quicknet legacy) GeneratorRepository and as a consequence, it is the prefered way to go.

I know I stated in my previous post that the GeneratorRepository was more stable, and it probably is, through sheer usage, but the lack of tests, make it so, that any change to it would degrade that stability by a serious amount.

Changes to the DomainGenerator should be, and already have proven to be, far less painfull.

The interface will probably change though, hence the ‘..1′.

Posted in QuickGenerate | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.