Search And Destroy

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

Go Check

Posted by kilfour on November 26, 2009

Not being very happy with the way the regular dot net events tightly couples sender and receiver, a while ago I went looking for a better solution. Currently Im using a slightly modified version of this implementation of the event aggregation pattern.

So how to test EventAggregator usage in an app ?

You could ofcourse mock the EventAggregator and set an expectation on the publish method for the specific event that you …erm… expect to be published.
Now I’m currently working on an MVP app where a lot of the architecture is enforced through generic interface definitions. There’s an IView<TDto>, an IService<TDto> and an IPresenter<TView, TService, TDto>, TDto is ofcourse required to be the same type. This means that I usually can create a mocked view, a mocked service, and a real presenter in the tests setup, and that setup doesn’t have to change for any of the tests related to that part of the gui.
Mocking the EventAggregator would mean that for some tests I would need to have a real EventAggregator (f.i. when I’m testing what Events the Presenter handles), and at at other times I need to plug in a mock to be able to use AssertWasCalled (I’m using Rhino.Mocks right now).

Enter the IEavesDropper interface.

Eavesdropping is the act of secretly listening to the private conversation of others without their consent, as defined by Black’s Law Dictionary.

This interface is just an aggregate interface for all the different IListener interfaces that exist in the app. Subscribing this interface to the EventAggregator in test setup allows you to set expectations on it, and thus imo, simplifying test setup.
Setup :

IEavesDropper eavesDropper = MockRepository.GenerateMock<IEavesDropper>();
aggregator.Subscribe(eavesDropper);

Expectation :

eavesDropper
    .Expect(
    e => e.Handle(
             Arg<SomeKindOfEven>
                 .Matches(args => args.Parameter == localParameter)));

Now I’m one of those people that still uses strict mocks and in this case, with events flying all over the place, potentially causing circular calls, after a while I thought it would be usefull to change the IEavesdropper Mock to a strict one. Sometimes an Event fires another event, to avoid the duplicate code related to testing this, i.e. having to set an expectation on the IEavesdropper for the event under test instead of just setting expectations on the ones I’m expecting to be fired by the event under test, I coded the following helper :

public class DDR : IDisposable
{
    public readonly IEavesDropper Stasi;
    public readonly IEventAggregator Aggregator;
    public DDR()
    {
        Aggregator = new EventAggregator();
        Stasi = MockRepository.GenerateStrictMock<IEavesDropper>();
        Aggregator.Subscribe(Stasi);
    }

    protected void Propaganda<TEvent>(TEvent @event) where TEvent : Event
    {
        var typedReference = (IListener<TEvent>)Stasi;
        typedReference.Expect(e => e.Handle(@event));
        Aggregator.Publish(@event);
    }

    public void Dispose()
    {
        Stasi.VerifyAllExpectations();
    }
}

Using xunit’s IUseFixture feature this leads to the following type of test :

[Fact]
public void OnSomeEventThrownByView()
{
    DDR.Stasi.Expect(s => s.Handle(Arg<SomeAggregatorEvent>.Is.Anything));
    View.Raise(v => v.OnSomeEvent += null, null, null);
}

or :

[Fact]
public void SomethingEventHandledByPresenter()
{
    DDR.Stasi.Expect(s => s.Handle(Arg<SomethingsFinshedEvent>.Is.Anything));
    DDR.Propaganda(new StartSomethingEvent());
}

Any event published without authorization will be caught by the Stasi and shot on sight.

Posted in C# Musings | Leave a Comment »

Abusing Using

Posted by kilfour on November 26, 2009

As remarked in one of the comments, the IDisposable interface is dotnet’s way of telling you that a class is probably doing something to memory, or is using unmanaged resources and well, … it needs disposing.

The C# team has supplied us with the ‘using’ keyword, in order to keep things more readable. ‘Using’ is much more elegant than a try/catch/finally construct.

The combination of IDisposable/using can, as was also remarked upon in the comments, be put to alternate use. A feature I would advise to use with care, but still, usefull in some cases.

Consider a class that can traverse an xml document using XPath expressions. F.i. :

