diff --git a/.gitmodules b/.gitmodules index b47c39a7..99ffe1c8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,9 @@ [submodule "lib/loggerpro"] path = lib/loggerpro url = https://github.com/danieleteti/loggerpro.git +[submodule "lib/jsondataobjects"] + path = lib/jsondataobjects + url = https://github.com/ahausladen/JsonDataObjects.git +[submodule "lib/dunitx"] + path = lib/dunitx + url = https://github.com/VSoftTechnologies/DUnitX.git \ No newline at end of file diff --git a/samples/outputcachewithredis/Test/TestCommonsU.pas b/samples/outputcachewithredis/Test/TestCommonsU.pas index a74f678e..21283bf2 100644 --- a/samples/outputcachewithredis/Test/TestCommonsU.pas +++ b/samples/outputcachewithredis/Test/TestCommonsU.pas @@ -3,7 +3,7 @@ unit TestCommonsU; interface uses - TestFramework; + DUnitX.TestFramework; type TTestCommons = class(TTestCase) @@ -67,6 +67,6 @@ end; initialization // Register any test cases with the test runner -RegisterTest(TTestCommons.Suite); +DUnitX.RegisterTestFixture(TTestCommons); end. diff --git a/samples/outputcachewithredis/Test/TestPeopleModuleU.pas b/samples/outputcachewithredis/Test/TestPeopleModuleU.pas index eea9427e..c62b0dbd 100644 --- a/samples/outputcachewithredis/Test/TestPeopleModuleU.pas +++ b/samples/outputcachewithredis/Test/TestPeopleModuleU.pas @@ -1,18 +1,9 @@ unit TestPeopleModuleU; -{ - - Delphi DUnit Test Case - ---------------------- - This unit contains a skeleton test case class generated by the Test Case Wizard. - Modify the generated code to correctly setup and call the methods from the unit - being tested. - -} interface uses - TestFramework, System.Generics.Collections, FireDAC.Stan.Error, Data.DB, + DUnitX.TestFramework, System.Generics.Collections, FireDAC.Stan.Error, Data.DB, PeopleModuleU, FireDAC.Stan.Intf, FireDAC.DApt, FireDAC.Stan.Pool, FireDAC.Comp.Client, FireDAC.Stan.Async, FireDAC.DatS, FireDAC.UI.Intf, FireDAC.Stan.Param, FireDAC.Phys.IB, FireDAC.Phys, PersonBO, FireDAC.Stan.Option, @@ -119,6 +110,6 @@ end; initialization // Register any test cases with the test runner -//RegisterTest(TestTPeopleModule.Suite); +//TDUnitX.RegisterTestFixture(TestTPeopleModule); end. diff --git a/unittests/general/RESTClient/MVCFramework.Tests.RESTClient.pas b/unittests/general/RESTClient/MVCFramework.Tests.RESTClient.pas index f7766036..3699f051 100644 --- a/unittests/general/RESTClient/MVCFramework.Tests.RESTClient.pas +++ b/unittests/general/RESTClient/MVCFramework.Tests.RESTClient.pas @@ -3,7 +3,7 @@ unit MVCFramework.Tests.RESTClient; interface uses - TestFramework, + DUnitX.TestFramework, System.Classes, System.SysUtils, System.Generics.Collections, @@ -40,23 +40,33 @@ type procedure PostUsers([Body] pBody: TObjectList); end; - TTestRESTClient = class(TTestCase) + [TestFixture] + TTestRESTClient = class(TObject) strict private FServerListener: IMVCListener; FRESTClient: TRESTClient; FRESTAdapter: TRESTAdapter; FAppResource: IAppResource; protected - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published + [Test] procedure TestCreateAndDestroy(); + [Test] procedure TestInformation(); + [Test] procedure TestHelloWorld(); + [Test] procedure TestGetUser(); + [Test] procedure TestPostUser(); + [Test] procedure TestPostUsers(); + [Test] procedure TestGetUsers(); end; @@ -100,9 +110,9 @@ var LClient: TRESTClient; begin LClient := TRESTClient.Create('', 80, nil); - CheckTrue(LClient <> nil); + Assert.IsTrue(LClient <> nil); FreeAndNil(LClient); - CheckTrue(LClient = nil); + Assert.IsTrue(LClient = nil); end; procedure TTestRESTClient.TestGetUser; @@ -115,7 +125,7 @@ begin // String LResp := FRESTClient.doGET; - CheckTrue( + Assert.IsTrue( ('{"Cod":1,"Name":"Ezequiel","Pass":"123"}' = LResp.BodyAsString) and (LResp.ResponseCode = 200) ); @@ -126,7 +136,7 @@ begin LUser := TAppUser.Create; // TSystemJSON.BodyAsJSONObject(FRESTClient.doGET).BodyAsJSONObject.AsObject(); try GetDefaultSerializer.DeserializeObject(FRESTClient.doGET.BodyAsString, LUser); - CheckTrue((LUser <> nil) and (LUser.Cod > 0)); + Assert.IsTrue((LUser <> nil) and (LUser.Cod > 0)); finally FreeAndNil(LUser); end; @@ -134,7 +144,7 @@ begin // Adapter LUser := FAppResource.GetUser; try - CheckTrue((LUser <> nil) and (LUser.Cod > 0)); + Assert.IsTrue((LUser <> nil) and (LUser.Cod > 0)); finally FreeAndNil(LUser); end; @@ -150,7 +160,7 @@ begin lBody := FRESTClient.doGET.BodyAsString; // String - CheckEqualsString('[{"Cod":0,"Name":"Ezequiel 0","Pass":"0"},{"Cod":1,"Name":"Ezequiel 1","Pass":"1"},' + + Assert.AreEqual('[{"Cod":0,"Name":"Ezequiel 0","Pass":"0"},{"Cod":1,"Name":"Ezequiel 1","Pass":"1"},' + '{"Cod":2,"Name":"Ezequiel 2","Pass":"2"},{"Cod":3,"Name":"Ezequiel 3","Pass":"3"},{"Cod":4,"Name":"Ezequiel 4","Pass":"4"},' + '{"Cod":5,"Name":"Ezequiel 5","Pass":"5"},{"Cod":6,"Name":"Ezequiel 6","Pass":"6"},{"Cod":7,"Name":"Ezequiel 7","Pass":"7"},' + '{"Cod":8,"Name":"Ezequiel 8","Pass":"8"},{"Cod":9,"Name":"Ezequiel 9","Pass":"9"},{"Cod":10,"Name":"Ezequiel 10","Pass":"10"}]', @@ -161,7 +171,7 @@ begin try GetDefaultSerializer.DeserializeCollection(lBody, lUsers, TAppUser); // BodyAsJSONArray.AsObjectList; LUsers.OwnsObjects := True; - CheckTrue(LUsers.Count > 0); + Assert.IsTrue(LUsers.Count > 0); finally FreeAndNil(LUsers); end; @@ -170,7 +180,7 @@ begin LUsers := FAppResource.GetUsers; try LUsers.OwnsObjects := True; - CheckTrue(LUsers.Count > 0); + Assert.IsTrue(LUsers.Count > 0); finally FreeAndNil(LUsers); end; @@ -182,10 +192,10 @@ begin FRESTClient.Authentication('dmvc', '123'); // String - CheckEqualsString('Hello World called with GET', FRESTClient.doGET.BodyAsString); + Assert.AreEqual('Hello World called with GET', FRESTClient.doGET.BodyAsString); // Adapter - CheckEqualsString('Hello World called with GET', FAppResource.HelloWorld); + Assert.AreEqual('Hello World called with GET', FAppResource.HelloWorld); end; procedure TTestRESTClient.TestInformation; @@ -205,22 +215,22 @@ begin .SSL .Compression; - CheckTrue(LClient.ReadTimeOut = 100); - CheckTrue(LClient.ConnectionTimeOut = 100); - CheckTrue(LClient.Username = 'dmvc'); - CheckTrue(LClient.Password = 'dmvc'); - CheckTrue(LClient.UseBasicAuthentication); - CheckTrue(LClient.Accept = 'application/json;charset=UTF-8'); - CheckTrue(LClient.ContentType = 'application/json;charset=UTF-8'); - CheckTrue(LClient.ContentEncoding = 'UTF-8'); - CheckTrue(LClient.HasSSL); - CheckTrue(LClient.HasCompression); + Assert.IsTrue(LClient.ReadTimeOut = 100); + Assert.IsTrue(LClient.ConnectionTimeOut = 100); + Assert.IsTrue(LClient.Username = 'dmvc'); + Assert.IsTrue(LClient.Password = 'dmvc'); + Assert.IsTrue(LClient.UseBasicAuthentication); + Assert.IsTrue(LClient.Accept = 'application/json;charset=UTF-8'); + Assert.IsTrue(LClient.ContentType = 'application/json;charset=UTF-8'); + Assert.IsTrue(LClient.ContentEncoding = 'UTF-8'); + Assert.IsTrue(LClient.HasSSL); + Assert.IsTrue(LClient.HasCompression); - CheckTrue(LClient.RawBody <> nil); - CheckTrue(LClient.MultiPartFormData <> nil); - CheckTrue(LClient.BodyParams <> nil); - CheckTrue(LClient.RequestHeaders <> nil); - CheckTrue(LClient.QueryStringParams <> nil); + Assert.IsTrue(LClient.RawBody <> nil); + Assert.IsTrue(LClient.MultiPartFormData <> nil); + Assert.IsTrue(LClient.BodyParams <> nil); + Assert.IsTrue(LClient.RequestHeaders <> nil); + Assert.IsTrue(LClient.QueryStringParams <> nil); FreeAndNil(LClient); end; @@ -238,7 +248,7 @@ begin LUser.Name := 'Ezequiel'; LUser.Pass := '123'; LResp := FRESTClient.doPOST(LUser, True); - CheckTrue(('Success!' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); + Assert.IsTrue(('Success!' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); // Adapter LUser := TAppUser.Create; @@ -274,7 +284,7 @@ begin finally LUsers.Free; end; - CheckTrue(('Success!' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); + Assert.IsTrue(('Success!' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); // Adapter LUsers := TObjectList.Create(True); @@ -291,6 +301,6 @@ end; initialization -RegisterTest(TTestRESTClient.Suite); +TDUnitX.RegisterTestFixture(TTestRESTClient); end. diff --git a/unittests/general/Several/DMVCFrameworkTests.dpr b/unittests/general/Several/DMVCFrameworkTests.dpr index b25bd8da..3da8fef7 100644 --- a/unittests/general/Several/DMVCFrameworkTests.dpr +++ b/unittests/general/Several/DMVCFrameworkTests.dpr @@ -1,22 +1,17 @@ program DMVCFrameworkTests; -{ - Delphi DUnit Test Project - ------------------------- - This project contains the DUnit test framework and the GUI/Console test runners. - Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options - to use the console test runner. Otherwise the GUI test runner will be used by - default. - -} - -{$IFDEF CONSOLE_TESTRUNNER} +{$IFNDEF TESTINSIGHT} {$APPTYPE CONSOLE} -{$ENDIF} - +{$ENDIF}{$STRONGLINKTYPES ON} uses - DUnitTestRunner, + System.SysUtils, + {$IFDEF TESTINSIGHT} + TestInsight.DUnitX, + {$ENDIF } + DUnitX.Loggers.Console, + DUnitX.Loggers.Xml.NUnit, + DUnitX.TestFramework, FrameworkTestsU in 'FrameworkTestsU.pas', LiveServerTestU in 'LiveServerTestU.pas', MessagingExtensionsTestU in 'MessagingExtensionsTestU.pas', @@ -34,17 +29,50 @@ uses {$R *.RES} - +var + runner : ITestRunner; + results : IRunResults; + logger : ITestLogger; + nunitLogger : ITestLogger; begin ReportMemoryLeaksOnShutdown := True; - DUnitTestRunner.RunRegisteredTests; +{$IFDEF TESTINSIGHT} + TestInsight.DUnitX.RunRegisteredTests; + exit; +{$ENDIF} - {$IFDEF CONSOLE_TESTRUNNER} + try + //Check command line options, will exit if invalid + TDUnitX.CheckCommandLine; + //Create the test runner + runner := TDUnitX.CreateRunner; + //Tell the runner to use RTTI to find Fixtures + runner.UseRTTI := True; + //tell the runner how we will log things + //Log to the console window + logger := TDUnitXConsoleLogger.Create(true); + runner.AddLogger(logger); + //Generate an NUnit compatible XML File + nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile); + runner.AddLogger(nunitLogger); + runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests; - write('Press return to continue...'); - ReadLn; - - {$ENDIF} + //Run tests + results := runner.Execute; + if not results.AllPassed then + System.ExitCode := EXIT_ERRORS; + {$IFNDEF CI} + //We don't want this happening when running under CI. + if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then + begin + System.Write('Done.. press key to quit.'); + System.Readln; + end; + {$ENDIF} + except + on E: Exception do + System.Writeln(E.ClassName, ': ', E.Message); + end; end. diff --git a/unittests/general/Several/FrameworkTestsU.pas b/unittests/general/Several/FrameworkTestsU.pas index 1f70b28a..9270ab58 100644 --- a/unittests/general/Several/FrameworkTestsU.pas +++ b/unittests/general/Several/FrameworkTestsU.pas @@ -27,7 +27,7 @@ unit FrameworkTestsU; interface uses - TestFramework, + DUnitX.TestFramework, MVCFramework.Router, System.Generics.Collections, BOs, @@ -36,8 +36,10 @@ uses MVCFramework.MultiMap, MVCFramework.Commons; type - TTestMappers = class(TTestCase) + [TestFixture] + TTestMappers = class(TObject) protected + [Test] procedure SameFishesDataSet(ds, ds2: TDataSet); published @@ -71,7 +73,8 @@ type // procedure TestJSONObjectStringToObjectWithWrongJSON; end; - TTestRouting = class(TTestCase) + [TestFixture] + TTestRouting = class(TObject) private FRouter: TMVCRouter; FControllers: TObjectList; @@ -79,73 +82,114 @@ type FConfig: TMVCConfig; public - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published + [Test] procedure TestWithNoParameters; + [Test] procedure TestWithNoPath; + [Test] procedure TestPathButNoParameters; + [Test] procedure TestPathWithParameters; + [Test] procedure TestWithMethodTypes; + [Test] procedure TestComplexRoutings; + [Test] procedure TestProduceRoutings; + [Test] procedure TestProduceRoutingsWithExplicitCharset; + [Test] procedure TestPathPrefix; // procedure TestRoutingSpeed; // objects mappers end; - TTestJWT = class(TTestCase) + [TestFixture] + TTestJWT = class(TObject) private FJWT: TJWT; public - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published + [Test] procedure TestHMAC; + [Test] procedure TestStorage; + [Test] procedure TestCreateAndValidateToken; + [Test] procedure TestLoadToken; + [Test] procedure TestNotBefore; + [Test] procedure TestExpirationTime; + [Test] procedure TestIssuedAt; + [Test] procedure TestDefaults; end; { This is the base test case for all the serunser testcases, check 'SerializationFrameworkTestU.pas' } - TMVCSerUnSerTestCase = class abstract(TTestCase) + [TestFixture] + TMVCSerUnSerTestCase = class abstract(TObject) private FSerializer: IMVCSerializer; protected procedure SetSerializer(const ASerializer: IMVCSerializer); - procedure SetUp; override; + [SetUp] + procedure SetUp; function GetObjectsList: TObjectList; function GetObjectsWithStreamsList: TObjectList; function GetObjectsWithTValueList: TObjectList; property Serializer: IMVCSerializer read FSerializer; published + [Test] procedure TestSerUnSerObject; virtual; abstract; + [Test] procedure TestSerUnSerObjectList; virtual; abstract; + [Test] procedure TestSerUnSerNestedObjects; virtual; abstract; + [Test] procedure TestSerUnSerObjectWithStream; virtual; abstract; + [Test] procedure TestSerUnSerObjectListWithStream; virtual; abstract; + [Test] procedure TestSerUnSerObjectWithTValue; virtual; abstract; + [Test] procedure TestSerUnSerObjectListWithTValue; virtual; abstract; + [Test] procedure TestSerUnSerObjectStrict; virtual; abstract; + [Test] procedure TestSerUnSerObjectBuiltInCustomTypes; virtual; abstract; + [Test] procedure TestSerUnSerObjectBuiltInCustomTypesFullObject; virtual; abstract; end; - TTestMultiMap = class(TTestCase) + [TestFixture] + TTestMultiMap = class(TObject) protected - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published + [Test] procedure TestObjectMultiMapAdd; + [Test] procedure TestObjectMultiMapRemove; + [Test] procedure TestInterfaceMultiMapAdd; + [Test] procedure TestInterfaceMultiMapRemove; end; @@ -214,21 +258,21 @@ end; procedure TTestMappers.SameFishesDataSet(ds, ds2: TDataSet); begin - CheckEquals(ds.FieldByName('Species No').AsInteger, + Assert.areEqual(ds.FieldByName('Species No').AsInteger, ds2.FieldByName('Species No').AsInteger); - CheckEquals(ds.FieldByName('Category').AsString, ds2.FieldByName('Category') + Assert.areEqual(ds.FieldByName('Category').AsString, ds2.FieldByName('Category') .AsString); - CheckEquals(ds.FieldByName('Common_Name').AsString, + Assert.areEqual(ds.FieldByName('Common_Name').AsString, ds2.FieldByName('Common_Name').AsString); - CheckEquals(ds.FieldByName('Species Name').AsString, + Assert.areEqual(ds.FieldByName('Species Name').AsString, ds2.FieldByName('Species Name').AsString); - CheckEquals(ds.FieldByName('Length (cm)').AsString, + Assert.areEqual(ds.FieldByName('Length (cm)').AsString, ds2.FieldByName('Length (cm)').AsString); - CheckEquals(ds.FieldByName('Length_In').AsInteger, + Assert.areEqual(ds.FieldByName('Length_In').AsInteger, ds2.FieldByName('Length_In').AsInteger); - CheckEquals(ds.FieldByName('Notes').AsString, ds2.FieldByName('Notes') + Assert.areEqual(ds.FieldByName('Notes').AsString, ds2.FieldByName('Notes') .AsString); - CheckEquals(ds.FieldByName('Graphic').AsString, ds2.FieldByName('Graphic') + Assert.areEqual(ds.FieldByName('Graphic').AsString, ds2.FieldByName('Graphic') .AsString); end; @@ -260,11 +304,11 @@ end; // begin // Params := TMVCRequestParamsTable.Create; // try -// CheckTrue(Router.ExecuteRouting('/TNotSoSimpleController/Method1', httpGET, 'text/plain', Controllers, +// Assert.isTrue(Router.ExecuteRouting('/TNotSoSimpleController/Method1', httpGET, 'text/plain', Controllers, // Params, ResponseContentType, ResponseContentEncoding)); -// CheckEquals(0, Params.Count); -// CheckEquals('TSimpleController', Router.MVCControllerClass.ClassName); -// CheckEquals('Index', Router.MethodToCall.Name); +// Assert.areEqual(0, Params.Count); +// Assert.areEqual('TSimpleController', Router.MVCControllerClass.ClassName); +// Assert.areEqual('Index', Router.MethodToCall.Name); // finally // Params.Free; // end; @@ -288,8 +332,8 @@ end; // DesObj := TSystemJSON.JSONObjectToObject(JSONObj); // try // // ASSERT -// CheckTrue(TStringStream(DesObj.PropStream).DataString.IsEmpty); -// CheckTrue(TStringStream(DesObj.Prop8Stream).DataString.IsEmpty); +// Assert.isTrue(TStringStream(DesObj.PropStream).DataString.IsEmpty); +// Assert.isTrue(TStringStream(DesObj.Prop8Stream).DataString.IsEmpty); // finally // DesObj.Free; // end; @@ -313,7 +357,7 @@ end; // try // Obj2 := Mapper.JSONObjectToObject(JObj); // try -// CheckTrue(Obj.Equals(Obj2)); +// Assert.isTrue(Obj.Equals(Obj2)); // finally // Obj2.Free; // end; @@ -339,7 +383,7 @@ end; // try // Obj2 := Mapper.JSONObjectToObject(JObj); // try -// CheckTrue(Obj.Equals(Obj2)); +// Assert.isTrue(Obj.Equals(Obj2)); // finally // Obj2.Free; // end; @@ -359,37 +403,37 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/path1/1', httpPOST, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/path1/1', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('TestMultiplePaths', FRouter.MethodToCall.Name); + Assert.areEqual('TestMultiplePaths', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/path2/1/2/3', httpPOST, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/path2/1/2/3', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('TestMultiplePaths', FRouter.MethodToCall.Name); + Assert.areEqual('TestMultiplePaths', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/path3/1/2/tre/3', httpPOST, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/path3/1/2/tre/3', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('TestMultiplePaths', FRouter.MethodToCall.Name); + Assert.areEqual('TestMultiplePaths', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/path4/par1/2/par2/3/4', httpPOST, + Assert.isTrue(FRouter.ExecuteRouting('/path4/par1/2/par2/3/4', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('TestMultiplePaths', FRouter.MethodToCall.Name); + Assert.areEqual('TestMultiplePaths', FRouter.MethodToCall.Name); Params.Clear; - CheckFalse(FRouter.ExecuteRouting('/path4/par1/par2/3/4/notvalidparameter', + Assert.isFalse(FRouter.ExecuteRouting('/path4/par1/par2/3/4/notvalidparameter', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckNull(FRouter.MethodToCall); - CheckFalse(Assigned(FRouter.ControllerClazz)); + Assert.isNull(FRouter.MethodToCall); + Assert.isFalse(Assigned(FRouter.ControllerClazz)); finally Params.Free; @@ -564,16 +608,16 @@ end; // ds.Post; // JObj := ds.AsJSONObject; // try -// CheckEquals('myStringValue', JObj.Values['string_value'].Value); -// CheckEquals(123, JObj.Values['integer_value'].GetValue().AsInt); -// CheckEquals(123.456, JObj.Values['float_value'].GetValue().AsDouble, 0.0009); -// CheckTrue(JObj.Values['null_value'].GetValue().Null); -// CheckEquals(true, JObj.Values['boolean_value'].GetValue().AsBoolean); -// CheckTrue(JObj.ToJSON.Replace(' ', '').Contains('"null_value":null')); +// Assert.areEqual('myStringValue', JObj.Values['string_value'].Value); +// Assert.areEqual(123, JObj.Values['integer_value'].GetValue().AsInt); +// Assert.areEqual(123.456, JObj.Values['float_value'].GetValue().AsDouble, 0.0009); +// Assert.isTrue(JObj.Values['null_value'].GetValue().Null); +// Assert.areEqual(true, JObj.Values['boolean_value'].GetValue().AsBoolean); +// Assert.isTrue(JObj.ToJSON.Replace(' ', '').Contains('"null_value":null')); // ds.Insert; // ds.LoadFromJSONObject(JObj); // ds.Post; -// CheckTrue(ds.FieldByName('null_value').IsNull); +// Assert.isTrue(ds.FieldByName('null_value').IsNull); // finally // JObj.Free; // end; @@ -597,9 +641,9 @@ end; // RetList := TObjectList(Mapper.JSONArrayToObjectList(TMyObject, // JSONArr, false)); // try -// CheckEquals(2, RetList.Count); +// Assert.areEqual(2, RetList.Count); // for I := 0 to ListObj.Count - 1 do -// CheckTrue(ListObj[I].Equals(RetList[I])); +// Assert.isTrue(ListObj[I].Equals(RetList[I])); // finally // RetList.Free; // end; @@ -627,9 +671,9 @@ end; // try // Mapper.JSONArrayToObjectList(WrapAsList(RetList), TMyObject, // JSONArr, false); -// CheckEquals(2, RetList.Count); +// Assert.areEqual(2, RetList.Count); // for I := 0 to ListObj.Count - 1 do -// CheckTrue(ListObj[I].Equals(RetList[I])); +// Assert.isTrue(ListObj[I].Equals(RetList[I])); // finally // RetList.Free; // end; @@ -659,7 +703,7 @@ end; // try // lMyObject2 := GetMyObject; // try -// CheckTrue(lMyObject.Equals(lMyObject2)); +// Assert.isTrue(lMyObject.Equals(lMyObject2)); // finally // lMyObject2.Free; // end; @@ -686,7 +730,7 @@ end; // try // Obj2 := Mapper.JSONObjectToObject(JObj); // try -// CheckTrue(Obj.Equals(Obj2)); +// Assert.isTrue(Obj.Equals(Obj2)); // finally // Obj2.Free; // end; @@ -705,7 +749,7 @@ end; // begin // LJSONObject := '{"ImageStream":null}'; // Obj := Mapper.JSONObjectStringToObject(LJSONObject); -// CheckNull(Obj.ImageStream); +// Assert.isNull(Obj.ImageStream); // Obj.Free; // end; // @@ -722,7 +766,7 @@ end; // Obj2 := TMyObject.Create; // try // Mapper.LoadJSONObjectToObject(JObj, Obj2); -// CheckTrue(Obj.Equals(Obj2)); +// Assert.isTrue(Obj.Equals(Obj2)); // finally // Obj2.Free; // end; @@ -753,10 +797,10 @@ end; // // Obj2List := Mapper.JSONArrayToObjectList(JSON); // try -// CheckEquals(ObjList.Count, Obj2List.Count); +// Assert.areEqual(ObjList.Count, Obj2List.Count); // for I := 0 to 9 do // begin -// CheckTrue(Obj2List[I].Equals(ObjList[I])); +// Assert.isTrue(Obj2List[I].Equals(ObjList[I])); // end; // finally // Obj2List.Free; @@ -787,12 +831,12 @@ end; // WrapList := WrapAsList(ObjList); // JSON := Mapper.ObjectListToJSONArray(WrapList); // try -// CheckEquals(WrapList.Count, JSON.Count); +// Assert.areEqual(WrapList.Count, JSON.Count); // for I := 0 to 9 do // begin // LJSONObj := JSON.Items[I] as TJSONObject; // LMyItem := WrapList.GetItem(I) as TMyObject; -// CheckEquals(LMyItem.PropInteger, LJSONObj.GetValue('PropInteger')); +// Assert.areEqual(LMyItem.PropInteger, LJSONObj.GetValue('PropInteger')); // end; // finally // JSON.Free; @@ -814,7 +858,7 @@ end; // try // Obj2 := Mapper.JSONObjectToObject(JSON); // try -// CheckTrue(Obj.Equals(Obj2)); +// Assert.isTrue(Obj.Equals(Obj2)); // finally // Obj2.Free; // end; @@ -843,8 +887,8 @@ end; // ResultSO := Mapper.JSONObjectToObject(JSONObj); // try // // ASSERT -// CheckEquals(SO.ImageStream.Size, ResultSO.ImageStream.Size); -// CheckEquals(MD5(SO.ImageStream), MD5(ResultSO.ImageStream)); +// Assert.areEqual(SO.ImageStream.Size, ResultSO.ImageStream.Size); +// Assert.areEqual(MD5(SO.ImageStream), MD5(ResultSO.ImageStream)); // finally // ResultSO.Free; // end; @@ -875,7 +919,7 @@ end; // try // ResultStr := TStringStream(ResultSO.PropStream).DataString; // // ASSERT -// CheckEquals(str, ResultStr); +// Assert.areEqual(str, ResultStr); // finally // ResultSO.Free; // end; @@ -906,7 +950,7 @@ end; // try // ResultStr := UTF8String(TStringStream(ResultSO.Prop8Stream).DataString); // // ASSERT -// CheckEquals(str, ResultStr); +// Assert.areEqual(str, ResultStr); // finally // ResultSO.Free; // end; @@ -932,7 +976,7 @@ end; // LJSONObj := Mapper.ObjectToJSONObject(lResponse); // try // CheckNotNull(LJSONObj.GetValue('Items')); -// CheckEquals(2, TJSONArray(LJSONObj.GetValue('Items')).Count); +// Assert.areEqual(2, TJSONArray(LJSONObj.GetValue('Items')).Count); // finally // LJSONObj.Free; // end; @@ -949,14 +993,14 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/orders', httpGET, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCConstants.DEFAULT_CONTENT_CHARSET, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals(0, Params.Count); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('Orders', FRouter.MethodToCall.Name); - CheckEquals(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentEncoding); + Assert.areEqual(0, Params.Count); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('Orders', FRouter.MethodToCall.Name); + Assert.areEqual(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentEncoding); finally Params.Free; end; @@ -983,20 +1027,20 @@ begin try lParams := TMVCRequestParamsTable.Create; try - CheckFalse(lRouter.ExecuteRouting('/api/orders', httpGET, 'text/plain', + Assert.isFalse(lRouter.ExecuteRouting('/api/orders', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCConstants.DEFAULT_CONTENT_CHARSET, lParams, ResponseContentType, ResponseContentEncoding)); lConfig.Value[TMVCConfigKey.PathPrefix] := '/api'; - CheckTrue(lRouter.ExecuteRouting('/api/orders', httpGET, 'text/plain', + Assert.isTrue(lRouter.ExecuteRouting('/api/orders', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCConstants.DEFAULT_CONTENT_CHARSET, lParams, ResponseContentType, ResponseContentEncoding)); - CheckEquals(0, lParams.Count); - CheckEquals('TSimpleController', lRouter.ControllerClazz.ClassName); - CheckEquals('Orders', lRouter.MethodToCall.Name); - CheckEquals(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentEncoding); + Assert.areEqual(0, lParams.Count); + Assert.areEqual('TSimpleController', lRouter.ControllerClazz.ClassName); + Assert.areEqual('Orders', lRouter.MethodToCall.Name); + Assert.areEqual(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentEncoding); finally lParams.Free; end; @@ -1017,27 +1061,27 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals(1, Params.Count); - CheckEquals('789', Params['ordernumber']); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('OrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual(1, Params.Count); + Assert.areEqual('789', Params['ordernumber']); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('OrderNumber', FRouter.MethodToCall.Name); finally Params.Free; end; Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/orders/àèéìòù .-_\', httpGET, + Assert.isTrue(FRouter.ExecuteRouting('/orders/àèéìòù .-_\', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals(1, Params.Count); - CheckEquals('àèéìòù .-_\', Params['ordernumber']); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('OrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual(1, Params.Count); + Assert.areEqual('àèéìòù .-_\', Params['ordernumber']); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('OrderNumber', FRouter.MethodToCall.Name); finally Params.Free; end; @@ -1053,14 +1097,14 @@ begin Params := TMVCRequestParamsTable.Create; try // a GET request with a ACCEPT: application/json - CheckTrue(FRouter.ExecuteRouting('/orders', httpGET, '', 'application/json', + Assert.isTrue(FRouter.ExecuteRouting('/orders', httpGET, '', 'application/json', FControllers, TMVCConstants.DEFAULT_CONTENT_TYPE, TMVCConstants.DEFAULT_CONTENT_CHARSET, Params, ResponseContentType, ResponseContentCharset)); - CheckEquals(0, Params.Count); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('OrdersProduceJSON', FRouter.MethodToCall.Name); - CheckEquals(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentCharset); + Assert.areEqual(0, Params.Count); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('OrdersProduceJSON', FRouter.MethodToCall.Name); + Assert.areEqual(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentCharset); finally Params.Free; end; @@ -1075,14 +1119,14 @@ begin Params := TMVCRequestParamsTable.Create; try // a GET request with a ACCEPT: application/json - CheckTrue(FRouter.ExecuteRouting('/orders', httpGET, '', + Assert.isTrue(FRouter.ExecuteRouting('/orders', httpGET, '', 'application/json; charset=UTF-8', FControllers, TMVCConstants.DEFAULT_CONTENT_TYPE, TMVCConstants.DEFAULT_CONTENT_CHARSET, Params, ResponseContentType, ResponseContentCharset)); - CheckEquals(0, Params.Count); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('OrdersProduceJSON', FRouter.MethodToCall.Name); - CheckEquals(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentCharset); + Assert.areEqual(0, Params.Count); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('OrdersProduceJSON', FRouter.MethodToCall.Name); + Assert.areEqual(TMVCConstants.DEFAULT_CONTENT_CHARSET, ResponseContentCharset); finally Params.Free; end; @@ -1116,7 +1160,7 @@ end; // Params, // ResponseContentType, ResponseContentEncoding); // end; -// CheckTrue(false, lSW.ElapsedMilliseconds.ToString); +// Assert.isTrue(false, lSW.ElapsedMilliseconds.ToString); // finally // Params.Free; // end; @@ -1133,7 +1177,7 @@ end; // try // lJObj := Mapper.ObjectToJSONObjectFields(lObj, []); // try -// CheckEquals(4, lJObj.Count); // 3 properties + $dmvc.classname +// Assert.areEqual(4, lJObj.Count); // 3 properties + $dmvc.classname // CheckNotNull(lJObj.Get('FFirstName')); // CheckNotNull(lJObj.Get('FLastName')); // CheckNotNull(lJObj.Get('FAge')); @@ -1141,7 +1185,7 @@ end; // try // CheckIs(lObj2, TMyObjectWithLogic, // 'wrong classtype for deserialized object'); -// CheckTrue(lObj.Equals(lObj2), +// Assert.isTrue(lObj.Equals(lObj2), // 'restored object is different from the original'); // finally // lObj2.Free; @@ -1164,7 +1208,7 @@ end; // try // lJObj := Mapper.ObjectToJSONObjectFields(lObj, []); // try -// CheckEquals(5, lJObj.Count); // 4 properties + $dmvc.classname +// Assert.areEqual(5, lJObj.Count); // 4 properties + $dmvc.classname // CheckNotNull(lJObj.Get('FProp1')); // CheckNotNull(lJObj.Get('FChildObjectList')); // CheckNotNull(lJObj.Get('FChildObject')); @@ -1172,7 +1216,7 @@ end; // try // CheckIs(lObj2, TMyComplexObject, // 'wrong classtype for deserialized object'); -// CheckTrue(lObj.Equals(lObj2), +// Assert.isTrue(lObj.Equals(lObj2), // 'restored object is different from the original'); // finally // lObj2.Free; @@ -1195,7 +1239,7 @@ end; // try // lJObj := Mapper.ObjectToJSONObjectFields(lObj, []); // try -// CheckEquals(5, lJObj.Count); // 4 properties + $dmvc.classname +// Assert.areEqual(5, lJObj.Count); // 4 properties + $dmvc.classname // CheckNotNull(lJObj.Get('FProp1')); // CheckNotNull(lJObj.Get('FChildObjectList')); // CheckNotNull(lJObj.Get('FChildObject')); @@ -1203,7 +1247,7 @@ end; // try // CheckIs(lObj2, TMyComplexObject, // 'wrong classtype for deserialized object'); -// CheckTrue(lObj.Equals(lObj2), +// Assert.isTrue(lObj.Equals(lObj2), // 'restored object is different from the original'); // finally // lObj2.Free; @@ -1230,7 +1274,7 @@ end; // lJObj.RemovePair('FFirstName').Free; // lObj2 := Mapper.JSONObjectFieldsToObject(lJObj) as TMyObjectWithLogic; // try -// CheckEquals('', lObj2.FirstName); +// Assert.areEqual('', lObj2.FirstName); // finally // lObj2.Free; // end; @@ -1252,7 +1296,7 @@ end; // try // lJObj := Mapper.ObjectToJSONObject(lObj, []); // try -// CheckEquals(5, lJObj.Count); // 5 properties +// Assert.areEqual(5, lJObj.Count); // 5 properties // CheckNotNull(lJObj.Get('FirstName')); // CheckNotNull(lJObj.Get('LastName')); // CheckNotNull(lJObj.Get('Age')); @@ -1260,7 +1304,7 @@ end; // CheckNotNull(lJObj.Get('IsAdult')); // lObj2 := Mapper.JSONObjectToObject(lJObj); // try -// CheckTrue(lObj2.Equals(lObj), +// Assert.isTrue(lObj2.Equals(lObj), // 'deserialized object is not equals to the original object'); // finally // lObj2.Free; @@ -1281,55 +1325,55 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpPOST, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpPOST, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('UpdateOrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual('UpdateOrderNumber', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpPUT, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpPUT, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('UpdateOrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual('UpdateOrderNumber', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpPATCH, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpPATCH, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('PatchOrder', FRouter.MethodToCall.Name); + Assert.areEqual('PatchOrder', FRouter.MethodToCall.Name); Params.Clear; - CheckFalse(FRouter.ExecuteRouting('/orders/789', httpDELETE, 'text/plain', + Assert.isFalse(FRouter.ExecuteRouting('/orders/789', httpDELETE, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckNull(FRouter.MethodToCall); - CheckFalse(Assigned(FRouter.ControllerClazz)); + Assert.isNull(FRouter.MethodToCall); + Assert.isFalse(Assigned(FRouter.ControllerClazz)); Params.Clear; - CheckFalse(FRouter.ExecuteRouting('/orders/789', httpHEAD, 'text/plain', + Assert.isFalse(FRouter.ExecuteRouting('/orders/789', httpHEAD, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding), 'Resolved as HEAD'); - CheckNull(FRouter.MethodToCall, 'Resolved as HEAD'); - CheckFalse(Assigned(FRouter.ControllerClazz)); + Assert.isNull(FRouter.MethodToCall, 'Resolved as HEAD'); + Assert.isFalse(Assigned(FRouter.ControllerClazz)); Params.Clear; - CheckFalse(FRouter.ExecuteRouting('/orders/789', httpOPTIONS, 'text/plain', + Assert.isFalse(FRouter.ExecuteRouting('/orders/789', httpOPTIONS, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding), 'Resolved as OPTIONS'); - CheckNull(FRouter.MethodToCall, 'Resolved as OPTIONS'); - CheckFalse(Assigned(FRouter.ControllerClazz)); + Assert.isNull(FRouter.MethodToCall, 'Resolved as OPTIONS'); + Assert.isFalse(Assigned(FRouter.ControllerClazz)); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('OrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual('OrderNumber', FRouter.MethodToCall.Name); Params.Clear; - CheckTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/orders/789', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals('OrderNumber', FRouter.MethodToCall.Name); + Assert.areEqual('OrderNumber', FRouter.MethodToCall.Name); finally Params.Free; end; @@ -1343,12 +1387,12 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('/', httpGET, 'text/plain', 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('/', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals(0, Params.Count); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('Index', FRouter.MethodToCall.Name); + Assert.areEqual(0, Params.Count); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('Index', FRouter.MethodToCall.Name); finally Params.Free; end; @@ -1362,12 +1406,12 @@ var begin Params := TMVCRequestParamsTable.Create; try - CheckTrue(FRouter.ExecuteRouting('', httpGET, 'text/plain', 'text/plain', + Assert.isTrue(FRouter.ExecuteRouting('', httpGET, 'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params, ResponseContentType, ResponseContentEncoding)); - CheckEquals(0, Params.Count); - CheckEquals('TSimpleController', FRouter.ControllerClazz.ClassName); - CheckEquals('Index', FRouter.MethodToCall.Name); + Assert.areEqual(0, Params.Count); + Assert.areEqual('TSimpleController', FRouter.ControllerClazz.ClassName); + Assert.areEqual('Index', FRouter.MethodToCall.Name); finally Params.Free; end; @@ -1402,18 +1446,18 @@ begin FJWT.Claims.NotBefore := Yesterday; lToken := FJWT.GetToken; // TFile.WriteAllText('jwt_token.dat', lToken); - CheckTrue(FJWT.IsValidToken(lToken, lError), 'Generated token is not valid'); + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Generated token is not valid'); end; procedure TTestJWT.TestDefaults; begin - CheckEquals('HS256', FJWT.HMACAlgorithm, 'Default algorithm should be HS256'); - CheckEquals(300, FJWT.LeewaySeconds, 'Default leeway should be 5 minutes'); + Assert.areEqual('HS256', FJWT.HMACAlgorithm, 'Default algorithm should be HS256'); + Assert.areEqual(300, FJWT.LeewaySeconds, 'Default leeway should be 5 minutes'); if FJWT.RegClaimsToChecks * [TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt] <> [TJWTCheckableClaim.ExpirationTime, TJWTCheckableClaim.NotBefore, TJWTCheckableClaim.IssuedAt] then - Fail('Default RegClaimsToCheck not correct'); + Assert.Fail('Default RegClaimsToCheck not correct'); end; procedure TTestJWT.TestExpirationTime; @@ -1424,22 +1468,22 @@ begin FJWT.RegClaimsToChecks := [TJWTCheckableClaim.ExpirationTime]; FJWT.Claims.ExpirationTime := Tomorrow; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered expired'); FJWT.Claims.ExpirationTime := Yesterday; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Expired token is considered valid'); FJWT.Claims.ExpirationTime := Now; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered expired'); FJWT.Claims.ExpirationTime := Now - (FJWT.LeewaySeconds + 1) * OneSecond; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Expired token is considered valid'); end; @@ -1453,7 +1497,7 @@ begin begin lAlg := HMAC_ALG_AND_RESULTS[I][0]; lValue := HMAC_ALG_AND_RESULTS[I][1]; - CheckEquals(lValue, BytesToHex(HMAC(lAlg, 'Daniele Teti', 'daniele')), + Assert.areEqual(lValue, BytesToHex(HMAC(lAlg, 'Daniele Teti', 'daniele')), 'HMAC ' + lAlg + ' fails'); end; end; @@ -1466,22 +1510,22 @@ begin FJWT.RegClaimsToChecks := [TJWTCheckableClaim.IssuedAt]; FJWT.Claims.IssuedAt := Yesterday; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered not valid'); FJWT.Claims.IssuedAt := Tomorrow; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Still-not-valid token is considered valid'); FJWT.Claims.IssuedAt := Now; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered not valid'); FJWT.Claims.IssuedAt := Now + (FJWT.LeewaySeconds + 1) * OneSecond; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Still-not-valid token is considered valid'); end; @@ -1506,18 +1550,18 @@ begin lJWT := TJWT.Create(JWT_SECRET_KEY_TEST); try lJWT.LoadToken(lToken); - CheckEquals('bit Time Professionals', lJWT.Claims.Issuer); - CheckEquals('DelphiMVCFramework', lJWT.Claims.Subject); - CheckEquals('DelphiDevelopers', lJWT.Claims.Audience); - CheckEquals('123456', lJWT.Claims.JWT_ID); - CheckEquals(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), + Assert.areEqual('bit Time Professionals', lJWT.Claims.Issuer); + Assert.areEqual('DelphiMVCFramework', lJWT.Claims.Subject); + Assert.areEqual('DelphiDevelopers', lJWT.Claims.Audience); + Assert.areEqual('123456', lJWT.Claims.JWT_ID); + Assert.areEqual(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), lJWT.Claims.IssuedAt); - CheckEquals(Roundto(lJWT.Claims.IssuedAt + OneHour * 2, 4), + Assert.areEqual(Roundto(lJWT.Claims.IssuedAt + OneHour * 2, 4), Roundto(lJWT.Claims.ExpirationTime, 4)); - CheckEquals(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), + Assert.areEqual(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), lJWT.Claims.NotBefore); - CheckEquals('dteti', lJWT.CustomClaims['username']); - CheckEquals('admin', lJWT.CustomClaims['userrole']); + Assert.areEqual('dteti', lJWT.CustomClaims['username']); + Assert.areEqual('admin', lJWT.CustomClaims['userrole']); finally lJWT.Free; end; @@ -1532,22 +1576,22 @@ begin FJWT.RegClaimsToChecks := [TJWTCheckableClaim.NotBefore]; FJWT.Claims.NotBefore := Yesterday; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered not valid'); FJWT.Claims.NotBefore := Tomorrow; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Still-not-valid token is considered valid (near midnight is ok... fix this test) '); FJWT.Claims.NotBefore := Now; lToken := FJWT.GetToken; - CheckTrue(FJWT.IsValidToken(lToken, lError), + Assert.isTrue(FJWT.IsValidToken(lToken, lError), 'Valid token is considered not valid'); FJWT.Claims.NotBefore := Now + (FJWT.LeewaySeconds + 1) * OneSecond; lToken := FJWT.GetToken; - CheckFalse(FJWT.IsValidToken(lToken, lError), + Assert.isFalse(FJWT.IsValidToken(lToken, lError), 'Still-not-valid token is considered valid'); end; @@ -1563,18 +1607,18 @@ begin FJWT.CustomClaims['username'] := 'dteti'; FJWT.CustomClaims['userrole'] := 'admin'; - CheckEquals('bit Time Professionals', FJWT.Claims.Issuer); - CheckEquals('DelphiMVCFramework', FJWT.Claims.Subject); - CheckEquals('DelphiDevelopers', FJWT.Claims.Audience); - CheckEquals('123456', FJWT.Claims.JWT_ID); - CheckEquals(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), FJWT.Claims.IssuedAt); - CheckEquals(Roundto(FJWT.Claims.IssuedAt + OneHour * 2, 4), + Assert.areEqual('bit Time Professionals', FJWT.Claims.Issuer); + Assert.areEqual('DelphiMVCFramework', FJWT.Claims.Subject); + Assert.areEqual('DelphiDevelopers', FJWT.Claims.Audience); + Assert.areEqual('123456', FJWT.Claims.JWT_ID); + Assert.areEqual(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), FJWT.Claims.IssuedAt); + Assert.areEqual(Roundto(FJWT.Claims.IssuedAt + OneHour * 2, 4), Roundto(FJWT.Claims.ExpirationTime, 4)); - CheckEquals(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), + Assert.areEqual(EncodeDateTime(2011, 11, 17, 17, 30, 0, 0), FJWT.Claims.NotBefore); - CheckEquals('dteti', FJWT.CustomClaims['username']); - CheckEquals('admin', FJWT.CustomClaims['userrole']); + Assert.areEqual('dteti', FJWT.CustomClaims['username']); + Assert.areEqual('admin', FJWT.CustomClaims['userrole']); end; @@ -1645,19 +1689,19 @@ var lMultiMap: IMVCInterfaceMultiMap; begin lMultiMap := TMVCInterfaceMultiMap.Create; - CheckEquals(0, Length(lMultiMap.Keys)); + Assert.areEqual(0, Length(lMultiMap.Keys)); lMultiMap.Clear; - CheckFalse(lMultiMap.Contains('key1')); + Assert.isFalse(lMultiMap.Contains('key1')); lMultiMap.Add('key1', TMyIntfObject.Create(1, 'value1')); - CheckTrue(lMultiMap.Contains('key1')); - CheckEquals(1, lMultiMap.GetItems('key1').Count); + Assert.isTrue(lMultiMap.Contains('key1')); + Assert.areEqual(1, lMultiMap.GetItems('key1').Count); lMultiMap.Add('key1', TMyIntfObject.Create(2, 'value2')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckEquals('value1', lMultiMap.GetItems('key1')[0].GetDescription); - CheckEquals('value2', lMultiMap.GetItems('key1')[1].GetDescription); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.areEqual('value1', lMultiMap.GetItems('key1')[0].GetDescription); + Assert.areEqual('value2', lMultiMap.GetItems('key1')[1].GetDescription); lMultiMap.Add('key2', TMyIntfObject.Create(1, 'value3')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckEquals(1, lMultiMap.GetItems('key2').Count); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.areEqual(1, lMultiMap.GetItems('key2').Count); end; procedure TTestMultiMap.TestInterfaceMultiMapRemove; @@ -1668,10 +1712,10 @@ begin lMultiMap.Remove('not valid'); lMultiMap.Add('key1', TMyIntfObject.Create(1, 'value1')); lMultiMap.Add('key1', TMyIntfObject.Create(2, 'value2')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckTrue(lMultiMap.Contains('key1')); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.isTrue(lMultiMap.Contains('key1')); lMultiMap.Remove('key1'); - CheckFalse(lMultiMap.Contains('key1')); + Assert.isFalse(lMultiMap.Contains('key1')); end; procedure TTestMultiMap.TestObjectMultiMapAdd; @@ -1679,19 +1723,19 @@ var lMultiMap: IMVCObjectMultiMap; begin lMultiMap := TMVCObjectMultiMap.Create; - CheckEquals(0, Length(lMultiMap.Keys)); + Assert.areEqual(0, Length(lMultiMap.Keys)); lMultiMap.Clear; - CheckFalse(lMultiMap.Contains('key1')); + Assert.isFalse(lMultiMap.Contains('key1')); lMultiMap.Add('key1', TMyClass.Create(1, 'value1')); - CheckTrue(lMultiMap.Contains('key1')); - CheckEquals(1, lMultiMap.GetItems('key1').Count); + Assert.isTrue(lMultiMap.Contains('key1')); + Assert.areEqual(1, lMultiMap.GetItems('key1').Count); lMultiMap.Add('key1', TMyClass.Create(2, 'value2')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckEquals('value1', lMultiMap.GetItems('key1')[0].Description); - CheckEquals('value2', lMultiMap.GetItems('key1')[1].Description); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.areEqual('value1', lMultiMap.GetItems('key1')[0].Description); + Assert.areEqual('value2', lMultiMap.GetItems('key1')[1].Description); lMultiMap.Add('key2', TMyClass.Create(1, 'value3')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckEquals(1, lMultiMap.GetItems('key2').Count); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.areEqual(1, lMultiMap.GetItems('key2').Count); end; procedure TTestMultiMap.TestObjectMultiMapRemove; @@ -1702,18 +1746,18 @@ begin lMultiMap.Remove('not valid'); lMultiMap.Add('key1', TMyClass.Create(1, 'value1')); lMultiMap.Add('key1', TMyClass.Create(2, 'value2')); - CheckEquals(2, lMultiMap.GetItems('key1').Count); - CheckTrue(lMultiMap.Contains('key1')); + Assert.areEqual(2, lMultiMap.GetItems('key1').Count); + Assert.isTrue(lMultiMap.Contains('key1')); lMultiMap.Remove('key1'); - CheckFalse(lMultiMap.Contains('key1')); + Assert.isFalse(lMultiMap.Contains('key1')); end; initialization -RegisterTest(TTestRouting.suite); -// RegisterTest(TTestMappers.suite); -RegisterTest(TTestJWT.suite); -RegisterTest(TTestMultiMap.suite); +TDUnitX.RegisterTestFixture(TTestRouting); +// TDUnitX.RegisterTestFixture(TTestMappers); +TDUnitX.RegisterTestFixture(TTestJWT); +TDUnitX.RegisterTestFixture(TTestMultiMap); finalization diff --git a/unittests/general/Several/LiveServerTestU.pas b/unittests/general/Several/LiveServerTestU.pas index 1f5b9d82..fdb1ce18 100644 --- a/unittests/general/Several/LiveServerTestU.pas +++ b/unittests/general/Several/LiveServerTestU.pas @@ -27,7 +27,7 @@ unit LiveServerTestU; interface uses - TestFramework, + DUnitX.TestFramework, MVCFramework.RESTClient; const @@ -43,15 +43,18 @@ const {$ENDIF} type - TBaseServerTest = class(TTestCase) + [TestFixture] + TBaseServerTest = class(TObject) protected RESTClient: TRESTClient; procedure DoLoginWith(UserName: string); procedure DoLogout; protected - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; end; @@ -134,7 +137,7 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/logout', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Logout Failed'); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Logout Failed'); end; procedure TBaseServerTest.SetUp; @@ -155,10 +158,10 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/actionfilters/beforeaction/alwayscalled', []); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); res := RESTClient.doGET('/actionfilters/beforeaction/nevercalled', []); - CheckEquals(HTTP_STATUS.NotFound, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.NotFound, res.ResponseCode); end; procedure TServerTest.TestAsynchRequestDELETE; @@ -186,7 +189,7 @@ begin r := evt.WaitFor(2000); until r = TWaitResult.wrSignaled; - CheckEquals(true, OK); + Assert.areEqual(true, OK); finally evt.Free; end; @@ -220,8 +223,8 @@ begin r := evt.WaitFor(2000); until r = TWaitResult.wrSignaled; - CheckTrue(Assigned(j)); - CheckEquals('1', j.Get('par1').JsonValue.Value); + Assert.isTrue(Assigned(j)); + Assert.areEqual('1', j.Get('par1').JsonValue.Value); j.Free; finally evt.Free; @@ -259,8 +262,8 @@ begin r := evt.WaitFor(2000); until r = TWaitResult.wrSignaled; - CheckTrue(Assigned(j)); - CheckEquals('from server', j.Get('echo').JsonValue.Value); + Assert.isTrue(Assigned(j)); + Assert.areEqual('from server', j.Get('echo').JsonValue.Value); j.Free; finally evt.Free; @@ -296,8 +299,8 @@ begin r := evt.WaitFor(2000); until r = TWaitResult.wrSignaled; - CheckTrue(Assigned(j)); - CheckEquals('from server', j.Get('echo').JsonValue.Value); + Assert.isTrue(Assigned(j)); + Assert.areEqual('from server', j.Get('echo').JsonValue.Value); j.Free; finally evt.Free; @@ -309,10 +312,10 @@ var LRes: IRESTResponse; begin RESTClient.Authentication('user1', 'user1'); - CheckEquals('user1', RESTClient.UserName); - CheckEquals('user1', RESTClient.Password); + Assert.areEqual('user1', RESTClient.UserName); + Assert.areEqual('user1', RESTClient.Password); LRes := RESTClient.doGET('/private/role1', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); end; procedure TServerTest.TestBasicAuth02; @@ -323,7 +326,7 @@ begin RESTClient.Password := ''; RESTClient.UseBasicAuthentication := false; LRes := RESTClient.doGET('/private/role1', []); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode); end; procedure TServerTest.TestBasicAuth03; @@ -334,7 +337,7 @@ begin RESTClient.Password := 'user1'; RESTClient.UseBasicAuthentication := true; LRes := RESTClient.doGET('/private/role2', []); - CheckEquals(HTTP_STATUS.Forbidden, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.Forbidden, LRes.ResponseCode); end; procedure TServerTest.TestBasicAuth04; @@ -345,9 +348,9 @@ begin RESTClient.Password := 'user1'; RESTClient.UseBasicAuthentication := true; LRes := RESTClient.doGET('/private/role1', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); LRes := RESTClient.doGET('/people', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); end; procedure TServerTest.TestBasicAuth05; @@ -360,17 +363,17 @@ begin // first LRes := RESTClient.doGET('/private/role1session?value=danieleteti', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); LRes := RESTClient.doGET('/private/role1session', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); - CheckEquals('danieleteti', LRes.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual('danieleteti', LRes.BodyAsString); // second LRes := RESTClient.doGET('/private/role1session?value=johndoe', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); LRes := RESTClient.doGET('/private/role1session', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); - CheckEquals('johndoe', LRes.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual('johndoe', LRes.BodyAsString); end; procedure TServerTest.TestCookies; @@ -379,15 +382,15 @@ var I: Integer; begin res := RESTClient.doGET('/lotofcookies', []); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals(4, res.Cookies.Count, 'Wrong number of cookies'); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual(4, res.Cookies.Count, 'Wrong number of cookies'); for I := 0 to 3 do begin - CheckEquals('usersettings' + IntToStr(I + 1), + Assert.areEqual('usersettings' + IntToStr(I + 1), res.Cookies.Cookies[I].CookieName); - CheckEquals('usersettings' + IntToStr(I + 1) + '-value', + Assert.areEqual('usersettings' + IntToStr(I + 1) + '-value', res.Cookies.Cookies[I].Value); - CheckEquals('/usersettings' + IntToStr(I + 1), res.Cookies.Cookies[I].Path); + Assert.areEqual('/usersettings' + IntToStr(I + 1), res.Cookies.Cookies[I].Path); end; end; @@ -397,14 +400,14 @@ var LRes: IRESTResponse; begin LRes := RESTClient.doGET('/privatecustom/role1', []); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode); - CheckEquals('/system/users/logged', LRes.HeaderValue('X-LOGIN-URL')); - CheckEquals('POST', LRes.HeaderValue('X-LOGIN-METHOD')); + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode); + Assert.areEqual('/system/users/logged', LRes.HeaderValue('X-LOGIN-URL')); + Assert.areEqual('POST', LRes.HeaderValue('X-LOGIN-METHOD')); LRes := RESTClient.doGET('/privatecustom/role2', []); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode); - CheckEquals('/system/users/logged', LRes.HeaderValue('X-LOGIN-URL')); - CheckEquals('POST', LRes.HeaderValue('X-LOGIN-METHOD')); + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode); + Assert.areEqual('/system/users/logged', LRes.HeaderValue('X-LOGIN-URL')); + Assert.areEqual('POST', LRes.HeaderValue('X-LOGIN-METHOD')); end; procedure TServerTest.TestCustomAuthRequestsWithValidLogin; @@ -418,23 +421,23 @@ begin lJSON.AddPair('username', 'user1'); lJSON.AddPair('password', 'user1'); LRes := RESTClient.doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals('application/json', LRes.ContentType); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); - CheckEquals('/system/users/logged', LRes.HeaderValue('X-LOGOUT-URL')); - CheckEquals('DELETE', LRes.HeaderValue('X-LOGOUT-METHOD')); - CheckEquals('{"status":"OK"}', LRes.BodyAsString); + Assert.areEqual('application/json', LRes.ContentType); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual('/system/users/logged', LRes.HeaderValue('X-LOGOUT-URL')); + Assert.areEqual('DELETE', LRes.HeaderValue('X-LOGOUT-METHOD')); + Assert.areEqual('{"status":"OK"}', LRes.BodyAsString); lCookieValue := LRes.Cookies [LRes.Cookies.GetCookieIndex(TMVCConstants.SESSION_TOKEN_NAME)].Value; - CheckNotEquals('', lCookieValue, 'Session cookie not returned after login'); - CheckFalse(lCookieValue.Contains('invalid'), + Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); + Assert.isFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); LRes := RESTClient.doGET('/privatecustom/role2', []); - CheckEquals(HTTP_STATUS.Forbidden, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.Forbidden, LRes.ResponseCode, 'Authorization not respected for not allowed action'); LRes := RESTClient.doGET('/privatecustom/role1', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode, 'Authorization not respected for allowed action'); finally lJSON.Free; @@ -452,23 +455,23 @@ begin lJSON.AddPair('username', 'user1'); lJSON.AddPair('password', 'user1'); LRes := RESTClient.Accept('text/html').doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals('application/json', LRes.ContentType); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); - CheckEquals('/system/users/logged', LRes.HeaderValue('X-LOGOUT-URL')); - CheckEquals('DELETE', LRes.HeaderValue('X-LOGOUT-METHOD')); - CheckEquals('{"status":"OK"}', LRes.BodyAsString); + Assert.areEqual('application/json', LRes.ContentType); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual('/system/users/logged', LRes.HeaderValue('X-LOGOUT-URL')); + Assert.areEqual('DELETE', LRes.HeaderValue('X-LOGOUT-METHOD')); + Assert.areEqual('{"status":"OK"}', LRes.BodyAsString); lCookieValue := LRes.Cookies [LRes.Cookies.GetCookieIndex(TMVCConstants.SESSION_TOKEN_NAME)].Value; - CheckNotEquals('', lCookieValue, 'Session cookie not returned after login'); - CheckFalse(lCookieValue.Contains('invalid'), + Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); + Assert.isFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); LRes := RESTClient.doGET('/privatecustom/role2', []); - CheckEquals(HTTP_STATUS.Forbidden, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.Forbidden, LRes.ResponseCode, 'Authorization not respected for not allowed action'); LRes := RESTClient.doGET('/privatecustom/role1', []); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode, 'Authorization not respected for allowed action'); finally lJSON.Free; @@ -484,19 +487,19 @@ begin try // no request body LRes := RESTClient.doPOST('/system/users/logged', []); - CheckEquals(HTTP_STATUS.BadRequest, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.BadRequest, LRes.ResponseCode, 'Empty request body doesn''t return HTTP 400 Bad Request'); // wrong request body 1 LRes := RESTClient.doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode, 'Invalid json doesn''t return HTTP 401 Unauthorized'); // wrong request body 2 lJSON.AddPair('username', ''); lJSON.AddPair('password', ''); LRes := RESTClient.doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode, 'Empty username and password doesn''t return HTTP 401 Unauthorized'); // wrong username and password 3 @@ -505,7 +508,7 @@ begin lJSON.AddPair('username', 'notvaliduser'); lJSON.AddPair('password', 'notvalidpassword'); LRes := RESTClient.doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals(HTTP_STATUS.Unauthorized, LRes.ResponseCode, + Assert.areEqual(HTTP_STATUS.Unauthorized, LRes.ResponseCode, 'Wrong username and password doesn''t return HTTP 401 Unauthorized'); finally lJSON.Free; @@ -528,7 +531,7 @@ begin lJSON.AddPair('password', 'user1'); LRes := RESTClient.doPOST('/system/users/logged', [], TSystemJSON.JSONValueToString(lJSON, False)); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); lLogoutUrl := LRes.HeaderValue('X-LOGOUT-URL'); LRes := RESTClient.doDELETE(lLogoutUrl, []); @@ -548,7 +551,7 @@ begin end; end; end; - CheckTrue(lPass, 'No session cookie cleanup in the response'); + Assert.isTrue(lPass, 'No session cookie cleanup in the response'); finally lJSON.Free; end; @@ -565,17 +568,17 @@ begin lJSONObj := TSystemJSON.StringAsJSONObject(res.BodyAsString); s := lJSONObj.Get('name1').JsonValue.Value; - CheckEquals('jørn', s); + Assert.areEqual('jørn', s); lJSONObj.Free; lJSONObj := TSystemJSON.StringAsJSONObject(res.BodyAsString); s := lJSONObj.Get('name3').JsonValue.Value; - CheckEquals('àèéìòù', s); + Assert.areEqual('àèéìòù', s); lJSONObj.Free; lJSONObj := TSystemJSON.StringAsJSONObject(res.BodyAsString); s := lJSONObj.Get('name2').JsonValue.Value; - CheckEquals('Što je Unicode?', s, + Assert.areEqual('Što je Unicode?', s, 'If this test fail, check http://qc.embarcadero.com/wc/qcmain.aspx?d=119779'); lJSONObj.Free; { WARNING!!! } @@ -590,7 +593,7 @@ var LRes: IRESTResponse; begin LRes := RESTClient.doGET('/renderstreamandfreewithownerfalse', []); - CheckEquals(200, LRes.ResponseCode); + Assert.areEqual(200, LRes.ResponseCode); end; procedure TServerTest.TestRenderStreamAndFreeWithOwnerTrue; @@ -598,7 +601,7 @@ var LRes: IRESTResponse; begin LRes := RESTClient.doGET('/renderstreamandfreewithownertrue', []); - CheckEquals(200, LRes.ResponseCode); + Assert.areEqual(200, LRes.ResponseCode); end; procedure TServerTest.TestRenderWrappedList; @@ -615,7 +618,7 @@ begin for I := 0 to lJSONArr.Count - 1 do begin lJSONObj := lJSONArr.Items[I] as TJSONObject; - CheckFalse(lJSONObj.GetValue('firstname').IsEmpty); + Assert.isFalse(lJSONObj.GetValue('firstname').IsEmpty); end; finally lJSONArr.Free; @@ -628,7 +631,7 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/exception/aftercreate/nevercalled', []); - CheckEquals(HTTP_STATUS.InternalServerError, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.InternalServerError, res.ResponseCode); end; procedure TServerTest.TestExceptionInMVCBeforeDestroy; @@ -636,7 +639,7 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/exception/beforedestroy/nevercalled', []); - CheckEquals(HTTP_STATUS.InternalServerError, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.InternalServerError, res.ResponseCode); end; procedure TServerTest.TestInvalidateSession; @@ -649,10 +652,10 @@ begin c1.Accept(TMVCMediaType.APPLICATION_JSON); c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione res := c1.doGET('/session', []); // rileggo il valore dalla sessione - CheckEquals('daniele teti', res.BodyAsString); + Assert.areEqual('daniele teti', res.BodyAsString); c1.SessionID := ''; res := c1.doGET('/session', []); // rileggo il valore dalla sessione - CheckEquals('', res.BodyAsString); + Assert.areEqual('', res.BodyAsString); finally c1.Free; end; @@ -664,8 +667,8 @@ var begin r := RESTClient.Accept(TMVCMediaType.APPLICATION_JSON) .doGET('/handledbymiddleware', []); - CheckEquals('This is a middleware response', r.BodyAsString); - CheckEquals(HTTP_STATUS.OK, r.ResponseCode); + Assert.areEqual('This is a middleware response', r.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, r.ResponseCode); end; procedure TServerTest.TestMiddlewareSpeedMiddleware; @@ -685,7 +688,7 @@ begin P.Free; end; - CheckNotEquals('', r.HeaderValue('request_gen_time')); + Assert.AreNotEqual('', r.HeaderValue('request_gen_time')); end; // procedure TServerTest.TestPATCHWithParamsAndJSONBody; @@ -696,8 +699,8 @@ end; // json := TJSONObject.Create; // json.AddPair('client', 'clientdata'); // r := RESTClient.doPATCH('/echo', ['1', '2', '3'], json); -// CheckEquals('clientdata', r.BodyAsJsonObject.Get('client').JsonValue.Value); -// CheckEquals('from server', r.BodyAsJsonObject.Get('echo').JsonValue.Value); +// Assert.areEqual('clientdata', r.BodyAsJsonObject.Get('client').JsonValue.Value); +// Assert.areEqual('from server', r.BodyAsJsonObject.Get('echo').JsonValue.Value); // end; procedure TServerTest.TestPostAListOfObjects; @@ -711,7 +714,7 @@ begin GetDefaultSerializer.SerializeCollection(LCustomers) { Mapper.ObjectListToJSONArray(LCustomers) } ); - CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, LRes.ResponseCode); finally LCustomers.Free; end; @@ -735,7 +738,7 @@ begin { Mapper.ObjectToJSONObject(P) } ); except - Fail('If this test fail, check http://qc.embarcadero.com/wc/qcmain.aspx?d=119779'); + Assert.Fail('If this test fail, check http://qc.embarcadero.com/wc/qcmain.aspx?d=119779'); { WARNING!!! } { If this test fail, check @@ -752,10 +755,10 @@ begin try GetDefaultSerializer.DeserializeObject(r.BodyAsString, P); // P := Mapper.JSONObjectToObject(r.BodyAsJsonObject); - CheckEquals('Daniele', P.FirstName); - CheckEquals('àòùèéì', P.LastName); - CheckEquals(true, P.Married); - CheckEquals(EncodeDate(1979, 1, 1), P.DOB); + Assert.areEqual('Daniele', P.FirstName); + Assert.areEqual('àòùèéì', P.LastName); + Assert.areEqual(true, P.Married); + Assert.areEqual(EncodeDate(1979, 1, 1), P.DOB); finally P.Free; end; @@ -771,8 +774,8 @@ begin r := RESTClient.doPOST('/echo', ['1', '2', '3'], TSystemJSON.JSONValueToString(JSON)); JSON := TSystemJSON.StringAsJSONObject(r.BodyAsString); try - CheckEquals('clientdata', JSON.Get('client').JsonValue.Value); - CheckEquals('from server', JSON.Get('echo').JsonValue.Value); + Assert.areEqual('clientdata', JSON.Get('client').JsonValue.Value); + Assert.areEqual('from server', JSON.Get('echo').JsonValue.Value); finally JSON.Free; end; @@ -786,7 +789,7 @@ begin // action is waiting for a accept: application/json .ContentType('application/json').doPOST('/testconsumes', [], TSystemJSON.JSONValueToString(TJSONString.Create('Hello World'))); - CheckEquals(HTTP_STATUS.NotFound, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.NotFound, res.ResponseCode); end; procedure TServerTest.TestProducesConsumes01; @@ -796,10 +799,10 @@ begin res := RESTClient.Accept('application/json').ContentType('application/json') .ContentEncoding('utf-8').doPOST('/testconsumes', [], TSystemJSON.JSONValueToString(TJSONString.Create('Hello World'))); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals('Hello World', res.BodyAsString); - CheckEquals('application/json', res.ContentType); - CheckEquals('utf-8', res.ContentEncoding); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual('Hello World', res.BodyAsString); + Assert.areEqual('application/json', res.ContentType); + Assert.areEqual('utf-8', res.ContentEncoding); end; procedure TServerTest.TestProducesConsumes02; @@ -808,13 +811,13 @@ var begin res := RESTClient.Accept('text/plain').ContentType('text/plain') .doPOST('/testconsumes', [], 'Hello World'); - CheckEquals('Hello World', res.BodyAsString); - CheckEquals('text/plain', res.ContentType); - CheckEquals('UTF-8', res.ContentEncoding); + Assert.areEqual('Hello World', res.BodyAsString); + Assert.areEqual('text/plain', res.ContentType); + Assert.areEqual('UTF-8', res.ContentEncoding); res := RESTClient.Accept('text/plain').ContentType('application/json') .doPOST('/testconsumes', [], '{"name": "Daniele"}'); - CheckEquals(HTTP_STATUS.NotFound, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.NotFound, res.ResponseCode); end; procedure TServerTest.TestProducesConsumes03; @@ -827,10 +830,10 @@ begin .ContentEncoding('iso8859-1') .doPOST('/testconsumes/textiso8859_1', [], 'àèéìòù'); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals('àèéìòù', res.BodyAsString); - CheckEquals(TMVCMediaType.TEXT_PLAIN, res.ContentType); - CheckEquals('iso8859-1', res.ContentEncoding); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual('àèéìòù', res.BodyAsString); + Assert.areEqual(TMVCMediaType.TEXT_PLAIN, res.ContentType); + Assert.areEqual('iso8859-1', res.ContentEncoding); end; @@ -845,8 +848,8 @@ begin JSON := TSystemJSON.StringAsJSONObject(r.BodyAsString); try - CheckEquals('clientdata', JSON.Get('client').JsonValue.Value); - CheckEquals('from server', JSON.Get('echo').JsonValue.Value); + Assert.areEqual('clientdata', JSON.Get('client').JsonValue.Value); + Assert.areEqual('from server', JSON.Get('echo').JsonValue.Value); finally JSON.Free; end; @@ -863,39 +866,39 @@ begin ss := TStringStream.Create; try ss.CopyFrom(r.Body, 0); - CheckEquals(ss.DataString, r.BodyAsString, + Assert.areEqual(ss.DataString, r.BodyAsString, 'In case of rotocol error, the body doesn''t contain the same of BodyAsString'); finally ss.Free; end; - CheckEquals(HTTP_STATUS.NotFound, r.ResponseCode, '/unknownurl/bla/bla'); + Assert.areEqual(HTTP_STATUS.NotFound, r.ResponseCode, '/unknownurl/bla/bla'); r := RESTClient.doGET('/req/with/params/', []); - CheckEquals(HTTP_STATUS.NotFound, r.ResponseCode, '/req/with/params/'); + Assert.areEqual(HTTP_STATUS.NotFound, r.ResponseCode, '/req/with/params/'); r := RESTClient.doGET('/req/with/params', []); - CheckEquals(HTTP_STATUS.NotFound, r.ResponseCode, '/req/with/params'); + Assert.areEqual(HTTP_STATUS.NotFound, r.ResponseCode, '/req/with/params'); r := RESTClient.doGET('/req/with/params', ['1', '2', '3']); - CheckEquals(HTTP_STATUS.OK, r.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, r.ResponseCode); lJSON := TSystemJSON.StringAsJSONObject(r.BodyAsString); try - CheckEquals('1', lJSON.Get('par1').JsonValue.Value); - CheckEquals('2', lJSON.Get('par2').JsonValue.Value); - CheckEquals('3', lJSON.Get('par3').JsonValue.Value); - CheckEquals('GET', lJSON.Get('method').JsonValue.Value); + Assert.areEqual('1', lJSON.Get('par1').JsonValue.Value); + Assert.areEqual('2', lJSON.Get('par2').JsonValue.Value); + Assert.areEqual('3', lJSON.Get('par3').JsonValue.Value); + Assert.areEqual('GET', lJSON.Get('method').JsonValue.Value); r := RESTClient.doPOST('/req/with/params', ['1', '2', '3']); - CheckEquals(HTTP_STATUS.NotFound, r.ResponseCode); + Assert.areEqual(HTTP_STATUS.NotFound, r.ResponseCode); r := RESTClient.doPUT('/req/with/params', ['1', '2', '3']); - CheckEquals(HTTP_STATUS.NotFound, r.ResponseCode); + Assert.areEqual(HTTP_STATUS.NotFound, r.ResponseCode); r := RESTClient.doDELETE('/req/with/params', ['1', '2', '3']); - CheckEquals(HTTP_STATUS.OK, r.ResponseCode); - CheckEquals('', r.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, r.ResponseCode); + Assert.areEqual('', r.BodyAsString); finally lJSON.Free; end; @@ -913,9 +916,9 @@ end; // LResp := RESTClient.doGET('/people', ['1', 'asfields']); // LObj := Mapper.JSONObjectFieldsToObject(LResp.BodyAsJsonObject); // try -// CheckEquals('BusinessObjectsU.TPerson', LObj.QualifiedClassName); +// Assert.areEqual('BusinessObjectsU.TPerson', LObj.QualifiedClassName); // LPersonFlds := TPerson(LObj); -// CheckTrue(LPersonFlds.Equals(LPersonProps), +// Assert.isTrue(LPersonFlds.Equals(LPersonProps), // 'Object tranferred using field serialization is different from the object serialized in the default way'); // finally // LObj.Free; @@ -936,20 +939,20 @@ begin c1.Accept(TMVCMediaType.APPLICATION_JSON); res := c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione s := res.HeaderValue('Set-Cookie'); - CheckFalse(s.Contains('Expires'), 'Session cookie contains "expires" attribute'); + Assert.isFalse(s.Contains('Expires'), 'Session cookie contains "expires" attribute'); res := c1.doGET('/session', []); // rileggo il valore dalla sessione - CheckEquals('daniele teti', res.BodyAsString); + Assert.areEqual('daniele teti', res.BodyAsString); c1.Accept(TMVCMediaType.TEXT_PLAIN); res := c1.doGET('/session', []); // rileggo il valore dalla sessione - CheckEquals('daniele teti', res.BodyAsString); + Assert.areEqual('daniele teti', res.BodyAsString); // aggiungo altri cookies res := c1.doGET('/lotofcookies', []); // rileggo il valore dalla sessione - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); c1.Accept(TMVCMediaType.TEXT_PLAIN); res := c1.doGET('/session', []); // rileggo il valore dalla sessione - CheckEquals('daniele teti', res.BodyAsString); + Assert.areEqual('daniele teti', res.BodyAsString); finally c1.Free; end; @@ -969,19 +972,19 @@ begin // ----------------------'/typed/all/($ParString)/($ParInteger)/($ParInt64)/($ParSingle)/($ParDouble)/($ParExtended)')', []); res := RESTClient.doGET ('/typed/all/mystring/1234/12345678/12.3/1234.5678/1234.5678', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); lJObj := TSystemJSON.StringAsJSONObject(res.BodyAsString); try - CheckEquals('mystring', lJObj.GetValue('ParString').Value, 'ParString'); - CheckEquals(1234, TJSONNumber(lJObj.GetValue('ParInteger')).AsInt, + Assert.areEqual('mystring', lJObj.GetValue('ParString').Value, 'ParString'); + Assert.areEqual(1234, TJSONNumber(lJObj.GetValue('ParInteger')).AsInt, 'ParInteger'); - CheckEquals(12345678, TJSONNumber(lJObj.GetValue('ParInt64')).AsInt64, + Assert.areEqual(int64(12345678), TJSONNumber(lJObj.GetValue('ParInt64')).AsInt64, 'ParInt64'); - CheckEquals(12.3, RoundTo(TJSONNumber(lJObj.GetValue('ParSingle')).AsDouble, + Assert.areEqual(12.3, RoundTo(TJSONNumber(lJObj.GetValue('ParSingle')).AsDouble, -1), 'ParSingle'); - CheckEquals(1234.5678, RoundTo(TJSONNumber(lJObj.GetValue('ParDouble')) + Assert.areEqual(1234.5678, RoundTo(TJSONNumber(lJObj.GetValue('ParDouble')) .AsDouble, -4), 'ParDouble'); - CheckEquals(1234.5678, RoundTo(TJSONNumber(lJObj.GetValue('ParExtended')) + Assert.areEqual(1234.5678, RoundTo(TJSONNumber(lJObj.GetValue('ParExtended')) .AsDouble, -4), 'ParExtended'); finally lJObj.Free; @@ -993,8 +996,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/booleans/true/false/1/0', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('true.false.true.false', res.BodyAsString.ToLower); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('true.false.true.false', res.BodyAsString.ToLower); end; procedure TServerTest.TestTypedDouble1; @@ -1002,8 +1005,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/double1/1234.5678', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('1234.5678 modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('1234.5678 modified from server', res.BodyAsString); end; @@ -1012,8 +1015,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/extended1/1234.5678', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('1234.5678 modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('1234.5678 modified from server', res.BodyAsString); end; @@ -1022,8 +1025,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/int641/12345678', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('12345678 modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('12345678 modified from server', res.BodyAsString); end; procedure TServerTest.TestTypedInteger1; @@ -1031,8 +1034,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/integer1/1234', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('1234 modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('1234 modified from server', res.BodyAsString); end; procedure TServerTest.TestTypedSingle1; @@ -1040,8 +1043,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/single1/1234.5', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('1234.5 modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('1234.5 modified from server', res.BodyAsString); end; @@ -1050,8 +1053,8 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/typed/string1/daniele', []); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); - CheckEquals('daniele modified from server', res.BodyAsString); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Cannot route'); + Assert.areEqual('daniele modified from server', res.BodyAsString); end; procedure TServerTest.TestTypedDateTimeTypes; @@ -1060,28 +1063,28 @@ var begin // TDate, wrong and correct res := RESTClient.doGET('/typed/tdate1/20161012', []); - CheckEquals(HTTP_STATUS.InternalServerError, res.ResponseCode, 'wrong TDate'); + Assert.areEqual(HTTP_STATUS.InternalServerError, res.ResponseCode, 'wrong TDate'); res := RESTClient.doGET('/typed/tdate1/2016-10-12', []); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals('2016-10-12 modified from server', res.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual('2016-10-12 modified from server', res.BodyAsString); // TDateTime, wrong and correct res := RESTClient.doGET('/typed/tdatetime1/20161012121212', []); - CheckEquals(HTTP_STATUS.InternalServerError, res.ResponseCode, + Assert.areEqual(HTTP_STATUS.InternalServerError, res.ResponseCode, 'wrong TDateTime'); res := RESTClient.doGET('/typed/tdatetime1/2016-10-12 12:12:12', []); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals('2016-10-12 12:12:12 modified from server', res.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual('2016-10-12 12:12:12 modified from server', res.BodyAsString); // TTime, wrong and correct res := RESTClient.doGET('/typed/ttime1/121212', []); - CheckEquals(HTTP_STATUS.InternalServerError, res.ResponseCode, 'wrong TTime'); + Assert.areEqual(HTTP_STATUS.InternalServerError, res.ResponseCode, 'wrong TTime'); res := RESTClient.doGET('/typed/ttime1/12:12:12', []); - CheckEquals(HTTP_STATUS.OK, res.ResponseCode); - CheckEquals('12:12:12 modified from server', res.BodyAsString); + Assert.areEqual(HTTP_STATUS.OK, res.ResponseCode); + Assert.areEqual('12:12:12 modified from server', res.BodyAsString); end; @@ -1090,11 +1093,11 @@ var res: IRESTResponse; begin res := RESTClient.doGET('/login', [UserName]); - CheckTrue(res.ResponseCode = HTTP_STATUS.OK, 'Login Failed'); + Assert.isTrue(res.ResponseCode = HTTP_STATUS.OK, 'Login Failed'); end; initialization -RegisterTest(TServerTest.Suite); +TDUnitX.RegisterTestFixture(TServerTest); end. diff --git a/unittests/general/Several/MessagingExtensionsTestU.pas b/unittests/general/Several/MessagingExtensionsTestU.pas index e2b4b5d7..5b58bd21 100644 --- a/unittests/general/Several/MessagingExtensionsTestU.pas +++ b/unittests/general/Several/MessagingExtensionsTestU.pas @@ -27,7 +27,7 @@ unit MessagingExtensionsTestU; interface uses - TestFramework, + DUnitX.TestFramework, MVCFramework.RESTClient, LiveServerTestU; { @@ -236,7 +236,7 @@ initialization {$IFDEF USE_MESSAGING} - RegisterTest(TMessagingExtensionsTestCase.Suite); + TDUnitX.RegisterTestFixture(TMessagingExtensionsTestCase); {$ENDIF} diff --git a/unittests/general/Several/RESTAdapterTestsU.pas b/unittests/general/Several/RESTAdapterTestsU.pas index 73ee2ba2..f3585d62 100644 --- a/unittests/general/Several/RESTAdapterTestsU.pas +++ b/unittests/general/Several/RESTAdapterTestsU.pas @@ -29,7 +29,7 @@ unit RESTAdapterTestsU; interface uses - MVCFramework.RESTAdapter, TestFramework, BusinessObjectsU, + MVCFramework.RESTAdapter, DUnitX.TestFramework, BusinessObjectsU, Generics.Collections, MVCFramework.TypesAliases, MVCFramework.RESTClient, @@ -84,22 +84,34 @@ type end; - TTestRESTAdapter = class(TTestCase) + [TestFixture] + TTestRESTAdapter = class(TObject) private RESTAdapter: TRESTAdapter; TESTService: ITESTService; protected - procedure SetUp; override; + [SetUp] + procedure SetUp; published + [Test] procedure TestGetPeople; + [Test] procedure TestGetPeopleAsynch; + [Test] procedure TestGetTonyStark; + [Test] procedure TestGetTonyStarkAsynch; + [Test] procedure TestPostPerson; + [Test] procedure TestGetPersonByID; + [Test] procedure TestHeadersApplicationJSON; + [Test] procedure TestHeadersTextPlain; + [Test] procedure TestApplicationJSONWithHeaderTextPlain; + [Test] procedure TestGetPersonInJSONArray; end; @@ -122,9 +134,9 @@ var begin; Person := TESTService.GetPersonByID(1); try - CheckEquals('Tony', Person.FirstName); - CheckEquals('Stark', Person.LastName); - CheckTrue(Person.Married); + Assert.AreEqual('Tony', Person.FirstName); + Assert.AreEqual('Stark', Person.LastName); + Assert.isTrue(Person.Married); finally Person.Free; end; @@ -136,10 +148,10 @@ var begin JSONArray := TESTService.GetPersonInJSONArray; try - CheckTrue(JSONArray.ToString.Contains('Tony')); - CheckTrue(JSONArray.ToString.Contains('Stark')); - CheckTrue(JSONArray.ToString.Contains('Bruce')); - CheckTrue(JSONArray.ToString.Contains('Banner')); + Assert.isTrue(JSONArray.ToString.Contains('Tony')); + Assert.isTrue(JSONArray.ToString.Contains('Stark')); + Assert.isTrue(JSONArray.ToString.Contains('Bruce')); + Assert.isTrue(JSONArray.ToString.Contains('Banner')); finally JSONArray.Free; end; @@ -151,9 +163,9 @@ var begin; Person := TESTService.GetTonyStark; try - CheckEquals('Tony', Person.FirstName); - CheckEquals('Stark', Person.LastName); - CheckTrue(Person.Married); + Assert.AreEqual('Tony', Person.FirstName); + Assert.AreEqual('Stark', Person.LastName); + Assert.isTrue(Person.Married); finally Person.Free; end; @@ -175,12 +187,12 @@ begin end); TESTService.GetTonyStarkAsynch(AsynchRequest); // attend for max 5 seconds - CheckTrue(TWaitResult.wrSignaled = LEvt.WaitFor(5000), 'Timeout request'); - CheckNotNull(Person); + Assert.isTrue(TWaitResult.wrSignaled = LEvt.WaitFor(5000), 'Timeout request'); + Assert.IsNotNull(Person); try - CheckEquals('Tony', Person.FirstName); - CheckEquals('Stark', Person.LastName); - CheckTrue(Person.Married); + Assert.AreEqual('Tony', Person.FirstName); + Assert.AreEqual('Stark', Person.LastName); + Assert.isTrue(Person.Married); finally Person.Free; end; @@ -195,7 +207,7 @@ var begin Res := TESTService.HeadersApplicationJSON as TJSONObject; try - CheckEquals('Hello World', Res.GetValue('key').Value); + Assert.AreEqual('Hello World', Res.GetValue('key').Value); finally Res.Free; end; @@ -206,7 +218,7 @@ var Res: string; begin Res := TESTService.HeadersTextPlain; - CheckEquals('Hello World', Res); + Assert.AreEqual('Hello World', Res); end; procedure TTestRESTAdapter.TestPostPerson; @@ -217,9 +229,9 @@ begin Person := TPerson.GetNew('Peter', 'Parker', 0, false); RetPerson := TESTService.SendPerson(Person); try - CheckEquals('Peter', RetPerson.FirstName); - CheckEquals('Parker', RetPerson.LastName); - CheckFalse(RetPerson.Married); + Assert.AreEqual('Peter', RetPerson.FirstName); + Assert.AreEqual('Parker', RetPerson.LastName); + Assert.IsFalse(RetPerson.Married); finally RetPerson.Free; end; @@ -231,7 +243,7 @@ var begin // expected 404 because is not consumed text/plain Resp := TESTService.ApplicationJSONWithTextPlainHeader; - CheckEquals(404, Resp.ResponseCode); + Assert.AreEqual(404, Resp.ResponseCode); end; procedure TTestRESTAdapter.TestGetPeople; @@ -240,9 +252,9 @@ var begin ListPerson := TESTService.GetPeople; try - CheckTrue(ListPerson.Count > 0); - CheckEquals('Tony', ListPerson[0].FirstName); - CheckEquals('Stark', ListPerson[0].LastName); + Assert.isTrue(ListPerson.Count > 0); + Assert.AreEqual('Tony', ListPerson[0].FirstName); + Assert.AreEqual('Stark', ListPerson[0].LastName); finally ListPerson.Free; end; @@ -265,12 +277,12 @@ begin TESTService.GetPeopleAsynch(AsynchRequest); // attend for max 5 seconds - CheckTrue(TWaitResult.wrSignaled = LEvt.WaitFor(5000), 'Timeout request'); - CheckNotNull(People); + Assert.isTrue(TWaitResult.wrSignaled = LEvt.WaitFor(5000), 'Timeout request'); + Assert.IsNotNull(People); try - CheckTrue(People.Count > 0); - CheckEquals('Tony', People[0].FirstName); - CheckEquals('Stark', People[0].LastName); + Assert.isTrue(People.Count > 0); + Assert.AreEqual('Tony', People[0].FirstName); + Assert.AreEqual('Stark', People[0].LastName); finally People.Free; end; @@ -281,7 +293,7 @@ end; initialization -RegisterTest(TTestRESTAdapter.suite); +TDUnitX.RegisterTestFixture(TTestRESTAdapter); finalization diff --git a/unittests/general/StandaloneServer/MVCFramework.Tests.StandaloneServer.pas b/unittests/general/StandaloneServer/MVCFramework.Tests.StandaloneServer.pas index 4931818d..c898904c 100644 --- a/unittests/general/StandaloneServer/MVCFramework.Tests.StandaloneServer.pas +++ b/unittests/general/StandaloneServer/MVCFramework.Tests.StandaloneServer.pas @@ -3,7 +3,7 @@ unit MVCFramework.Tests.StandaloneServer; interface uses - TestFramework, + DUnitX.TestFramework, System.Classes, System.SysUtils, System.Generics.Collections, @@ -22,15 +22,22 @@ type procedure HelloWorld(ctx: TWebContext); end; - TTestMVCFrameworkServer = class(TTestCase) + + [TestFixture] + TTestMVCFrameworkServer = class(TObject) private protected - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published + [Test] procedure TestListener; + [Test] procedure TestListenerContext; + [Test] procedure TestServerListenerAndClient; end; @@ -65,13 +72,13 @@ begin .SetWebModuleClass(TestWebModuleClass) ); - CheckTrue(Assigned(LListener)); + Assert.isTrue(Assigned(LListener)); LListener.Start; - CheckTrue(LListener.Active); + Assert.isTrue(LListener.Active); LListener.Stop; - CheckFalse(LListener.Active); + Assert.isFalse(LListener.Active); end; procedure TTestMVCFrameworkServer.TestServerListenerAndClient; @@ -86,22 +93,22 @@ begin .SetWebModuleClass(TestWebModuleClass) ); - CheckTrue(Assigned(LListener)); + Assert.isTrue(Assigned(LListener)); LListener.Start; - CheckTrue(LListener.Active); + Assert.isTrue(LListener.Active); LClient := TRESTClient.Create('localhost', 6000); try LClient.UserName := 'dmvc'; LClient.Password := '123'; - CheckEqualsString('Hello World called with GET', LClient.doGET('/hello', []).BodyAsString); + Assert.AreEqual('Hello World called with GET', LClient.doGET('/hello', []).BodyAsString); finally FreeAndNil(LClient); end; LListener.Stop; - CheckFalse(LListener.Active); + Assert.isFalse(LListener.Active); end; procedure TTestMVCFrameworkServer.TestListenerContext; @@ -124,25 +131,25 @@ begin .SetWebModuleClass(TestWebModuleClass2) ); - CheckTrue(Assigned(LListenerCtx.FindByName('Listener2'))); - CheckTrue(Assigned(LListenerCtx.FindByName('Listener3'))); + Assert.isTrue(Assigned(LListenerCtx.FindByName('Listener2'))); + Assert.isTrue(Assigned(LListenerCtx.FindByName('Listener3'))); LListenerCtx.StartAll; - CheckTrue(LListenerCtx.Count = 2); - CheckTrue(LListenerCtx.FindByName('Listener2').Active); - CheckTrue(LListenerCtx.FindByName('Listener3').Active); + Assert.isTrue(LListenerCtx.Count = 2); + Assert.isTrue(LListenerCtx.FindByName('Listener2').Active); + Assert.isTrue(LListenerCtx.FindByName('Listener3').Active); LListenerCtx.StopAll; - CheckFalse(LListenerCtx.FindByName('Listener2').Active); - CheckFalse(LListenerCtx.FindByName('Listener3').Active); + Assert.isFalse(LListenerCtx.FindByName('Listener2').Active); + Assert.isFalse(LListenerCtx.FindByName('Listener3').Active); LListenerCtx .Remove('Listener2') .Remove('Listener3'); - CheckTrue(LListenerCtx.Count = 0); + Assert.isTrue(LListenerCtx.Count = 0); end; { TTestController } @@ -154,6 +161,6 @@ end; initialization -RegisterTest(TTestMVCFrameworkServer.Suite); +TDUnitX.RegisterTestFixture(TTestMVCFrameworkServer); end. diff --git a/unittests/serializer/jsondataobjects/MVCFramework.Tests.Serializer.JsonDataObjects.pas b/unittests/serializer/jsondataobjects/MVCFramework.Tests.Serializer.JsonDataObjects.pas index bd7773ad..1015e4dc 100644 --- a/unittests/serializer/jsondataobjects/MVCFramework.Tests.Serializer.JsonDataObjects.pas +++ b/unittests/serializer/jsondataobjects/MVCFramework.Tests.Serializer.JsonDataObjects.pas @@ -29,7 +29,7 @@ unit MVCFramework.Tests.Serializer.JsonDataObjects; interface uses - TestFramework, + DUnitX.TestFramework, System.Rtti, System.Classes, System.SysUtils, @@ -45,32 +45,52 @@ uses type - TMVCTestSerializerJsonDataObjects = class(TTestCase, IMVCTestSerializer) + [TestFixture] + TMVCTestSerializerJsonDataObjects = class(TObject) private FSerializer: IMVCSerializer; protected - procedure SetUp; override; - procedure TearDown; override; + [Setup] + procedure SetUp; + [TearDown] + procedure TearDown; published { serialize declarations } + [Test] procedure TestSerializeEntity; + [Test] procedure TestSerializeNil; + [Test] procedure TestSerializeEntityUpperCaseNames; + [Test] procedure TestSerializeEntityLowerCaseNames; + [Test] procedure TestSerializeEntityNameAs; + [Test] procedure TestSerializeEntityCustomSerializer; + [Test] procedure TestSerializeEntityCustomMemberSerializer; + [Test] procedure TestSerializeEntitySerializationType; + [Test] procedure TestSerializeCollection; + [Test] procedure TestSerializeDataSet; { deserialize declarations } + [Test] procedure TestDeserializeEntity; + [Test] procedure TestDeserializeEntityCustomSerializer; + [Test] procedure TestDeserializeEntityCustomMemberSerializer; + [Test] procedure TestDeserializeEntitySerializationType; + [Test] procedure TestDeserializeCollection; + [Test] procedure TestDeserializeDataSet; { full cycle } + [Test] procedure TestSerializeDeSerializeEntityWithEnums; end; @@ -109,11 +129,11 @@ procedure TMVCTestSerializerJsonDataObjects.TestDeserializeCollection; procedure CheckObjectList(const AList: TObjectList); begin - CheckTrue(AList.Count = 4); - CheckTrue(AList.Items[0].Description = 'Description 1'); - CheckTrue(AList.Items[1].Description = 'Description 2'); - CheckTrue(AList.Items[2].Description = 'Description 3'); - CheckTrue(AList.Items[3].Description = 'Description 4'); + Assert.isTrue(AList.Count = 4); + Assert.isTrue(AList.Items[0].Description = 'Description 1'); + Assert.isTrue(AList.Items[1].Description = 'Description 2'); + Assert.isTrue(AList.Items[2].Description = 'Description 3'); + Assert.isTrue(AList.Items[3].Description = 'Description 4'); end; const @@ -232,53 +252,53 @@ begin Dm := TEntitiesModule.Create(nil); try FSerializer.DeserializeDataSetRecord(JSON, Dm.Entity, ['Ignored']); - CheckTrue(Dm.EntityId.AsLargeInt = 1); - CheckTrue(Dm.EntityCode.AsInteger = 2); - CheckTrue(Dm.EntityName.AsString = 'Ezequiel Juliano Müller'); - CheckTrue(Dm.EntityBirthday.AsDateTime = StrToDate('15/10/1987')); - CheckTrue(Dm.EntityAccessDateTime.AsDateTime = StrToDateTime('17/02/2017 16:37:50')); - CheckTrue(Dm.EntityAccessTime.AsDateTime = StrToTime('16:40:50')); - CheckTrue(Dm.EntityActive.AsBoolean = True); - CheckTrue(Dm.EntitySalary.AsCurrency = 100); - CheckTrue(Dm.EntityAmount.AsFloat = 100); - CheckTrue(Dm.EntityBlobFld.AsString = '

