Specifications And/Or

Feb 11, 2010 at 10:39 AM

 

I think I need to brush up on my Lambdas/Expressions but I'm a bit stumped writing tests for code which uses the Specification And() extension.

 

Given this code...

var vehicles = _vehicleRepository.FindAll(new VehicleByMakeSpecification(criteria.Make)
.And(new VehicleByModelSpecification(criteria.Model)));

I get errors trying to call  AssertFindAllWasCalledWithSpecification, stepping through the code. When I call this twice (one each for the two specifications), I get null reference errors.

How are you guys testing use of .And()?

 

var vehicles = _vehicleRepository.FindAll(new VehicleByMakeSpecification(criteria.Make)
                                                    .And(new VehicleByModelSpecification(criteria.Model)));

 

 

Developer
Mar 18, 2010 at 5:44 PM

Hi Jon,

Sorry for the delay in replying. Did you make any progress with this?

I'm not sure what you mean by "call this twice (once for each specification)". As you may have already worked out, using the And() extension method in the form x.And(y) actually combines the the two specifications into a single AdHoc<T> specification, so you'd only be expecting one call to FindAll.

Let me know how you're getting on and I'll see if I can help.

Cheers

Jon