2013-10-30 01:09:09 +01:00
|
|
|
unit FrameworkTestsU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
TestFramework,
|
|
|
|
MVCFramework.Router,
|
|
|
|
System.Generics.Collections,
|
|
|
|
MVCFramework;
|
|
|
|
|
|
|
|
type
|
|
|
|
TTestRouting = class(TTestCase)
|
|
|
|
private
|
2013-11-09 10:05:14 +01:00
|
|
|
Router: TMVCRouter;
|
2013-10-30 01:09:09 +01:00
|
|
|
Controllers: TList<TMVCControllerClass>;
|
|
|
|
|
|
|
|
public
|
|
|
|
procedure SetUp; override;
|
|
|
|
procedure TearDown; override;
|
|
|
|
|
|
|
|
published
|
|
|
|
procedure TestWithNoParameters;
|
|
|
|
procedure TestWithNoPath;
|
|
|
|
procedure TestPathButNoParameters;
|
|
|
|
procedure TestPathWithParameters;
|
|
|
|
procedure TestWithMethodTypes;
|
|
|
|
procedure TestComplexRoutings;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TTestRouting }
|
|
|
|
|
|
|
|
uses MVCFramework.Commons,
|
|
|
|
TestControllersU,
|
|
|
|
Web.HTTPApp;
|
|
|
|
|
|
|
|
procedure TTestRouting.SetUp;
|
|
|
|
begin
|
|
|
|
Controllers := TList<TMVCControllerClass>.Create;
|
|
|
|
Controllers.Add(TSimpleController);
|
|
|
|
Router := TMVCRouter.Create(nil);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TearDown;
|
|
|
|
begin
|
|
|
|
Router.Free;
|
|
|
|
Controllers.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestComplexRoutings;
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestPathButNoParameters;
|
|
|
|
var
|
2013-11-09 10:05:14 +01:00
|
|
|
Params: TMVCRequestParamsTable;
|
2013-10-30 01:09:09 +01:00
|
|
|
ResponseContentType: string;
|
2013-11-09 10:05:14 +01:00
|
|
|
ResponseContentEncoding: string;
|
2013-10-30 01:09:09 +01:00
|
|
|
begin
|
|
|
|
Params := TMVCRequestParamsTable.Create;
|
|
|
|
try
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders', httpGET, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals(0, Params.Count);
|
|
|
|
CheckEquals('TSimpleController', Router.MVCControllerClass.ClassName);
|
|
|
|
CheckEquals('Orders', Router.MethodToCall.Name);
|
2013-11-09 10:05:14 +01:00
|
|
|
CheckEquals('UTF-8', ResponseContentEncoding);
|
2013-10-30 01:09:09 +01:00
|
|
|
finally
|
|
|
|
Params.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestPathWithParameters;
|
|
|
|
var
|
2013-11-09 10:05:14 +01:00
|
|
|
Params: TMVCRequestParamsTable;
|
2013-10-30 01:09:09 +01:00
|
|
|
ResponseContentType: string;
|
2013-11-09 10:05:14 +01:00
|
|
|
ResponseContentEncoding: string;
|
2013-10-30 01:09:09 +01:00
|
|
|
begin
|
|
|
|
Params := TMVCRequestParamsTable.Create;
|
|
|
|
try
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders/789', httpGET, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals(1, Params.Count);
|
|
|
|
CheckEquals('789', Params['ordernumber']);
|
|
|
|
CheckEquals('TSimpleController', Router.MVCControllerClass.ClassName);
|
|
|
|
CheckEquals('OrderNumber', Router.MethodToCall.Name);
|
|
|
|
finally
|
|
|
|
Params.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestWithMethodTypes;
|
|
|
|
var
|
2013-11-09 10:05:14 +01:00
|
|
|
Params: TMVCRequestParamsTable;
|
2013-10-30 01:09:09 +01:00
|
|
|
ResponseContentType: string;
|
2013-11-09 10:05:14 +01:00
|
|
|
ResponseContentEncoding: string;
|
2013-10-30 01:09:09 +01:00
|
|
|
begin
|
|
|
|
Params := TMVCRequestParamsTable.Create;
|
|
|
|
try
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders/789', httpPOST, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals('UpdateOrderNumber', Router.MethodToCall.Name);
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders/789', httpPUT, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals('UpdateOrderNumber', Router.MethodToCall.Name);
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckFalse(Router.ExecuteRouting('/orders/789', httpDELETE, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckNull(Router.MethodToCall);
|
|
|
|
CheckFalse(Assigned(Router.MVCControllerClass));
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckFalse(Router.ExecuteRouting('/orders/789', httpHEAD, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding),
|
2013-11-09 10:05:14 +01:00
|
|
|
'Resolved as HEAD');
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckNull(Router.MethodToCall, 'Resolved as HEAD');
|
|
|
|
CheckFalse(Assigned(Router.MVCControllerClass));
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckFalse(Router.ExecuteRouting('/orders/789', httpOPTIONS, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding),
|
2013-11-09 10:05:14 +01:00
|
|
|
'Resolved as OPTIONS');
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckNull(Router.MethodToCall, 'Resolved as OPTIONS');
|
|
|
|
CheckFalse(Assigned(Router.MVCControllerClass));
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders/789', httpGET, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals('OrderNumber', Router.MethodToCall.Name);
|
|
|
|
|
|
|
|
Params.Clear;
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/orders/789', httpGET, 'text/plain',
|
|
|
|
Controllers, Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals('OrderNumber', Router.MethodToCall.Name);
|
|
|
|
finally
|
|
|
|
Params.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestWithNoParameters;
|
|
|
|
var
|
2013-11-09 10:05:14 +01:00
|
|
|
Params: TMVCRequestParamsTable;
|
2013-10-30 01:09:09 +01:00
|
|
|
ResponseContentType: string;
|
2013-11-09 10:05:14 +01:00
|
|
|
ResponseContentEncoding: string;
|
2013-10-30 01:09:09 +01:00
|
|
|
begin
|
|
|
|
Params := TMVCRequestParamsTable.Create;
|
|
|
|
try
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('/', httpGET, 'text/plain', Controllers,
|
|
|
|
Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals(0, Params.Count);
|
|
|
|
CheckEquals('TSimpleController', Router.MVCControllerClass.ClassName);
|
|
|
|
CheckEquals('Index', Router.MethodToCall.Name);
|
|
|
|
finally
|
|
|
|
Params.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTestRouting.TestWithNoPath;
|
|
|
|
var
|
2013-11-09 10:05:14 +01:00
|
|
|
Params: TMVCRequestParamsTable;
|
2013-10-30 01:09:09 +01:00
|
|
|
ResponseContentType: string;
|
2013-11-09 10:05:14 +01:00
|
|
|
ResponseContentEncoding: string;
|
2013-10-30 01:09:09 +01:00
|
|
|
begin
|
|
|
|
Params := TMVCRequestParamsTable.Create;
|
|
|
|
try
|
2013-11-09 14:22:11 +01:00
|
|
|
CheckTrue(Router.ExecuteRouting('', httpGET, 'text/plain', Controllers,
|
|
|
|
Params, ResponseContentType, ResponseContentEncoding));
|
2013-10-30 01:09:09 +01:00
|
|
|
CheckEquals(0, Params.Count);
|
|
|
|
CheckEquals('TSimpleController', Router.MVCControllerClass.ClassName);
|
|
|
|
CheckEquals('Index', Router.MethodToCall.Name);
|
|
|
|
finally
|
|
|
|
Params.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
|
|
RegisterTest(TTestRouting.suite);
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
end.
|