BLOB

'); + Assert.isTrue(Dm.EntityId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityCode.AsInteger = 2); + Assert.isTrue(Dm.EntityName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityBirthday.AsDateTime = StrToDate('15/10/1987')); + Assert.isTrue(Dm.EntityAccessDateTime.AsDateTime = StrToDateTime('17/02/2017 16:37:50')); + Assert.isTrue(Dm.EntityAccessTime.AsDateTime = StrToTime('16:40:50')); + Assert.isTrue(Dm.EntityActive.AsBoolean = True); + Assert.isTrue(Dm.EntitySalary.AsCurrency = 100); + Assert.isTrue(Dm.EntityAmount.AsFloat = 100); + Assert.isTrue(Dm.EntityBlobFld.AsString = '

BLOB

'); Dm.Item.First; - CheckTrue(Dm.ItemId.AsLargeInt = 1); - CheckTrue(Dm.ItemName.AsString = 'Ezequiel'); + Assert.isTrue(Dm.ItemId.AsLargeInt = 1); + Assert.isTrue(Dm.ItemName.AsString = 'Ezequiel'); Dm.Item.Next; - CheckTrue(Dm.ItemId.AsLargeInt = 2); - CheckTrue(Dm.ItemName.AsString = 'Juliano'); + Assert.isTrue(Dm.ItemId.AsLargeInt = 2); + Assert.isTrue(Dm.ItemName.AsString = 'Juliano'); Dm.Departament.First; - CheckTrue(Dm.DepartamentName.AsString = 'Depto1'); + Assert.isTrue(Dm.DepartamentName.AsString = 'Depto1'); FSerializer.DeserializeDataSetRecord(JSON_LOWERCASE, Dm.EntityLowerCase); - CheckTrue(Dm.EntityLowerCaseId.AsLargeInt = 1); - CheckTrue(Dm.EntityLowerCaseName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityLowerCaseId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityLowerCaseName.AsString = 'Ezequiel Juliano Müller'); FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase); - CheckTrue(Dm.EntityUpperCaseId.AsLargeInt = 1); - CheckTrue(Dm.EntityUpperCaseName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityUpperCaseId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityUpperCaseName.AsString = 'Ezequiel Juliano Müller'); FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase2, [], ncUpperCase); - CheckTrue(Dm.EntityUpperCase2Id.AsLargeInt = 1); - CheckTrue(Dm.EntityUpperCase2Name.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityUpperCase2Id.AsLargeInt = 1); + Assert.isTrue(Dm.EntityUpperCase2Name.AsString = 'Ezequiel Juliano Müller'); FSerializer.DeserializeDataSetRecord(JSON_ASIS, Dm.EntityAsIs); - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 1); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); Dm.EntityAsIs.EmptyDataSet; FSerializer.DeserializeDataSet(JSON_LIST, Dm.EntityAsIs); Dm.EntityAsIs.First; - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 1); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); Dm.EntityAsIs.Next; - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 2); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 2); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller'); finally Dm.Free; end; @@ -288,26 +308,26 @@ procedure TMVCTestSerializerJsonDataObjects.TestDeserializeEntity; procedure CheckObject(const AEntity: TEntity); begin - CheckTrue(AEntity.Id = 1); - CheckTrue(AEntity.Code = 2); - CheckTrue(AEntity.Name = 'Ezequiel Juliano Müller'); - CheckTrue(AEntity.Salary = 100); - CheckTrue(DateToStr(AEntity.Birthday) = '15/10/1987'); - CheckTrue(DateTimeToStr(AEntity.AccessDateTime) = '17/02/2017 16:37:50'); - CheckTrue(TimeToStr(AEntity.AccessTime) = '16:40:50'); - CheckTrue(AEntity.Active = True); - CheckTrue(AEntity.Role = TRole.roGuest); - CheckTrue(DateTimeToStr(TimeStampToDateTime(AEntity.Teporization)) = '17/02/2017 16:37:50'); - CheckTrue(AEntity.Department <> nil); - CheckTrue(AEntity.Department.Id = 1); - CheckTrue(AEntity.Department.Name = 'Development'); - CheckTrue(AEntity.DepartmentNull = nil); - CheckTrue(AEntity.Notes.Count = 2); - CheckTrue(AEntity.Notes[0].Description = 'EntNote1'); - CheckTrue(AEntity.Notes[1].Description = 'EntNote2'); - CheckTrue(AEntity.NotesEmpty.Count = 0); - CheckTrue(AEntity.AppreciationAs.AsString = 'Yes'); - CheckTrue(AEntity.Appreciation.AsString = 'Yes'); + Assert.isTrue(AEntity.Id = 1); + Assert.isTrue(AEntity.Code = 2); + Assert.isTrue(AEntity.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(AEntity.Salary = 100); + Assert.isTrue(DateToStr(AEntity.Birthday) = '15/10/1987'); + Assert.isTrue(DateTimeToStr(AEntity.AccessDateTime) = '17/02/2017 16:37:50'); + Assert.isTrue(TimeToStr(AEntity.AccessTime) = '16:40:50'); + Assert.isTrue(AEntity.Active = True); + Assert.isTrue(AEntity.Role = TRole.roGuest); + Assert.isTrue(DateTimeToStr(TimeStampToDateTime(AEntity.Teporization)) = '17/02/2017 16:37:50'); + Assert.isTrue(AEntity.Department <> nil); + Assert.isTrue(AEntity.Department.Id = 1); + Assert.isTrue(AEntity.Department.Name = 'Development'); + Assert.isTrue(AEntity.DepartmentNull = nil); + Assert.isTrue(AEntity.Notes.Count = 2); + Assert.isTrue(AEntity.Notes[0].Description = 'EntNote1'); + Assert.isTrue(AEntity.Notes[1].Description = 'EntNote2'); + Assert.isTrue(AEntity.NotesEmpty.Count = 0); + Assert.isTrue(AEntity.AppreciationAs.AsString = 'Yes'); + Assert.isTrue(AEntity.Appreciation.AsString = 'Yes'); end; const @@ -430,11 +450,11 @@ begin O := TSale.Create; try FSerializer.DeserializeObject(JSON, O); - CheckTrue(O.Entity.Id = 1); - CheckTrue(O.Entity.Code = 2); - CheckTrue(O.Entity.Name = 'Ezequiel Juliano Müller'); - CheckTrue(O.Notes.DataString = 'Ezequiel Juliano Müller'); - CheckTrue(O.NotesAsString.DataString = 'Ezequiel Juliano Müller'); + Assert.isTrue(O.Entity.Id = 1); + Assert.isTrue(O.Entity.Code = 2); + Assert.isTrue(O.Entity.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(O.Notes.DataString = 'Ezequiel Juliano Müller'); + Assert.isTrue(O.NotesAsString.DataString = 'Ezequiel Juliano Müller'); finally O.Free; end; @@ -454,9 +474,9 @@ begin O := TEntityCustom.Create; try FSerializer.DeserializeObject(JSON, O); - CheckTrue(O.Id = 1); - CheckTrue(O.Code = 2); - CheckTrue(O.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(O.Id = 1); + Assert.isTrue(O.Code = 2); + Assert.isTrue(O.Name = 'Ezequiel Juliano Müller'); finally O.Free; end; @@ -484,9 +504,9 @@ begin OFields := TEntitySerializeFields.Create; try FSerializer.DeserializeObject(JSON_FIELDS, OFields); - CheckTrue(OFields.Id = 1); - CheckTrue(OFields.Code = 2); - CheckTrue(OFields.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(OFields.Id = 1); + Assert.isTrue(OFields.Code = 2); + Assert.isTrue(OFields.Name = 'Ezequiel Juliano Müller'); finally OFields.Free; end; @@ -494,9 +514,9 @@ begin OProperties := TEntitySerializeProperties.Create; try FSerializer.DeserializeObject(JSON_PROPERTIES, OProperties); - CheckTrue(OProperties.Id = 1); - CheckTrue(OProperties.Code = 2); - CheckTrue(OProperties.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(OProperties.Id = 1); + Assert.isTrue(OProperties.Code = 2); + Assert.isTrue(OProperties.Name = 'Ezequiel Juliano Müller'); finally OProperties.Free; end; @@ -547,10 +567,10 @@ begin O.Add(TNote.Create('Description 4')); S := FSerializer.SerializeCollection(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); S := FSerializer.SerializeCollection(O, stFields); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); finally O.Free; end; @@ -648,42 +668,42 @@ begin Dm.Entity.Post; S := FSerializer.SerializeDataSetRecord(Dm.Entity, ['Ignored'], ncAsIs); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); Dm.EntityLowerCase.Insert; Dm.EntityLowerCaseId.AsLargeInt := 1; Dm.EntityLowerCaseName.AsString := 'Ezequiel Juliano Müller'; Dm.EntityLowerCase.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityLowerCase); - CheckEqualsString(JSON_LOWERCASE, S); + Assert.areEqual(JSON_LOWERCASE, S); Dm.EntityUpperCase.Insert; Dm.EntityUpperCaseId.AsLargeInt := 1; Dm.EntityUpperCaseName.AsString := 'Ezequiel Juliano Müller'; Dm.EntityUpperCase.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase); - CheckEqualsString(JSON_UPPERCASE, S); + Assert.areEqual(JSON_UPPERCASE, S); Dm.EntityUpperCase2.Insert; Dm.EntityUpperCase2Id.AsLargeInt := 1; Dm.EntityUpperCase2Name.AsString := 'Ezequiel Juliano Müller'; Dm.EntityUpperCase2.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase2, [], ncUpperCase); - CheckEqualsString(JSON_UPPERCASE, S); + Assert.areEqual(JSON_UPPERCASE, S); Dm.EntityAsIs.Insert; Dm.EntityAsIsId.AsLargeInt := 1; Dm.EntityAsIsName.AsString := 'Ezequiel Juliano Müller'; Dm.EntityAsIs.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityAsIs); - CheckEqualsString(JSON_ASIS, S); + Assert.areEqual(JSON_ASIS, S); Dm.EntityAsIs.Append; Dm.EntityAsIsId.AsLargeInt := 2; Dm.EntityAsIsName.AsString := 'Ezequiel Juliano Müller'; Dm.EntityAsIs.Post; S := FSerializer.SerializeDataSet(Dm.EntityAsIs); - CheckEqualsString(JSON_LIST, S); + Assert.areEqual(JSON_LIST, S); finally Dm.Free; end; @@ -709,7 +729,7 @@ begin O.Name := 'Daniele Teti'; O.Color := TColorEnum.RED; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -717,10 +737,10 @@ begin O := TEntityWithEnums.Create; try FSerializer.DeserializeObject(S, O); - CheckEquals(1, O.Id); - CheckEquals(2, O.Code); - CheckEquals('Daniele Teti', O.Name); - CheckEquals(Ord(TColorEnum.RED), Ord(O.Color)); + Assert.areEqual(int64(1), O.Id); + Assert.areEqual(2, O.Code); + Assert.areEqual('Daniele Teti', O.Name); + Assert.areEqual(Ord(TColorEnum.RED), Ord(O.Color)); finally O.Free; end; @@ -878,16 +898,16 @@ begin O.Department.Notes.Add(TNote.Create('DepNote2')); S := FSerializer.SerializeObject(O, stProperties, ['Ignored']); - CheckEqualsString(JSON_PROPERTIES, S); + Assert.areEqual(JSON_PROPERTIES, S); S := FSerializer.SerializeObject(O, stFields, ['FIgnored']); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); O.Birthday := 0; O.AccessDateTime := 0; O.AccessTime := 0; S := FSerializer.SerializeObject(O, stProperties, ['Ignored']); - CheckEqualsString(JSON_NULLS, S); + Assert.areEqual(JSON_NULLS, S); finally O.Free; end; @@ -918,7 +938,7 @@ begin O.NotesAsString.WriteString('Ezequiel Juliano Müller'); S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -943,7 +963,7 @@ begin O.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -968,7 +988,7 @@ begin O.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -993,10 +1013,10 @@ begin O.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); S := FSerializer.SerializeObject(O, stFields); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -1029,7 +1049,7 @@ begin OFields.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(OFields); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); finally OFields.Free; end; @@ -1041,7 +1061,7 @@ begin OProperties.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(OProperties); - CheckEqualsString(JSON_PROPERTIES, S); + Assert.areEqual(JSON_PROPERTIES, S); finally OProperties.Free; end; @@ -1066,7 +1086,7 @@ begin O.Name := 'Ezequiel Juliano Müller'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -1074,7 +1094,7 @@ end; procedure TMVCTestSerializerJsonDataObjects.TestSerializeNil; begin - CheckEquals('null', FSerializer.SerializeObject(nil)); + Assert.areEqual('null', FSerializer.SerializeObject(nil)); end; { TMVCEntityCustomSerializerJsonDataObjects } @@ -1117,6 +1137,6 @@ end; initialization -RegisterTest(TMVCTestSerializerJsonDataObjects.Suite); +TDUnitX.RegisterTestFixture(TMVCTestSerializerJsonDataObjects); end. diff --git a/unittests/serializer/jsondataobjects/TestSerializerJsonDataObjects.dpr b/unittests/serializer/jsondataobjects/TestSerializerJsonDataObjects.dpr index e39074aa..75aeb0ac 100644 --- a/unittests/serializer/jsondataobjects/TestSerializerJsonDataObjects.dpr +++ b/unittests/serializer/jsondataobjects/TestSerializerJsonDataObjects.dpr @@ -25,26 +25,19 @@ // *************************************************************************** program TestSerializerJsonDataObjects; -{ - Delphi DUnit Test Project - ------------------------- - This project contains the DUnit test framework and the GUI/Console test runners. - Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options - to use the console test runner. Otherwise the GUI test runner will be used by - default. - -} - -{$IFDEF CONSOLE_TESTRUNNER} +{$IFNDEF TESTINSIGHT} {$APPTYPE CONSOLE} -{$ENDIF} +{$ENDIF}{$STRONGLINKTYPES ON} uses - TestFramework, - DUnitTestRunner, - TextTestRunner, System.SysUtils, + {$IFDEF TESTINSIGHT} + TestInsight.DUnitX, + {$ENDIF } + DUnitX.Loggers.Console, + DUnitX.Loggers.Xml.NUnit, + DUnitX.TestFramework, MVCFramework.Tests.Serializer.JsonDataObjects in 'MVCFramework.Tests.Serializer.JsonDataObjects.pas', MVCFramework.Serializer.JsonDataObjects in '..\..\..\sources\MVCFramework.Serializer.JsonDataObjects.pas', MVCFramework.Tests.Serializer.Entities in '..\..\common\MVCFramework.Tests.Serializer.Entities.pas', @@ -54,13 +47,49 @@ uses {$R *.RES} +var + runner : ITestRunner; + results : IRunResults; + logger : ITestLogger; + nunitLogger : ITestLogger; begin FormatSettings.TimeSeparator := ':'; -{$IFDEF CONSOLE_TESTRUNNER} - //Halt(0); - TextTestRunner.RunRegisteredTests(rxbHaltOnFailures); -{$ELSE} - ReportMemoryLeaksOnShutdown := True; - DUnitTestRunner.RunRegisteredTests; +{$IFDEF TESTINSIGHT} + TestInsight.DUnitX.RunRegisteredTests; + exit; {$ENDIF} + + try + //Check command line options, will exit if invalid + TDUnitX.CheckCommandLine; + //Create the test runner + runner := TDUnitX.CreateRunner; + //Tell the runner to use RTTI to find Fixtures + runner.UseRTTI := True; + //tell the runner how we will log things + //Log to the console window + logger := TDUnitXConsoleLogger.Create(true); + runner.AddLogger(logger); + //Generate an NUnit compatible XML File + nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile); + runner.AddLogger(nunitLogger); + runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests; + + //Run tests + results := runner.Execute; + if not results.AllPassed then + System.ExitCode := EXIT_ERRORS; + + {$IFNDEF CI} + //We don't want this happening when running under CI. + if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then + begin + System.Write('Done.. press key to quit.'); + System.Readln; + end; + {$ENDIF} + except + on E: Exception do + System.Writeln(E.ClassName, ': ', E.Message); + end; end. diff --git a/unittests/serializer/systemjson/MVCFramework.Tests.Serializer.JSON.pas b/unittests/serializer/systemjson/MVCFramework.Tests.Serializer.JSON.pas index 92418d4e..fbee8b9a 100644 --- a/unittests/serializer/systemjson/MVCFramework.Tests.Serializer.JSON.pas +++ b/unittests/serializer/systemjson/MVCFramework.Tests.Serializer.JSON.pas @@ -29,7 +29,7 @@ unit MVCFramework.Tests.Serializer.JSON; interface uses - TestFramework, + DUnitX.TestFramework, System.Rtti, System.Classes, System.SysUtils, @@ -45,32 +45,52 @@ uses type - TMVCTestSerializerJSON = class(TTestCase, IMVCTestSerializer) + [TestFixture] + TMVCTestSerializerJSON = class(TObject) private FSerializer: IMVCSerializer; protected - procedure SetUp; override; - procedure TearDown; override; + [SetUp] + procedure SetUp; + [TearDown] + procedure TearDown; published { serialize declarations } + [Test] procedure TestSerializeEntity; + [Test] procedure TestSerializeNill; + [Test] procedure TestSerializeEntityUpperCaseNames; + [Test] procedure TestSerializeEntityLowerCaseNames; + [Test] procedure TestSerializeEntityNameAs; + [Test] procedure TestSerializeEntityCustomSerializer; + [Test] procedure TestSerializeEntityCustomMemberSerializer; + [Test] procedure TestSerializeEntitySerializationType; + [Test] procedure TestSerializeCollection; + [Test] procedure TestSerializeDataSet; { deserialize declarations } + [Test] procedure TestDeserializeEntity; + [Test] procedure TestDeserializeEntityCustomSerializer; + [Test] procedure TestDeserializeEntityCustomMemberSerializer; + [Test] procedure TestDeserializeEntitySerializationType; + [Test] procedure TestDeserializeCollection; + [Test] procedure TestDeserializeDataSet; { full cycle } + [Test] procedure TestSerializeDeSerializeEntityWithEnums; end; @@ -105,11 +125,11 @@ procedure TMVCTestSerializerJSON.TestDeserializeCollection; procedure CheckObjectList(const AList: TObjectList); begin - CheckTrue(AList.Count = 4); - CheckTrue(AList.Items[0].Description = 'Description 1'); - CheckTrue(AList.Items[1].Description = 'Description 2'); - CheckTrue(AList.Items[2].Description = 'Description 3'); - CheckTrue(AList.Items[3].Description = 'Description 4'); + Assert.isTrue(AList.Count = 4); + Assert.isTrue(AList.Items[0].Description = 'Description 1'); + Assert.isTrue(AList.Items[1].Description = 'Description 2'); + Assert.isTrue(AList.Items[2].Description = 'Description 3'); + Assert.isTrue(AList.Items[3].Description = 'Description 4'); end; const @@ -228,53 +248,53 @@ begin Dm := TEntitiesModule.Create(nil); try FSerializer.DeserializeDataSetRecord(JSON, Dm.Entity, ['Ignored']); - CheckTrue(Dm.EntityId.AsLargeInt = 1); - CheckTrue(Dm.EntityCode.AsInteger = 2); - CheckTrue(Dm.EntityName.AsString = 'Ezequiel Juliano'); - CheckTrue(Dm.EntityBirthday.AsDateTime = StrToDate('15/10/1987')); - CheckTrue(Dm.EntityAccessDateTime.AsDateTime = StrToDateTime('17/02/2017 16:37:50')); - CheckTrue(Dm.EntityAccessTime.AsDateTime = StrToTime('16:40:50')); - CheckTrue(Dm.EntityActive.AsBoolean = True); - CheckTrue(Dm.EntitySalary.AsCurrency = 100); - CheckTrue(Dm.EntityAmount.AsFloat = 100); - CheckTrue(Dm.EntityBlobFld.AsString = '