navigator.Navigate(&amp;quot;//Node&amp;quot;); //Node
navigator.Navigate(&amp;quot;SomeChild/SomeGrandChild&amp;quot;);
// Do something with Node/SomeChildNode/SomeGrandChild
navigator.MoveBack(); //Node
navigator.Navigate(&amp;quot;SomeOtherChild/Leaf&amp;quot;);
//Do something with Node/SomeOtherChild/Leaf

A contrived and simple example, but you get the idea. The main worry is the MoveBack method.
Using the following nested class declared inside an XmlNavigator :

public sealed class NavigationClosure : IDisposable
{
    private readonly XmlNavigator _navigator;

    public NavigationClosure(XmlNavigator aNavigator)
    {
        _navigator = aNavigator;
    }

    void IDisposable.Dispose()
    {
        _navigator.MoveBack();
    }
}

and then returning this from all the different navigate methods, we can rewrite above example like so :

using(navigator.Navigate(&amp;quot;//Node&amp;quot;))
{
    using (navigator.Navigate(&amp;quot;SomeChild/SomeGrandChild&amp;quot;))
    {
        // Do something with Node/SomeChildNode/SomeGrandChild
    }
    using(navigator.Navigate(&amp;quot;SomeOtherChild/Leaf&amp;quot;))
    {
        // Do something with Node/SomeOtherChild/Leaf
    }
}

This turns the MoveBack method into an implementation detail as we can ‘privatise’ it.

Posted in C# Musings | 4 Comments »

Is That All There Is

Posted by kilfour on November 25, 2009

Which one do you prefer ?

public event EventHandler OnSomeThingChanged;

private void SomethingChanged(object sender, EventArgs e)
{
    if (OnSomeThingChanged != null)
        OnSomeThingChanged(sender, e);
}

Or :

public event EventHandler OnSomeThingChanged = Empty.Handler;

private void SomethingChanged(object sender, EventArgs e)
{
        OnSomeThingChanged(sender, e);
}

Posted in C# Musings | 5 Comments »

I Woke Up With a Word in My Head

Posted by kilfour on November 25, 2009

I’m one of those developers that consider the actual language being used of little importance. I’ve used quite a lot of them over the years.

The first agile project I’ve ever had the joy of being involved in f.i. was written in VB6 (using VBUnit as a testing tool) and even though it’s a pretty horrific language, I still had a good time.

Some random thoughts :

C++ : My ‘native language’. Although the languages I came across at a very young age were BASIC, RISC assembler and Pascal, this is the first one that I thouroughly studied. I still like it because it gives you total control over the box. Want to spoof a MAC adress ? Just put together a binary struct and send the packet on a raw socket. Reset the system clock ? Find the right memory address and push it in there. Want to hook into the windows login dialog ? Just redirect the call to MSGina.dll to one of your own.
Also it supports any programming paradigm you choose to follow. Procedural : use the C part. OOP : requires some discipline, but can (and should) be done. Functional : the STL supplies all you need, although it’s quite verbose compared to languages that support this ‘naturally’.
In the end, I’d say, not the most beautifull language around, but performance, control over the box and versatility still makes it an interesting choice. But as I said it’s my ‘native language’, so I might be biased.
Alan Kaye : “I invented the term Object Oriented Programming and I didn’t have C++ in mind”

SmallTalk : A thing of true beauty. Totally OOP. Everything’s an object. Five keywords, everything else is constructed on top of that. SmallTalk is written in SmallTalk. The first language I think that had MetaClasses.
On the other hand, I once had to maintain an implementation with thousands of classes and all of them were overwriting the MessageNotUnderstood method in order to handle db persistance. With great power comes great responsibility.

Haskell : I’ve only dabbled in this, but I was in awe. It takes you a long time to get the damn thing to compile, the type system is truly unforgiving, but once it does compile, you’ll have a pretty slick program. Performance is comparable to C++, which makes it incredible as it’s really a much higher level language. The most consise language I’ve seen so far.

C# : The one I’m using mostly these days. Mixed feelings about this one. Initial development is fast, once you hit a wall though it’s harder to debug than Ansi C. Memory management f.i. is supposed to be taken care of, but you still need to be aware of what you’re doing or you could end up in a lot of trouble.
It does possess some nice functional features (and some annoying deviations) however.

OCaml : When I got interested in functional programming, this is the language I decided to study. Again performance rivals C++. It’s not as restrictive as Haskell as it allows for side-effects to happen. This gives the developer more responsibility in keeping things beautifull. Organizing your code into logical units tends to be harder than in any OO orientated language I feel.
I haven’t coded any OCaml stuff for a while but if I could get a job doing this, I reckon I would take a serious paycut in order to do so.

Posted in Rants | 10 Comments »

a + a = b

Posted by kilfour on November 23, 2009

I consider myself talented in a couple of areas. I’m quite a decent bartender for one.
Commitment however is definitely not one of these areas.

A long time ago I anounced an alpha release of QuickNet and I must admit I haven’t delivered.

I have been trying to convince people of the advantages of property based testing however.
One of the most common misconceptions is that you have to reproduce business logic in the tests in order for property based testing to work. My co-workers first thoughts were along these lines, there’s been some ‘twitterings’ describing this, and more recently, a comment on the first article I ever posted about quicknet again suggested the same thing. A quick look at the QuickCheck manual should be enough to convince you that it is _not_ necessary to duplicate business logic. In fact if you do that, you’re writing a bad spec and you’re better of using regular unit testing techniques.

I must admit that the QuickNet introduction post, which I intentionally kept quite simple, does reuse the ‘*’ operator… I never thought it would be regarded as reusing ‘production code’.

At the time I was planning to do a full tour of all the testing tools I’ve used over the years. This includes SUnit, JUnit, csUnit, NUnit, MSTest, CPPUnit, TUT, TUnit (also a homebrewn one, for Win32 C++ dev, a lib that I’m still quite proud of), OUnit, HUnit, QuickCheck, PEX … And I was planning to use the same example for each and every one of them.

As I said, commitment isn’t one of my strong points. So as soon as I got quicknet working I digressed.
In retrospect maybe the ‘Cannonical Calculator’ wasn’t the best way to introduce people to QuickNet as a lot of them just picked up on the reusing of the ‘*’ operator part and disregarded everything else. On the other hand, I think that there’s plenty of examples in the project itself on google code, on the internet from similar frameworks, and even on this blog, that explain how one should write a spec.

Anyway, back on topic, Davy Brion, was one of the first C# oriented developer to recognize the potential. Like me, he has been unit-testing for a while, appreciates the advantages, but recognizes the pittfalls and downsides. These downsides are what we tend to play down when we talk to management or unwilling developers, but on a friday night, after a couple of beers, we have to bow down and admit that they exist.

Recently Davy has expressed his intent to use QuickNet as the main means of testing Agatha, his open-source implementation of the Request/Response pattern for C#.

From the Agatha mailing list :

…but until there’s an official quicknet release, we should probably add a simple text file that contains the svn revision number that the quicknet assemblies were built from…

Now, I have no patience for maintaining such a text file so the easy thing from my point of view is to just get on with it, and get a release out the door.

We’ve been discussing some minor interface decisions and there’s one or two bugs to sort out, but as far as I am concerned when these have been fixed a release will be … erm … released.

I think if I only declare TestDriven.Net and the xunit.gui as supported, I should be able to get a release together by next monday. After that, I can really start getting involved with the Agatha project and I am quite convinced that QuickNet will seriously benefit from having to test something that hasn’t been written by me.
There’s an issue with the Resharper runner that might take some more time resolving.

Posted in QuickNet, Rants | Leave a Comment »

When Not To Use Quicknet

Posted by kilfour on November 23, 2009

Whenever you can’t come up with a good specification.

I’m currently working on an application that uses Dto’s as a way of communicating and I previously demonstrated how easy it was to use quicknet to test the mapping from and to business object.
The input.Equals(output) part only works ofcourse if the Dto’s are implemented as ValueObjects. Doing this is a valid design choice anyway, but it does imply some extra coding. C# could really do with something like an ‘immutable’ keyword I believe. Or maybe allow the access to the private setters of a property in Initializers.
Anyway, back on topic. In order to reduce some of this repetitive coding, I coded an immutable ‘SelectionList’ that can be used by the the Gui. It has an inner list of key/value elements and a method for selecting the current item. Selecting something however returns a copy of the object, the object itself is not modified.
Now I couldn’t really figure out how to test this with quicknet. I really want to test the Equals method. Writing a spec for this would just repeat the code inside the SelectionList and would be quite complicated.
I ended up just TDD-ing it using Facts instead of Specs.

I’m quite happy with the result so here’s the code for those of you that would like an immutable dictionary type thing, but still allows you to set a selection.

    // Implemented as a value object.
    //   - Immutable : manipulating the data gives you a new instance.
    //   - Value Equality : based on the Field values, not the reference, or Field references.
    // Both qualities above should always go together as otherwise the objects
    // can not be safely used in any kind of HashTable, which includes dictionaries and the likes.
    // The dictionary itself is only copied when exposed, in any other case it remains referentially equal.
    // Bit of a FlyWeight pattern.
    public class SelectionList<TKey, TValue>
    {
        private List<KeyValuePair<TKey, TValue>> dictionary;

        public TKey Selection { get; private set; }
        public TValue SelectionValue { get; private set; }

        //private constructors, use the factory method below
        private SelectionList() { }
        private SelectionList(
            List<KeyValuePair<TKey, TValue>> dictionary,
            TKey selection,
            TValue selectionValue)
        {
            this.dictionary = dictionary;
            Selection = selection;
            SelectionValue = selectionValue;
        }

        // Factory Method.
        // Takes
        //   - a collection of elements.
        //   - a memberexpression defining the field (of the elements in the list) to use as key.
        //   - a memberexpression defining the field to use as value.
        //   - an initial selection.
        // passing in an invalid initial selection puts the object in an unstable state, see the tests.
        public static SelectionList<TKey, TValue> New<T>(
            IEnumerable<T> enumerable,
            Expression<Func<T, TKey>> keyExpression,
            Expression<Func<T, TValue>> valueExpression,
            TKey initialSelection)
        {
            SelectionList<TKey, TValue> list =
                new SelectionList<TKey, TValue>
                {
                    dictionary = new List<KeyValuePair<TKey, TValue>>()
                };
            Func<T, TKey> keyFunc = keyExpression.Compile();
            Func<T, TValue> valueFunc = valueExpression.Compile();
            enumerable.ForEach(
                element => list.dictionary.Add(
                               new KeyValuePair<TKey, TValue>(
                                   keyFunc.Invoke(element),
                                   valueFunc.Invoke(element))));

            return list.Select(initialSelection);
        }

        // The only way to manipulate the object.
        // Trying to select something that isn't there simply returns a copy of the object.
        // When correctly selecting something it returns a copy of the object
        // with the new selection set.
        public SelectionList<TKey, TValue> Select(TKey key)
        {
            if (!dictionary.Exists(p => p.Key.Equals(key)))
                return new SelectionList<TKey, TValue>(dictionary, Selection, SelectionValue);

            KeyValuePair<TKey, TValue> pair = dictionary.Find(p => p.Key.Equals(key));
            return new SelectionList<TKey, TValue>(dictionary, pair.Key, pair.Value);
        }

        // Returns a copy of the private collection.
        // Primarely used by Gui to display combo's and the likes.
        // It exposes inner state but the inner state can't be changed.
        // Using the implicit conversion technique as syntactic sugar,
        // meaning we can just assign a selection list to a variable of type
        // List<KeyValuePair<TKey, TValue>> without an extra call.
        public static implicit operator List<KeyValuePair<TKey, TValue>>(SelectionList<TKey, TValue> aSelectionList)
        {
            return new List<KeyValuePair<TKey, TValue>>(aSelectionList.dictionary);
        }

        // Equality member.
        public bool Equals(SelectionList<TKey, TValue> other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return
                dictionary.SequenceEqual(other.dictionary) &&
                Equals(other.Selection, Selection) && Equals(other.SelectionValue, SelectionValue);
        }

        // Equality member.
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(SelectionList<TKey, TValue>)) return false;
            return Equals((SelectionList<TKey, TValue>)obj);
        }

        // Equality member.
        private int GetDictionaryHashCode()
        {
            int result = 0;
            dictionary.ForEach(
                kv =>
                    {
                        result = (result * 397) ^ kv.Key.GetHashCode();
                        result = (result * 397) ^ kv.Value.GetHashCode();
                    });
            return result;
        }

        // Equality member.
        public override int GetHashCode()
        {
            unchecked
            {
                int result = dictionary != null ? GetDictionaryHashCode() : 0;
                result = (result * 397) ^ Selection.GetHashCode();
                result = (result * 397) ^ SelectionValue.GetHashCode();
                return result;
            }
        }
    }

    public static class SelectionList
    {
        // Helper Factory Method that gets rid of some of the generics.
        public static SelectionList<TKey, TValue> New<T, TKey, TValue>(
            IEnumerable<T> enumerable,
            Expression<Func<T, TKey>> keyExpression,
            Expression<Func<T, TValue>> valueExpression,
            TKey initialSelection)
        {
            return SelectionList<TKey, TValue>.New(enumerable, keyExpression, valueExpression, initialSelection);
        }
    }

And an example of usage :

        [Fact]
        public void Selecting()
        {
            List<Element> elements = new List<Element>();
            for (int i = 0; i < 5; i++)
            {
                elements.Add(new Element { Id = i, Display = i.ToString() });
            }

            SelectionList<int, string> selectionList =
                SelectionList.New(elements, el => el.Id, el => el.Display, 0);

            selectionList = selectionList.Select(4);
            Assert.Equal(4, selectionList.Selection);
            Assert.Equal("4", selectionList.SelectionValue);
        }

There’s one known issue with this code : If the initial selection parameter of the factory method is not in the collection it puts the object in an invalid state, as the following test demonstrates :

        [Fact]
        public void BadInitializationThrowsExceptionOnGetHashCode()
        {
            // Todo : maybe change this to BadInitialization Throws InvalidOperationException ?
            List<Element> elements = new List<Element>();
            for (int i = 0; i < 5; i++)
            {
                elements.Add(new Element { Id = i, Display = i.ToString() });
            }

            SelectionList<int, string> selectionList =
                SelectionList.New(elements, t => t.Id, t => t.Display, 7); // Throw exception here ?

            Assert.Throws<NullReferenceException>(() => selectionList.GetHashCode());
        }

You might, as suggested in the comment validate upon construction and throw an exception there, I haven’t made up my mind yet about this.

Although the class is implemented in just about 140 lines (lengthy comments and all), there’s almost 450 lines of test code behind this, needed to cover all cases. I might still try to come up with some decent specs at a later date.

Posted in C# Musings | Leave a Comment »

The One Thing I Really Hate About XUnit.Net

Posted by kilfour on November 22, 2009

Everytime I send a mail out in which I mention the tool, my gmail automatically inserts a link to http://xunit.net/ whereas the correct link is ofcourse http://www.codeplex.com/xunit.

Apart from that is ‘ken fantastic.

Posted in C# Musings | Leave a Comment »

I’ll be Your Mirror

Posted by kilfour on November 22, 2009

As I said in a previous post I’m working on a service layer that maps business objects to dto’s.
The way quicknet plays nice with a mocking framework put a smile on my face, but still, a couple of hours later I had a pretty complicated test.
Driving home from work I had an idea.
The service layer ofcourse also maps dto’s to business objects, so I could use the same kind of specification that I used for the xml-serialization test.
I had to change the transition to :

class DtoRoundTrip: MetaTransition<Dto, Dto>
{
    public DtoRoundTrip()
    {
        Generator = new DtoGenerator();
        Execute = input => mapper.FromDomainObjectToDto(mapper.FromDtoToDomainObject(input));
    }
}

And then I deleted the bunch of SpecFor decorated methods (with some regret as I had put quite a bit of work into it) and replaced them with the following :

[SpecFor(typeof(DtoRoundTrip))]
public Spec ShouldBeEqual(Dto inputDto, ParamsDto Dto)
{
    return new Spec(
        () => Ensure.AreEqual(inputDto, outputDto));
}

Running this immediately reported a bunch (one by one) of errors. F.i. :

DtoRoundTrip ShouldBeEqual
Falsifiable after 1 test(s), 1 Transition(s).
--------------------Simplest Fail Case--------------------
Transition : DtoRoundTrip
Dto
CalendarClicked : True

This report tells me that when the input Dto has it’s property CalendarClicked set to True, it will come back with the property set to false. This is logical as it’s a property that controls Gui logic and has no place in the Dto anyway. The correct solution for this one was to refactor the Gui code. There were other’s like this, and also one or two that were needed but not mapped correctly or even not mapped at all.
This easy transition/specification combination showed them to me one by one.

Posted in QuickNet | Leave a Comment »

Previous Posts : Don’t Look Back

Posted by kilfour on November 20, 2009

Dylan, She Belongs To Me :
She’s got everything she needs,
She’s an artist, she don’t look back.

Talking ’bout my Generation
The Who. On the cd version of one of my favourite albums, Horses by Patty Smith, produced By John Cale, there’s a bonus track where the Patty Smith Band does a wicked cover of this with John Cale playing bass.

Hey Man, Now You’re Really Living
Eels. Not my favourite Eels song, but still pretty good.

Sometimes I’m So Happy,
Sometimes I’m So Sad,
But Mostly You Just Make Me Mad.
First verse of Pale Blue Eyes by the Velvet Underground. This song’s a classic.

The Only One That Could Ever Reach Me
First line of the chorus of Son of a Preacher Man. I don’t really know who wrote it. Dusty Springfield made it famous, Aretha made it great.

Rode the Trolleys,
Down to Forty-Seven,
Figured He Was Good,
To Get Himself to Heaven
Part of Run, Run, Run. Again V.U. From their ‘banana’ debut album. Everything on that one is a classic.

Make It Rain
Tom Waits. White Man’s Blues. You heard the story, here it comes again.

If Love Was an Equation
The main line of one of my favorite Console songs : Into the Universe. From the german notwist scene, brilliant stuff.

Into the Universe
Console. If love was an equation, we’d have no need for songs.

When You Add it Up, It Brings You Down
Part of the chorus from Fear by John Cale.

With a Heart Full of Napalm
Second part of the first line of my favourite stooges song, which makes it one of my all-time favourites.
Blog title and description is also taken from this one :

I’m a street walking cheetah
with a heart full of napalm
I’m a runaway son of the nuclear A-bomb
I am a world’s forgotten boy
The one who searches and destroys
Honey gotta help me please
Somebody gotta save my soul
Baby detonates for me
Look out honey, ’cause I’m using technology !
Ain’t got time to make no apology
Soul radiation in the dead of night
Love in the middle of a fire fight
Honey gotta strike me blind
Somebody gotta save my soul
Baby penetrates my mind
And I’m the world’s forgotten boy
The one who’s searchin’, searchin’ to destroy
And honey I’m the world’s forgotten boy
The one who’s searchin’, searchin’ to destroy
Forgotten boy, forgotten boy
Forgotten boy said
hey forgotten boy

Hush, Little Baby, Don’t Say a Word
… Mama’s going to buy you a mockingbird. First line of a traditional lullaby.

Posted in Looking Back, Music | 1 Comment »

Hush, Little Baby, Don’t Say a Word

Posted by kilfour on November 20, 2009

I’ve been using QuickNet at work lately. Almost always to reduce the amount of repetitive code tests.
We make pretty heavy use of Rhino.Mocks in our tests. Unfortunately the code is not in the best of shape, so sometimes test setup, defining stubs, expectations, etc… is quite a lot of work. Yesterday I wrote a test that asserts a domain object to dto transformation. After coding the first simplest case I already had a lot of tests. Thinking about the corner-cases I still needed to code, being a bit of a lazy person, I got disheartened and decided to see if quicknet could help me out here.
“I’m a pretty lazy person, and am prepared to work quite hard in order to avoid work.” – Martin Fowler
So I translated the tests I allready had, and stumbled onto a happy accident :

[SpecFor(typeof(FromDomainObjectToDto))]
public Spec WithProduct(Offer offer, OfferDto dto)
{
    return new Spec(
        () => repository.VerifyAllExpectations())
        .If(() => offer.Product != null)
        .DoBefore(
        () =>
        {
            repository = MockRepository.GenerateMock<IProductRepository>();
            repository
                .Expect(r => r.GetAvailabilityDatesForProduct(offer.Product.Id))
                .Return(listOfAvailabilityDates);
            mapper = new OfferMapper(repository);
        });
}

[SpecFor(typeof(FromDomainObjectToDto))]
public Spec NoProduct(Offer offer, OfferDto dto)
{
    return new Spec(
        () => repository.VerifyAllExpectations())
        .If(() => offer.Product == null)
        .DoBefore(
        () =>
        {
            repository = MockRepository.GenerateMock<IProductRepository>();
            repository
                .Expect(r => r.GetDefaultProductAvailabilityDates())
                .Return(listOfDefaultAvailabilityDates);
            mapper = new OfferMapper(repository);
        });
}

Here’s the kind of transition I was working on :

class FromDomainObjectToDto : MetaTransition<Offer, OfferDto>
{
    public FromDomainObjectToDto()
    {
        Generator = new OfferGenerator();
        Execute = input => mapper.FromDomainObjectToDto(input);
    }
}

Posted in QuickNet | 2 Comments »