After making the post on mocking LINQ to SQL, this morning i was having a chat with Stephen forte and come to know that telerik a has product named RLINQ. RLINQ is built on top of OpenAccess and it supports variety of databases. Being curious, i thought of giving a spin with it and may be try to mock its LINQ to SQL implementation using JustMock.
Now, before i start, i also found that OpenAccess has a free / express version that works on top express database [Ex.sqlexpress] but supports all the features that full version offers. I will be using the free version here. The download is provided at the end of the post along with link pointing steve’s introduction of RLINQ.
Once you have downloaded OpenAccess Q2, you first need to create a class library project and inside the add item dialog you need to choose “Telerik OpenAccess Domain Model” option . Actually, it looks to me same as creating an entity framework edmx just the extension is rlinq.
Next, it will give you an option to choose an empty model or populating it from your database. I would rather choose to populate it from my Northwind database in SqlExpress. That prompts me up with this screen
Here to note that i actually first found the “New Connection” option disabled [may be due to express version] and set my target database using the “Server Explorer” inside visual studio and found it populated as shown above.
Next, i have to choose a model name and by default it suggests “NorthwithEntityDiagram1” but i prefer to choose “NorthwindDataContext” since things are more with data than with diagram.
Once everything is set. I am off to the main topic. I will use the same example from previous post. Accordingly, i created the EmployeeRepository class:
This is plan and simple. There is only method that returns list of employees by hire for a date range. The goal is [those who have missed my previous post] to run the LINQ query into my fake collection to assert the expected behavior of this method.
Therefore, i will be creating a fake data context and for context.Employees i will return my custom collection and finally assert the expected behavior.
That’s it. As “ReturnsCollection” does a number of tasks on behalf of the developer and which is not required for all cases except for IQueryable / IEnumerable implementations, having few feedbacks from my last post, we have made this as an extension method. The reason is not to pull it up every time for mocking members where you don’t need it. Therefore, when you need it you just have to include the following line on top your class:
The helpers extension[from SP1] also gives an opportunity to add more domain specific methods like “ReturnsCollection” without ever cluttering the core API.
Finally, you can check the introductory post from Steve of RLINQ here:
The free version of OpenAccess ORM with RLINQ can be found here, there are other free and interesting tools as well:
OpenAccess version of the sample can be downloaded from:
Subscribe to be the first to get our expert-written articles and tutorials for developers!