BLOB

'); + Assert.isTrue(Dm.EntityId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityCode.AsInteger = 2); + Assert.isTrue(Dm.EntityName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityBirthday.AsDateTime = StrToDate('15/10/1987')); + Assert.isTrue(Dm.EntityAccessDateTime.AsDateTime = StrToDateTime('17/02/2017 16:37:50')); + Assert.isTrue(Dm.EntityAccessTime.AsDateTime = StrToTime('16:40:50')); + Assert.isTrue(Dm.EntityActive.AsBoolean = True); + Assert.isTrue(Dm.EntitySalary.AsCurrency = 100); + Assert.isTrue(Dm.EntityAmount.AsFloat = 100); + Assert.isTrue(Dm.EntityBlobFld.AsString = '

BLOB

'); Dm.Item.First; - CheckTrue(Dm.ItemId.AsLargeInt = 1); - CheckTrue(Dm.ItemName.AsString = 'Ezequiel'); + Assert.isTrue(Dm.ItemId.AsLargeInt = 1); + Assert.isTrue(Dm.ItemName.AsString = 'Ezequiel'); Dm.Item.Next; - CheckTrue(Dm.ItemId.AsLargeInt = 2); - CheckTrue(Dm.ItemName.AsString = 'Juliano'); + Assert.isTrue(Dm.ItemId.AsLargeInt = 2); + Assert.isTrue(Dm.ItemName.AsString = 'Juliano'); Dm.Departament.First; - CheckTrue(Dm.DepartamentName.AsString = 'Depto1'); + Assert.isTrue(Dm.DepartamentName.AsString = 'Depto1'); FSerializer.DeserializeDataSetRecord(JSON_LOWERCASE, Dm.EntityLowerCase); - CheckTrue(Dm.EntityLowerCaseId.AsLargeInt = 1); - CheckTrue(Dm.EntityLowerCaseName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityLowerCaseId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityLowerCaseName.AsString = 'Ezequiel Juliano'); FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase); - CheckTrue(Dm.EntityUpperCaseId.AsLargeInt = 1); - CheckTrue(Dm.EntityUpperCaseName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityUpperCaseId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityUpperCaseName.AsString = 'Ezequiel Juliano'); FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase2, [], ncUpperCase); - CheckTrue(Dm.EntityUpperCase2Id.AsLargeInt = 1); - CheckTrue(Dm.EntityUpperCase2Name.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityUpperCase2Id.AsLargeInt = 1); + Assert.isTrue(Dm.EntityUpperCase2Name.AsString = 'Ezequiel Juliano'); FSerializer.DeserializeDataSetRecord(JSON_ASIS, Dm.EntityAsIs); - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 1); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); Dm.EntityAsIs.EmptyDataSet; FSerializer.DeserializeDataSet(JSON_LIST, Dm.EntityAsIs); Dm.EntityAsIs.First; - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 1); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); Dm.EntityAsIs.Next; - CheckTrue(Dm.EntityAsIsId.AsLargeInt = 2); - CheckTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); + Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 2); + Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano'); finally Dm.Free; end; @@ -284,26 +304,26 @@ procedure TMVCTestSerializerJSON.TestDeserializeEntity; procedure CheckObject(const AEntity: TEntity); begin - CheckTrue(AEntity.Id = 1); - CheckTrue(AEntity.Code = 2); - CheckTrue(AEntity.Name = 'Ezequiel Juliano Müller'); - CheckTrue(AEntity.Salary = 100); - CheckTrue(DateToStr(AEntity.Birthday) = '15/10/1987'); - CheckTrue(DateTimeToStr(AEntity.AccessDateTime) = '17/02/2017 16:37:50'); - CheckTrue(TimeToStr(AEntity.AccessTime) = '16:40:50'); - CheckTrue(AEntity.Active = True); - CheckTrue(AEntity.Role = TRole.roGuest); - CheckTrue(DateTimeToStr(TimeStampToDateTime(AEntity.Teporization)) = '17/02/2017 16:37:50'); - CheckTrue(AEntity.Department <> nil); - CheckTrue(AEntity.Department.Id = 1); - CheckTrue(AEntity.Department.Name = 'Development'); - CheckTrue(AEntity.DepartmentNull = nil); - CheckTrue(AEntity.Notes.Count = 2); - CheckTrue(AEntity.Notes[0].Description = 'EntNote1'); - CheckTrue(AEntity.Notes[1].Description = 'EntNote2'); - CheckTrue(AEntity.NotesEmpty.Count = 0); - CheckTrue(AEntity.AppreciationAs.AsString = 'Yes'); - CheckTrue(AEntity.Appreciation.AsString = 'Yes'); + Assert.isTrue(AEntity.Id = 1); + Assert.isTrue(AEntity.Code = 2); + Assert.isTrue(AEntity.Name = 'Ezequiel Juliano Müller'); + Assert.isTrue(AEntity.Salary = 100); + Assert.isTrue(DateToStr(AEntity.Birthday) = '15/10/1987'); + Assert.isTrue(DateTimeToStr(AEntity.AccessDateTime) = '17/02/2017 16:37:50'); + Assert.isTrue(TimeToStr(AEntity.AccessTime) = '16:40:50'); + Assert.isTrue(AEntity.Active = True); + Assert.isTrue(AEntity.Role = TRole.roGuest); + Assert.isTrue(DateTimeToStr(TimeStampToDateTime(AEntity.Teporization)) = '17/02/2017 16:37:50'); + Assert.isTrue(AEntity.Department <> nil); + Assert.isTrue(AEntity.Department.Id = 1); + Assert.isTrue(AEntity.Department.Name = 'Development'); + Assert.isTrue(AEntity.DepartmentNull = nil); + Assert.isTrue(AEntity.Notes.Count = 2); + Assert.isTrue(AEntity.Notes[0].Description = 'EntNote1'); + Assert.isTrue(AEntity.Notes[1].Description = 'EntNote2'); + Assert.isTrue(AEntity.NotesEmpty.Count = 0); + Assert.isTrue(AEntity.AppreciationAs.AsString = 'Yes'); + Assert.isTrue(AEntity.Appreciation.AsString = 'Yes'); end; const @@ -426,11 +446,11 @@ begin O := TSale.Create; try FSerializer.DeserializeObject(JSON, O); - CheckTrue(O.Entity.Id = 1); - CheckTrue(O.Entity.Code = 2); - CheckTrue(O.Entity.Name = 'Ezequiel Juliano'); - CheckTrue(O.Notes.DataString = 'Ezequiel Juliano'); - CheckTrue(O.NotesAsString.DataString = 'Ezequiel Juliano'); + Assert.isTrue(O.Entity.Id = 1); + Assert.isTrue(O.Entity.Code = 2); + Assert.isTrue(O.Entity.Name = 'Ezequiel Juliano'); + Assert.isTrue(O.Notes.DataString = 'Ezequiel Juliano'); + Assert.isTrue(O.NotesAsString.DataString = 'Ezequiel Juliano'); finally O.Free; end; @@ -450,9 +470,9 @@ begin O := TEntityCustom.Create; try FSerializer.DeserializeObject(JSON, O); - CheckTrue(O.Id = 1); - CheckTrue(O.Code = 2); - CheckTrue(O.Name = 'Ezequiel Juliano'); + Assert.isTrue(O.Id = 1); + Assert.isTrue(O.Code = 2); + Assert.isTrue(O.Name = 'Ezequiel Juliano'); finally O.Free; end; @@ -480,9 +500,9 @@ begin OFields := TEntitySerializeFields.Create; try FSerializer.DeserializeObject(JSON_FIELDS, OFields); - CheckTrue(OFields.Id = 1); - CheckTrue(OFields.Code = 2); - CheckTrue(OFields.Name = 'Ezequiel Juliano'); + Assert.isTrue(OFields.Id = 1); + Assert.isTrue(OFields.Code = 2); + Assert.isTrue(OFields.Name = 'Ezequiel Juliano'); finally OFields.Free; end; @@ -490,9 +510,9 @@ begin OProperties := TEntitySerializeProperties.Create; try FSerializer.DeserializeObject(JSON_PROPERTIES, OProperties); - CheckTrue(OProperties.Id = 1); - CheckTrue(OProperties.Code = 2); - CheckTrue(OProperties.Name = 'Ezequiel Juliano'); + Assert.isTrue(OProperties.Id = 1); + Assert.isTrue(OProperties.Code = 2); + Assert.isTrue(OProperties.Name = 'Ezequiel Juliano'); finally OProperties.Free; end; @@ -543,10 +563,10 @@ begin O.Add(TNote.Create('Description 4')); S := FSerializer.SerializeCollection(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); S := FSerializer.SerializeCollection(O, stFields); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); finally O.Free; end; @@ -644,42 +664,42 @@ begin Dm.Entity.Post; S := FSerializer.SerializeDataSetRecord(Dm.Entity, ['Ignored'], ncAsIs); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); Dm.EntityLowerCase.Insert; Dm.EntityLowerCaseId.AsLargeInt := 1; Dm.EntityLowerCaseName.AsString := 'Ezequiel Juliano'; Dm.EntityLowerCase.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityLowerCase); - CheckEqualsString(JSON_LOWERCASE, S); + Assert.areEqual(JSON_LOWERCASE, S); Dm.EntityUpperCase.Insert; Dm.EntityUpperCaseId.AsLargeInt := 1; Dm.EntityUpperCaseName.AsString := 'Ezequiel Juliano'; Dm.EntityUpperCase.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase); - CheckEqualsString(JSON_UPPERCASE, S); + Assert.areEqual(JSON_UPPERCASE, S); Dm.EntityUpperCase2.Insert; Dm.EntityUpperCase2Id.AsLargeInt := 1; Dm.EntityUpperCase2Name.AsString := 'Ezequiel Juliano'; Dm.EntityUpperCase2.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase2, [], ncUpperCase); - CheckEqualsString(JSON_UPPERCASE, S); + Assert.areEqual(JSON_UPPERCASE, S); Dm.EntityAsIs.Insert; Dm.EntityAsIsId.AsLargeInt := 1; Dm.EntityAsIsName.AsString := 'Ezequiel Juliano'; Dm.EntityAsIs.Post; S := FSerializer.SerializeDataSetRecord(Dm.EntityAsIs); - CheckEqualsString(JSON_ASIS, S); + Assert.areEqual(JSON_ASIS, S); Dm.EntityAsIs.Append; Dm.EntityAsIsId.AsLargeInt := 2; Dm.EntityAsIsName.AsString := 'Ezequiel Juliano'; Dm.EntityAsIs.Post; S := FSerializer.SerializeDataSet(Dm.EntityAsIs); - CheckEqualsString(JSON_LIST, S); + Assert.areEqual(JSON_LIST, S); finally Dm.Free; end; @@ -837,16 +857,16 @@ begin O.Department.Notes.Add(TNote.Create('DepNote2')); S := FSerializer.SerializeObject(O, stProperties, ['Ignored']); - CheckEqualsString(JSON_PROPERTIES, S); + Assert.areEqual(JSON_PROPERTIES, S); S := FSerializer.SerializeObject(O, stFields, ['FIgnored']); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); O.Birthday := 0; O.AccessDateTime := 0; O.AccessTime := 0; S := FSerializer.SerializeObject(O, stProperties, ['Ignored']); - CheckEqualsString(JSON_NULLS, S); + Assert.areEqual(JSON_NULLS, S); finally O.Free; end; @@ -877,7 +897,7 @@ begin O.NotesAsString.WriteString('Ezequiel Juliano'); S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -902,7 +922,7 @@ begin O.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -927,7 +947,7 @@ begin O.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -952,10 +972,10 @@ begin O.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); S := FSerializer.SerializeObject(O, stFields); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -988,7 +1008,7 @@ begin OFields.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(OFields); - CheckEqualsString(JSON_FIELDS, S); + Assert.areEqual(JSON_FIELDS, S); finally OFields.Free; end; @@ -1000,7 +1020,7 @@ begin OProperties.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(OProperties); - CheckEqualsString(JSON_PROPERTIES, S); + Assert.areEqual(JSON_PROPERTIES, S); finally OProperties.Free; end; @@ -1025,7 +1045,7 @@ begin O.Name := 'Ezequiel Juliano'; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -1051,7 +1071,7 @@ begin O.Name := 'Daniele Teti'; O.Color := TColorEnum.RED; S := FSerializer.SerializeObject(O); - CheckEqualsString(JSON, S); + Assert.areEqual(JSON, S); finally O.Free; end; @@ -1059,10 +1079,10 @@ begin O := TEntityWithEnums.Create; try FSerializer.DeserializeObject(S, O); - CheckEquals(1, O.Id); - CheckEquals(2, O.Code); - CheckEquals('Daniele Teti', O.Name); - CheckEquals(Ord(TColorEnum.RED), Ord(O.Color)); + Assert.areEqual(int64(1), O.Id); + Assert.areEqual(2, O.Code); + Assert.areEqual('Daniele Teti', O.Name); + Assert.areEqual(Ord(TColorEnum.RED), Ord(O.Color)); finally O.Free; end; @@ -1070,7 +1090,7 @@ end; procedure TMVCTestSerializerJSON.TestSerializeNill; begin - CheckEquals('null', FSerializer.SerializeObject(nil)); + Assert.areEqual('null', FSerializer.SerializeObject(nil)); end; { TMVCEntityCustomSerializerJSON } @@ -1113,6 +1133,6 @@ end; initialization -RegisterTest(TMVCTestSerializerJSON.Suite); +TDUnitX.RegisterTestFixture(TMVCTestSerializerJSON); end. diff --git a/unittests/serializer/systemjson/TestSerializerJSON.dpr b/unittests/serializer/systemjson/TestSerializerJSON.dpr index 2902527c..fdac00b5 100644 --- a/unittests/serializer/systemjson/TestSerializerJSON.dpr +++ b/unittests/serializer/systemjson/TestSerializerJSON.dpr @@ -25,25 +25,19 @@ // *************************************************************************** program TestSerializerJSON; -{ - Delphi DUnit Test Project - ------------------------- - This project contains the DUnit test framework and the GUI/Console test runners. - Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options - to use the console test runner. Otherwise the GUI test runner will be used by - default. - -} - -{$IFDEF CONSOLE_TESTRUNNER} +{$IFNDEF TESTINSIGHT} {$APPTYPE CONSOLE} -{$ENDIF} +{$ENDIF}{$STRONGLINKTYPES ON} uses - DUnitTestRunner, - TextTestRunner, System.SysUtils, + {$IFDEF TESTINSIGHT} + TestInsight.DUnitX, + {$ENDIF } + DUnitX.Loggers.Console, + DUnitX.Loggers.Xml.NUnit, + DUnitX.TestFramework, MVCFramework.Tests.Serializer.JSON in 'MVCFramework.Tests.Serializer.JSON.pas', MVCFramework.Tests.Serializer.Entities in '..\..\common\MVCFramework.Tests.Serializer.Entities.pas', MVCFramework.Serializer.JSON in '..\..\..\sources\MVCFramework.Serializer.JSON.pas', @@ -53,14 +47,49 @@ uses {$R *.RES} +var + runner : ITestRunner; + results : IRunResults; + logger : ITestLogger; + nunitLogger : ITestLogger; begin FormatSettings.TimeSeparator := ':'; -{$IFDEF CONSOLE_TESTRUNNER} - //Halt(0); - TextTestRunner.RunRegisteredTests(rxbHaltOnFailures); -{$ELSE} - ReportMemoryLeaksOnShutdown := True; - DUnitTestRunner.RunRegisteredTests; +{$IFDEF TESTINSIGHT} + TestInsight.DUnitX.RunRegisteredTests; + exit; {$ENDIF} + try + //Check command line options, will exit if invalid + TDUnitX.CheckCommandLine; + //Create the test runner + runner := TDUnitX.CreateRunner; + //Tell the runner to use RTTI to find Fixtures + runner.UseRTTI := True; + //tell the runner how we will log things + //Log to the console window + logger := TDUnitXConsoleLogger.Create(true); + runner.AddLogger(logger); + //Generate an NUnit compatible XML File + nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile); + runner.AddLogger(nunitLogger); + runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests; + + //Run tests + results := runner.Execute; + if not results.AllPassed then + System.ExitCode := EXIT_ERRORS; + + {$IFNDEF CI} + //We don't want this happening when running under CI. + if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then + begin + System.Write('Done.. press key to quit.'); + System.Readln; + end; + {$ENDIF} + except + on E: Exception do + System.Writeln(E.ClassName, ': ', E.Message); + end; end.