Introduced XmlDoc on IMVCMiddleware

Updated unit test for new middleware interface
This commit is contained in:
danieleteti 2016-02-23 23:22:44 +01:00
parent e68dcafe9b
commit 25b064fec2
2 changed files with 44 additions and 13 deletions

View File

@ -426,12 +426,34 @@ type
TMVCControllerClass = class of TMVCController; TMVCControllerClass = class of TMVCController;
/// <summary>
/// Basis Interface for DMVC Middleware.
/// </summary>
IMVCMiddleware = interface IMVCMiddleware = interface
['{3278183A-124A-4214-AB4E-94CA4C22450D}'] ['{3278183A-124A-4214-AB4E-94CA4C22450D}']
/// <summary>
/// Procedure is called before the MVCEngine routes the request to a specific controller/method.
/// </summary>
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
procedure OnBeforeRouting(Context: TWebContext; var Handled: boolean); procedure OnBeforeRouting(Context: TWebContext; var Handled: boolean);
/// <summary>
/// Procedure is called before the specific controller method is called.
/// </summary>
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
/// <param name="AControllerQualifiedClassName">Qualified classname of the matching controller.</param>
/// <param name="AActionNAme">Method name of the matching controller method.</param>
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
procedure OnBeforeControllerAction(Context: TWebContext; procedure OnBeforeControllerAction(Context: TWebContext;
const AControllerQualifiedClassName: string; const AActionNAme: string; const AControllerQualifiedClassName: string; const AActionNAme: string;
var Handled: boolean); var Handled: boolean);
/// <summary>
/// Procedure is called after the specific controller method was called.
/// It is still possible to cancel or to completly modifiy the request.
/// </summary>
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
/// <param name="AActionNAme">Method name of the matching controller method.</param>
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
procedure OnAfterControllerAction(Context: TWebContext; procedure OnAfterControllerAction(Context: TWebContext;
const AActionNAme: string; const Handled: boolean); const AActionNAme: string; const Handled: boolean);
end; end;

View File

@ -30,11 +30,13 @@ type
TSampleAuth = class(TInterfacedObject, IMVCAuthenticationHandler) TSampleAuth = class(TInterfacedObject, IMVCAuthenticationHandler)
public public
procedure OnRequest(const ControllerQualifiedClassName: string; const ActionName: string; procedure OnRequest(const ControllerQualifiedClassName: string;
var AuthenticationRequired: Boolean); const ActionName: string; var AuthenticationRequired: Boolean);
procedure OnAuthentication(const UserName: string; const Password: string; procedure OnAuthentication(const UserName: string; const Password: string;
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean); UserRoles: System.Generics.Collections.TList<System.string>;
procedure OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean; const SessionData: TDictionary<String, String>);
procedure OnAuthorization(UserRoles
: System.Generics.Collections.TList<System.string>;
const ControllerQualifiedClassName: string; const ActionName: string; const ControllerQualifiedClassName: string; const ActionName: string;
var IsAuthorized: Boolean); var IsAuthorized: Boolean);
end; end;
@ -46,19 +48,23 @@ begin
begin begin
Config[TMVCConfigKey.Messaging] := 'true'; Config[TMVCConfigKey.Messaging] := 'true';
end); end);
MVCEngine.AddController(TTestServerController).AddController(TTestPrivateServerController) MVCEngine.AddController(TTestServerController)
.AddController(TTestPrivateServerController)
.AddController(TTestServerControllerExceptionAfterCreate) .AddController(TTestServerControllerExceptionAfterCreate)
.AddController(TTestServerControllerExceptionBeforeDestroy) .AddController(TTestServerControllerExceptionBeforeDestroy)
.AddMiddleware(TMVCSpeedMiddleware.Create) .AddMiddleware(TMVCSpeedMiddleware.Create)
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create(TSampleAuth.Create)); .AddMiddleware(TMVCBasicAuthenticationMiddleware.Create
(TSampleAuth.Create));
// MVCEngine.Config[TMVCConfigKey.Messaging] := 'false'; // MVCEngine.Config[TMVCConfigKey.Messaging] := 'false';
end; end;
{ TSampleAuth } { TSampleAuth }
procedure TSampleAuth.OnAuthentication(const UserName, Password: string; procedure TSampleAuth.OnAuthentication(const UserName: string;
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean); const Password: string;
UserRoles: System.Generics.Collections.TList<System.string>;
var IsValid: Boolean; const SessionData: TDictionary<String, String>);
begin begin
UserRoles.Clear; UserRoles.Clear;
IsValid := UserName = Password; IsValid := UserName = Password;
@ -77,8 +83,10 @@ begin
end; end;
end; end;
procedure TSampleAuth.OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>; procedure TSampleAuth.OnAuthorization(UserRoles
const ControllerQualifiedClassName, ActionName: string; var IsAuthorized: Boolean); : System.Generics.Collections.TList<System.string>;
const ControllerQualifiedClassName, ActionName: string;
var IsAuthorized: Boolean);
begin begin
IsAuthorized := False; IsAuthorized := False;
if ActionName = 'OnlyRole1' then if ActionName = 'OnlyRole1' then
@ -88,10 +96,11 @@ begin
IsAuthorized := UserRoles.Contains('role2'); IsAuthorized := UserRoles.Contains('role2');
end; end;
procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName, ActionName: string; procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName,
var AuthenticationRequired: Boolean); ActionName: string; var AuthenticationRequired: Boolean);
begin begin
AuthenticationRequired := ControllerQualifiedClassName.EndsWith('TTestPrivateServerController'); AuthenticationRequired := ControllerQualifiedClassName.EndsWith
('TTestPrivateServerController');
end; end;
end. end.