CapableObjects forum



Unit test Eco

Posted By an_drey_curent 2013-12-03 11:25:24
Add to Favorites0
Author Message
an_drey_curent
 Posted 2013-12-03 11:25:24
Supreme Being

Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)Supreme Being - (1 880 reputation)

Group: Awaiting Activation
Last Active: 2013-12-10 12:23:37
Posts: 5, Visits: 52
I'd like to know how can I unit test an EcoApplication. I'm interested in creating mocks of my repositories. I'd like to test the repositories ( which mostly do CRUD operations ) without connecting to the database.

Duplicate here: http://www.capableobjects.com/apps/InstantForum414/Topic3968.aspx?Keywords=test , but I was wondering if there's something else? Thanks.
Scott Price Marked As Answer
 Posted 2013-12-04 13:26:32
Supreme Being

Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)

Group: Forum Members
Last Active: 2014-02-06 08:37:13
Posts: 206, Visits: 841
Hi there,

I create an EcoSpace class in the unit test project that inherits from the normal EcoSpace class you get in our project, but that provides a different PersistenceMapper. This creates an instance of PersistenceMapperMemory and assigns it to the PersistenceMapper attribute of the EcoSpace.

I can then do most operations in my unit tests without issue, excluding one: Direct OclPs queries.

Obviously these go directly to the database to do something, and that doesn't work with PersistenceMapperMemory or PersistenceMapperXml.

So how did I deal with these situations? Well I put a boolean into the repositories, and in registering with the EcoSpace I pass that into the constructors for each repository. That will tell them if I am allowed to query directly to the database or not, and you can react accordingly in code.

This allows you to create a situation where your code will execute any OclPs stuff if you are running in production, but allows you to circumvent that or replace it with in memory evaluations for your testing purposes. Ideally what I do is run OclPs queries, and then perform Ocl queries against the same class type but using the .allLoadedObjects instead of .allInstances, which then allows me to refine any searches to references of that type that are loaded.

I hope this helps you get a rough idea, but if not please post something back and I will see if I have a simple project lying around somewhere I can use as an example. Smile
2013-12-04 13:27:04 by Scott Price
PeterMorris
 Posted 2013-12-04 13:36:30
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
I thought OclPS works on memory mapper, doesn't it? I use the memory mapper + LINQ and that works fine.
HansKarlsen
 Posted 2013-12-04 16:21:54
Supreme Being

Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)Supreme Being - (102 786 reputation)

Group: Administrators
Last Active: 2016-05-11 20:56:01
Posts: 608, Visits: 3 230
Scott - I share Peters view that the OclPs work even if you have a memorymapper. If it does not we should fix it.

I think it should be enough to swap the real pmapper with a memorymapper to run mock tests on any app.
PeterMorris
 Posted 2013-12-04 16:42:45
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
It is. I also use RhinoMocks to create mock repositories etc and register them as ECO services during the test.
Scott Price
 Posted 2013-12-05 14:29:07
Supreme Being

Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)Supreme Being - (17 865 reputation)

Group: Forum Members
Last Active: 2014-02-06 08:37:13
Posts: 206, Visits: 841
Hi Guys,


I always use MemoryMapper these days, but in the past used to use XmlMapper.

I was pretty sure I always used to get exceptions thrown when any OclPs or Eco Linq PSQuery operations occurred, and had to come up with a way to circumvent that whilst still testing the functionality adequately.

That should be very easy to test against a MemoryMapper and XmlMapper though?

I will try to review at some point, but I may not be able to do that until near the weekend. I will see if I can knock up an appropriate case.



Scott Smile
Peter Buchmann
 Posted 2013-12-30 13:00:38
Supreme Being

Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)

Group: Forum Members
Last Active: 2014-03-11 15:27:28
Posts: 230, Visits: 2 803
HansKarlsen (2013-12-04)
Scott - I share Peters view that the OclPs work even if you have a memorymapper. If it does not we should fix it.

I think it should be enough to swap the real pmapper with a memorymapper to run mock tests on any app.


I tried this today with our current ECO release (6.0.0.6733) but both trying PSQuery or OclPs.Execute deliver a empty list whereas Ocl.Evaluate gives me correct list of test data.

Has there been a fix in a later release or is there something still not working?
PeterMorris
 Posted 2013-12-30 14:23:26
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
After you had called UpdateDatabase?
Peter Buchmann
 Posted 2013-12-30 16:55:30
Supreme Being

Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)Supreme Being - (41 091 reputation)

Group: Forum Members
Last Active: 2014-03-11 15:27:28
Posts: 230, Visits: 2 803
OOps. Cool, I didn't think that a MemoryPMP would need a UpdateDatabase(). So now OclPs works but Crying PSQuery not. A simple:

OclPs.Execute("MyClass.AllInstances->Select(StringAttribute='value')") works and delivers the desired values but
PSQuery<MyClass>().Where(x=>StringAttribute=="value").ToList() does not.

Can you verify this?

What you CAN do is to fake (add fakes assembly for referenced dll) the PSQuery extension method by
ShimEcoLinqExtender.PSQueryOf1IEcoServiceProvider(x => new EcoQuery<MyClass>(ecoSpace.Extents.AllInstances<MyClass>().GetAsIObjectList()) { InPS = false })
so that PSQuery is replaced by a EcoQuery to AllInstances but this fake is necessary for all utilized classes, so I think this should only be a interim solution.
2013-12-30 16:56:44 by Peter Buchmann
PeterMorris
 Posted 2013-12-30 21:32:49
Supreme Being

Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)Supreme Being - (60 048 reputation)

Group: Forum Members
Last Active: 2014-08-27 20:30:28
Posts: 324, Visits: 2 449
MemoryPMP needs UpdateDatabase called because it survives past the life of individual ecospaces, and is also multi-thread safe.

As for your PSQuery try doing this

PSQuery<MyClass>().Select(x => x)....Where....OrderBy....etc
2014-01-02 14:52:35 by PeterMorris

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top