Let's see some advanced topics about mORMot's mocking and stubbing features:
- How to handle complex values in parameters / arguments or results, like
record; - Stubbing via a custom delegate or callback;
- Calls tracing.
2012-10-14
2012-10-14. Open Source › mORMot Framework
Let's see some advanced topics about mORMot's mocking and stubbing features:
record;2012-10-14. Open Source › mORMot Framework
In order to fulfill the SOLID principles, two features are to be available when handling interfaces:
We will show now how mORMot provides all needed features for such patterns, testing a simple "forgot my password" scenario: a password shall be computed for a given user name, then transmitted via SMS, and its record shall be updated in the database.
2012-10-14. Open Source › mORMot Framework
Our mORMot framework is now able to
stub or mock any Delphi interface.

As usual, the best way to explain what a library does is to look at the code
using it.
Here is an example (similar to the one shipped with RhinoMocks) of
verifying that when we execute the "forgot my password" scenario, we remembered
to call the Save() method properly:
procedure TMyTest.ForgotMyPassword;
var SmsSender: ISmsSender;
UserRepository: IUserRepository;
begin
TInterfaceStub.Create(TypeInfo(ISmsSender),SmsSender).
Returns('Send',[true]);
TInterfaceMock.Create(TypeInfo(IUserRepository),UserRepository,self).
ExpectsCount('Save',qoEqualTo,1);
with TLoginController.Create(UserRepository,SmsSender) do
try
ForgotMyPassword('toto');
finally
Free;
end;
end;
And... that's all, since the verification will take place when
IUserRepository instance will be release.
If you want to follow the "test spy" pattern (i.e. no expectation defined a priori, but manual check after the execution), you can use:
procedure TMyTest.ForgotMyPassword;
var SmsSender: ISmsSender;
UserRepository: IUserRepository;
Spy: TInterfaceMockSpy;
begin
TInterfaceStub.Create(TypeInfo(ISmsSender),SmsSender).
Returns('Send',[true]);
Spy := TInterfaceMockSpy.Create(TypeInfo(IUserRepository),UserRepository,self);
with TLoginController.Create(UserRepository,SmsSender) do
try
ForgotMyPassword('toto');
finally
Free;
end;
Spy.Verify('Save');
end;
This is something unique with our library: you can decide if you want to use
the classic "expect-run-verify" pattern, or the somewhat more direct
"run-verify" / "test spy" pattern.
With mORMot, you pick up your mocking class (either
TInterfaceMock or TInterfaceMockSpy), then use it as
intended. You can even mix the two aspects in the same instance! It is just a
matter of taste and opportunity for you to use the right pattern.
2012-10-06
2012-10-06. Pascal Programming
In Delphi, you have several ways of handling data life time, therefore several ways of handling memory:
byte integer double
shortstring and fixed size arrays or
record containing only such types), the value is copied in
fixed-size buffers;string and dynamic
arrays or record containing such types), there is a reference
counter handled by each instance, with copy-on-write feature and
compiler-generated reference counting at code scope level (with hidden
try..finally blocks);class instances (e.g. deriving from
TObject), you have to Create then Free
each instance, and manage its life time by hand - with explicit
try..finally blocks;class deriving from TInterfacedObject, you
have a RefCount property, with _AddRef _Release
methods (this is the reference-counted COM model), and you can use Delphi
interface to work with such instances - see this blog article.class level are about to be introduced at the compiler and RTL
level.2012-10-03
2012-10-03. Open Source › mORMot Framework
The limited RTTI available in earlier versions of Delphi we want to
support (starting with Delphi 6/7) lacks of attributes.
Even the attribute feature of newer Delphi version is not
compatible with the one exposed by the FreePascalCompiler, we also
want to support.
Therefore, our ORM expects unique columns in a TSQLRecord
published property to be defined as stored false.
It could be misleading at first, as reported by
several users.
In order to avoid any confusion, we just added a new constant named
AS_UNIQUE.
2012-09-14
2012-09-14. Open Source › mORMot Framework
With a refreshed hardware, and the latest code modifications of the framework code, I run again the benchmark sample.

The new PC has an Intel Core i7-2600 CPU, running on Windows
Seven 64-bit, with anti-virus (Norton) fully enabled.
Oracle 11g database is remotely accessed over a corporate
network, so latency and bandwidth is not optimal.
Still no SSD, but a standard 7200 rpm hard drive of 500 GB.
The results are impressive, when compared to the previous run using
a Core 2 Duo CPU - mORMot's optimized code achieves
amazing speed on this platform.
And I guess the 8MB of L3 cache of the Core i7 does wonders with our
code.
2012-09-10
2012-09-10. Open Source › mORMot Framework
We got some interesting feedback in reddit.
I looked at your website and it is a bit confusing to be honest. After browsing for five minutes I still can't figure out what it is that this framework is supposed to do. It seems like a strange mish mash of different unrelated libraries. You've got some client-server stuff. Some SQLite stuff, which doesn't really fit with client server stuff as it is not a server database. Then there is some PDF stuff.
What is the big picture? What does this actually do?
Such confusion does make sense. Our web site is split into forum, blog, source-code repository and tickets, some wiki pages.

Here are some points of orientation.
2012-09-09
2012-09-09. Open Source › mORMot Framework
Our Open Source mORMot framework is now available in revision 1.17.
The main new features are the following:
*FillPrepare() methods;TDataSet
available for SynDB units;We have some very exciting features on the road-map for the next
1.18 release, like
direct Event/CallBacks handling.
Stay tuned!
« previous entries - page 31 of 53 - next entries »