Comments on: Back to Basics: Mock Eliminating Patterns https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/ Fri, 13 Apr 2018 02:35:50 +0000 hourly 1 https://wordpress.org/?v=7.0 By: Pieter Koornhof https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-554 Wed, 04 Feb 2015 20:51:00 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-554 +1 for pattern 3. Moving in a DDD direction there.

]]>
By: andyclap https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-553 Thu, 27 Jan 2011 15:53:58 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-553 Interesting set of posts here.

Both you and I know it doesn’t, but Pattern1 – pull out state – could be read as recommending stateless behavior objects manipulating behaviorless state objects (i.e. procedures and records).
While the example is amusing (to my strange sense of humour), it’s could be a bit confusing. I’m assuming you’re separating out the concern of transforming the state of the world into an AppocalypseScenario from the concern of detecting the state of the world based on the environment, in order to make the transormation test simple. So how to address testing the state of the world detector? “StateMachine” is a bit confusing: it implies a state machine, but this wasn’t originally anything like a state machine – so have you done anything cool to make the detector more testable?

On pattern 4 – Whether you’re calling the workers via a pipeline, a batch process, or a unit test should be irrelevant to the workers involved. Once they’re tested, you can orchestrate your process however you want as long as it calls all the Action it gets given in the order you want with the envelopes it needs . But then I’d instinctively reach for a mock Action to test that …. hmmm.

]]>
By: jsonmez https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-552 Thu, 27 Jan 2011 14:11:49 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-552 In reply to Paul.

Thanks! Appreciate the compliment!

]]>
By: jsonmez https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-551 Thu, 27 Jan 2011 14:11:32 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-551 In reply to Paul.

Hi Paul, you bring up a good point. It is a bit beyond the scope of my example though. I probably should have included some code in this case.

Essentially the pattern I was tying to show here was something like:

for(x = 0; x < blah; x++)
{
var result = DoSomething(x);
Dependency.Use(result);
}

Can be refactored to:

List results = new List();
for(x = 0; x < blah; x++)
{
results.Add(DoSomething(x));
}

return results;

Essentially extracting the dependency by removing it from the original loop and storing the results of all the iterations of the loop into a structure that can be passed to a method that will use the dependency with the accumulated collection of results, so that the first loop can be unit tested easily.

This isn't always going to be efficient or present the best choice (for some of the reasons you stated above), but it will often allow for pulling out dependencies that look like they are tightly coupled to a process because of a loop.

]]>
By: Paul https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-550 Thu, 27 Jan 2011 09:53:21 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-550 Great post as always by the way!

]]>
By: Paul https://simpleprogrammer.com/back-to-basics-mock-eliminating-patterns/#comment-549 Thu, 27 Jan 2011 09:52:59 +0000 https://simpleprogrammer.com/2011/01/26/back-to-basics-mock-eliminating-patterns/#comment-549 In Pattern 4 you’ve now added a dependency on the size of the pile of the letters and an implied 1 to 1 mapping between the two processes. Staying with your good example (which I hopefully won’t abstract and ruin): The 2nd guy can’t start sealing a single letter until the 1st guy has stuffed the entire pile of letters. It also makes “load balancing” be difficult. How about instead if the 1st guy (or guys) stuff each letter and drop them (as they finish each one) into a chute that automatically sends them to the 2nd guy (or guys). The 2nd guy (or guys) takes letters one at a time from the chute, seals it and places it in the next chute to be delivered (the 3rd guy). Basically a CQRS pattern, you can easily add load balancing and the 2nd guy can start working the moment the 1st guy has stuffed his first letter. Finally if your 2nd guy is under-utilised it is easy to get him to start sealing letter from other people – he doesn’t care where the letter comes from, he just seals it!

]]>