From 44f9a3315230e7819ade0c66fdb3db9c26678605 Mon Sep 17 00:00:00 2001 From: Max Kirchberger Date: Mon, 21 Oct 2024 18:33:44 +0200 Subject: [PATCH] adjuist asserts for nunit 4 --- .../ApiDirectoryBuilderTests.cs | 8 +- .../ApiRequestTests.cs | 110 +++++++++--------- tests/Webserver.API.UnitTests/ModelTests.cs | 101 +++++++++------- 3 files changed, 115 insertions(+), 104 deletions(-) diff --git a/tests/Webserver.API.UnitTests/ApiDirectoryBuilderTests.cs b/tests/Webserver.API.UnitTests/ApiDirectoryBuilderTests.cs index f8c6fb6..6fdc525 100644 --- a/tests/Webserver.API.UnitTests/ApiDirectoryBuilderTests.cs +++ b/tests/Webserver.API.UnitTests/ApiDirectoryBuilderTests.cs @@ -81,7 +81,7 @@ public void T004_EmptyDirectory_Built() var dirInf = new DirectoryInfo(localTmpDirectory); Assert.That(res.Last_Modified, Is.EqualTo(dirInf.LastWriteTime)); Assert.That(res.Name, Is.EqualTo(dirInf.Name)); - Assert.IsNull(res.Size); + Assert.That(res.Size, Is.Null); } finally { @@ -105,7 +105,7 @@ public void T005_DirectoryWithFile_Built() var parseConfig = new ApiDirectoryBuilderConfiguration() { }; var res = builder.Build(parseConfig); Assert.That(res.Resources.Count, Is.EqualTo(1)); - Assert.IsNull(res.Size); + Assert.That(res.Size, Is.Null); var firstRes = res.Resources.First(); Assert.That(firstRes.Type, Is.EqualTo(ApiFileResourceType.File)); Assert.That(firstRes.State, Is.EqualTo(ApiFileResourceState.Active)); @@ -133,11 +133,11 @@ public void T006_DirectoryWithDir_Built() var parseConfig = new ApiDirectoryBuilderConfiguration() { }; var res = builder.Build(parseConfig); Assert.That(res.Resources.Count, Is.EqualTo(1)); - Assert.IsNull(res.Size); + Assert.That(res.Size, Is.Null); var firstRes = res.Resources.First(); Assert.That(firstRes.Type, Is.EqualTo(ApiFileResourceType.Dir)); Assert.That(firstRes.State, Is.EqualTo(ApiFileResourceState.Active)); - Assert.IsNull(firstRes.Size); + Assert.That(firstRes.Size, Is.Null); Assert.That(firstRes.Last_Modified, Is.EqualTo(dirInfo.LastWriteTime)); Assert.That(firstRes.PathToLocalDirectory, Is.EqualTo(dirPath)); } diff --git a/tests/Webserver.API.UnitTests/ApiRequestTests.cs b/tests/Webserver.API.UnitTests/ApiRequestTests.cs index 8e28503..7fb2805 100644 --- a/tests/Webserver.API.UnitTests/ApiRequestTests.cs +++ b/tests/Webserver.API.UnitTests/ApiRequestTests.cs @@ -2617,7 +2617,7 @@ public async Task T039_01_PlcCreateBackup_Valid_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var expected = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; var resp = await TestHandler.PlcCreateBackupAsync(); - Assert.IsTrue(resp.Result.ToString() == expected, "Failed"); + Assert.That(resp.Result.ToString() == expected, "Failed"); } /// @@ -2637,7 +2637,7 @@ public async Task T040_01_PlcRestoreBackup_Valid_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var expected = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; var resp = await TestHandler.PlcRestoreBackupAsync(); - Assert.IsTrue(resp.Result.ToString() == expected, "Failed"); + Assert.That(resp.Result.ToString() == expected, "Failed"); } /// @@ -2657,7 +2657,7 @@ public async Task T040_01_PlcRestoreBackup_DHCP_Valid_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var expected = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; var resp = await TestHandler.PlcRestoreBackupAsync(); - Assert.IsTrue(resp.Result.ToString() == expected, "Failed"); + Assert.That(resp.Result.ToString() == expected, "Failed"); } /// @@ -2700,7 +2700,7 @@ public async Task T042_01_ApiFilesDownload_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesDownloadAsync("/"); var expectedResult = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; - Assert.AreEqual(expectedResult, result.Result, "The tickets are not identical."); + Assert.That(result.Result, Is.EqualTo(expectedResult)); } /// @@ -2720,7 +2720,7 @@ public async Task T043_01_ApiFilesCreate_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesCreateAsync("/"); var expectedResult = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; - Assert.AreEqual(expectedResult, result.Result, "The tickets are not identical."); + Assert.That(result.Result, Is.EqualTo(expectedResult), "Tickets for FilesCreate!"); } /// @@ -2739,7 +2739,7 @@ public async Task T044_01_ApiFilesCreateDirectory_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesCreateDirectoryAsync("/Dir/newDir"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// @@ -2758,7 +2758,7 @@ public async Task T045_01_ApiFilesRename_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesRenameAsync("/Dir/newDir", "/Dir/renamedDir"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// @@ -2777,7 +2777,7 @@ public async Task T046_01_ApiFilesDelete_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesDeleteAsync("/Dir/newDir"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// @@ -2796,7 +2796,7 @@ public async Task T047_01_ApiFilesDeleteDirectory_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesDeleteDirectoryAsync("/Dir/newDir"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// @@ -2839,7 +2839,7 @@ public async Task T049_01_ApiDataLogsDownload_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesDownloadAsync("/"); var expectedResult = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; - Assert.AreEqual(expectedResult, result.Result, "The tickets are not identical."); + Assert.That(result.Result, Is.EqualTo(expectedResult)); } /// @@ -2858,7 +2858,7 @@ public async Task T050_01_ApiDataLogsDelete_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.FilesDeleteAsync("/Dir/newDir"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// @@ -2878,7 +2878,7 @@ public async Task T051_01_ApiDataLogsDownloadAndClear_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.DatalogsDownloadAndClearAsync("/"); var expectedResult = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; - Assert.AreEqual(expectedResult, result.Result, "The tickets are not identical."); + Assert.That(result.Result, Is.EqualTo(expectedResult)); } /// @@ -2899,11 +2899,11 @@ public async Task T052_ApiSyslogBrowse_Works() var result = (await TestHandler.ApiSyslogBrowseAsync()).Result; Assert.Multiple(() => { - Assert.AreEqual(5, result.Count_Total, "result Count_Total is not the expected value!"); - Assert.AreEqual(1, result.Count_Lost, "result Count_Lost is not the expected value!"); - Assert.AreEqual(2, result.Entries.Count, "result Entries.Count is not the expected value!"); - Assert.AreEqual("I am a syslog, no need to question it!", result.Entries[0].Raw, "result Entries[0].Raw is not the expected value!"); - Assert.AreEqual("I am a syslog, too. But the previous syslog is an impostor!", result.Entries[1].Raw, "result Entries[1].Raw is not the expected value!"); + Assert.That(result.Count_Total, Is.EqualTo(5)); + Assert.That(result.Count_Lost, Is.EqualTo(1)); + Assert.That(result.Entries.Count, Is.EqualTo(2)); + Assert.That(result.Entries[0].Raw, Is.EqualTo("I am a syslog, no need to question it!")); + Assert.That(result.Entries[1].Raw, Is.EqualTo("I am a syslog, too. But the previous syslog is an impostor!"), "Tickets for FilesCreate!"); }); } /// @@ -2989,8 +2989,8 @@ public async Task T054_ApiFailsafeReadRuntimeGroups_Works() withRemaining.Cycle_time_Max = TimeSpan.FromMilliseconds(200); withRemaining.Runtime_current = TimeSpan.FromMilliseconds(50); withRemaining.Runtime_max = TimeSpan.FromMilliseconds(80); - Assert.IsTrue(result.Result.Groups[0].Equals(noRemaining), "The groups don't match!"); - Assert.IsTrue(result.Result.Groups[1].Equals(withRemaining), "The groups don't match!"); + Assert.That(result.Result.Groups[0].Equals(noRemaining), "The groups don't match!"); + Assert.That(result.Result.Groups[1].Equals(withRemaining), "The groups don't match!"); } /// @@ -3009,7 +3009,7 @@ public async Task T055_ApiChangePassword_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.ApiChangePasswordAsync("Admin", "adminpw", "newadminpw"); - Assert.IsTrue(result.Result, "Changing passwords not possible!"); + Assert.That(result.Result, "Changing passwords not possible!"); } /// @@ -3035,7 +3035,7 @@ public async Task T056_ApiGetPasswordPolicy_Works() expectedResult.Max_password_length = 120; expectedResult.Min_digits = 1; expectedResult.Min_special_characters = 0; - Assert.AreEqual(expectedResult, result.Result.Password_policy, "Password policies dont match"); + Assert.That(result.Result.Password_policy, Is.EqualTo(expectedResult), "Tickets for FilesCreate!"); } /// @@ -3058,7 +3058,7 @@ public async Task T057_ApiGetAuthenticationMode_Works() expectedResult.Add(ApiAuthenticationMode.Local); expectedResult.Add(ApiAuthenticationMode.Static); expectedResult.Add(ApiAuthenticationMode.Disabled); - Assert.AreEqual(expectedResult.Count, result.Result.Authentication_modes.Count, "Authentication modes count don't match!"); + Assert.That(result.Result.Authentication_modes.Count, Is.EqualTo(expectedResult.Count)); Assert.That(expectedResult.SequenceEqual(result.Result.Authentication_modes), "Order of authetication modes is different!"); } @@ -3083,7 +3083,7 @@ public async Task T058_ProjectReadLanguages_Works() expectedResult.Add(new CultureInfo("en-GB")); expectedResult.Add(new CultureInfo("es-BR")); expectedResult.Add(new CultureInfo("ne-IN")); - Assert.AreEqual(expectedResult.Count, result.Result.Languages.Select(x => x.Language).Count(), "Languages don't match"); + Assert.That(result.Result.Languages.Select(x => x.Language).Count(), Is.EqualTo(expectedResult.Count)); Assert.That(expectedResult.SequenceEqual(result.Result.Languages.Select(x => x.Language)), "The order of languages are different, or they don't contain the same languages."); } @@ -3103,7 +3103,7 @@ public async Task T059_01_ApiPlcReadModeSelectorState_Standard_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var res = await TestHandler.PlcReadModeSelectorStateAsync(ApiPlcRedundancyId.StandardPLC); - Assert.AreEqual(ApiPlcModeSelectorState.Run, res.Result.Mode_Selector, "Plc Mode Selector state is not in run mode!"); + Assert.That(res.Result.Mode_Selector, Is.EqualTo(ApiPlcModeSelectorState.Run)); } /// @@ -3122,7 +3122,7 @@ public async Task T059_02_ApiPlcReadModeSelectorState_RH_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var res = await TestHandler.PlcReadModeSelectorStateAsync(ApiPlcRedundancyId.RedundancyId_1); - Assert.AreEqual(ApiPlcModeSelectorState.NoSwitch, res.Result.Mode_Selector, "Plc Mode Selector state is not in noswitch mode!"); + Assert.That(res.Result.Mode_Selector, Is.EqualTo(ApiPlcModeSelectorState.NoSwitch)); } /// @@ -3142,7 +3142,7 @@ public async Task T060_ApiModulesDownloadServiceData_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.ModulesDownloadServiceDataAsync(ApiPlcHwId.StandardPLC); var expectedResult = "dlBvEAfpgSVBfwlU7Py5TsVbmRTq"; - Assert.AreEqual(expectedResult, result.Result, "The tickets are not identical."); + Assert.That(result.Result, Is.EqualTo(expectedResult)); } /// @@ -3161,7 +3161,7 @@ public async Task T061_ApiAlarmsAcknowledge_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.AlarmsAcknowledgeAsync("/"); - Assert.AreEqual(true, result.Result, "The response should always contain true, but it doesn't."); + Assert.That(result.Result); } /// /// TestCase for Plc.SetSystemTime @@ -3179,7 +3179,7 @@ public async Task T062_PlcSetSystemTime_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.PlcSetSystemTimeAsync(new DateTime(2010, 10, 10)); - Assert.IsTrue(result.Result, "The time was not set successfully!"); + Assert.That(result.Result, "The time was not set successfully!"); } /// @@ -3204,7 +3204,7 @@ public async Task T063_01_ApiPlcSetTimeSettings_Works() DaylightSavingsRule dsr = new DaylightSavingsRule(sdt, dst); var result = await TestHandler.PlcSetTimeSettingsAsync(offset, dsr); - Assert.IsTrue(result.Result, "Couldn't set time settings!"); + Assert.That(result.Result, "Couldn't set time settings!"); } /// @@ -3226,7 +3226,7 @@ public async Task T063_02_ApiPlcSetTimeSettingsNoRule_Works() var offset = new TimeSpan(8, 0, 0); var result = await TestHandler.PlcSetTimeSettingsAsync(offset); - Assert.IsTrue(result.Result, "Couldn't set time settings!"); + Assert.That(result.Result, "Couldn't set time settings!"); } /// @@ -3267,7 +3267,7 @@ public async Task T065_WebServerSetDefaultPage_Works() client.BaseAddress = new Uri($"https://{Ip.ToString()}"); TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.WebServerSetDefaultPageAsync("index.html"); - Assert.IsTrue(result.Result, "The result is not true."); + Assert.That(result.Result, "The result is not true."); } /// /// TestCase for WebServer.ReadDefaultPage @@ -3286,7 +3286,7 @@ public async Task T066_WebServerReadDefaultPage_Works() TestHandler = new ApiHttpClientRequestHandler(client, ApiRequestFactory, ApiResponseChecker); var result = await TestHandler.WebServerGetReadDefaultPageAsync(); var expectedResult = "/~teszt2/index.html"; - Assert.AreEqual(expectedResult, result.Result.Default_page, "The result is not the expected."); + Assert.That(result.Result.Default_page, Is.EqualTo(expectedResult)); } /// @@ -3307,19 +3307,19 @@ public async Task T067_ApiAlarmsBrowse_Works() var result = (await TestHandler.ApiAlarmsBrowseAsync(new CultureInfo("en-US"))).Result; Assert.Multiple(() => { - Assert.AreEqual(2, result.Entries.Count, "result.Entries.Count"); - Assert.AreEqual("9947888669857743000", result.Entries[0].Id, "result.Entries[0].Id"); - Assert.AreEqual(512, result.Entries[0].Alarm_Number, "result.Entries[0].Alarm_Number"); - Assert.AreEqual(ApiObjectDirectoryStatus.Incoming, result.Entries[0].Status, "result.Entries[0].Status"); - Assert.AreEqual(new DateTime(2012, 1, 1, 1, 1, 42, 47), result.Entries[0].Timestamp, "result.Entries[0].Timestamp"); - Assert.AreEqual(ApiAlarmAcknowledgementState.Not_Acknowledged, result.Entries[0].Acknowledgement.State, "result.Entries[0].Acknowledgement.State"); - Assert.AreEqual("#1, 1", result.Entries[0].Alarm_Text, "result.Entries[0].Alarm_Text"); - Assert.AreEqual("#1, 0", result.Entries[0].Info_Text, "result.Entries[0].Info_Text"); - Assert.AreEqual(false, result.Entries[0].Text_Inconsistent, "result.Entries[0].Text_Inconsistent"); - Assert.AreEqual(new DateTime(2012, 1, 1, 1, 1, 42, 99), result.Last_Modified, "result.Last_Modified"); - Assert.AreEqual(51, result.Count_Current, "result.Count_Current"); - Assert.AreEqual(500, result.Count_Max, "result.Count_Max"); - Assert.AreEqual("en-US", result.Language, "result.Language"); + Assert.That(result.Entries.Count, Is.EqualTo(2)); + Assert.That(result.Entries[0].Id, Is.EqualTo("9947888669857743000")); + Assert.That(result.Entries[0].Alarm_Number, Is.EqualTo(512)); + Assert.That(result.Entries[0].Status, Is.EqualTo(ApiObjectDirectoryStatus.Incoming)); + Assert.That(result.Entries[0].Timestamp, Is.EqualTo(new DateTime(2012, 1, 1, 1, 1, 42, 47))); + Assert.That(result.Entries[0].Acknowledgement.State, Is.EqualTo(ApiAlarmAcknowledgementState.Not_Acknowledged)); + Assert.That(result.Entries[0].Alarm_Text, Is.EqualTo("#1, 1")); + Assert.That(result.Entries[0].Info_Text, Is.EqualTo("#1, 0")); + Assert.That(result.Entries[0].Text_Inconsistent, Is.EqualTo(false)); + Assert.That(result.Last_Modified, Is.EqualTo(new DateTime(2012, 1, 1, 1, 1, 42, 99))); + Assert.That(result.Count_Current, Is.EqualTo(51)); + Assert.That(result.Count_Max, Is.EqualTo(500)); + Assert.That(result.Language, Is.EqualTo("en-US")); }); } @@ -3343,16 +3343,16 @@ public async Task T068_ApiDiagnosticBufferBrowse_Works() expected = expected.AddTicks(5146785); Assert.Multiple(() => { - Assert.AreEqual(2, result.Entries.Count, "result.Entries.Count"); - Assert.AreEqual(ApiObjectDirectoryStatus.Outgoing, result.Entries[0].Status, "result.Entries[0].Status"); - Assert.AreEqual("Boot up - CPU changes from OFF to STOP (initialization) mode", result.Entries[0].Short_Text, "result.Entries[0].Short_Text"); - Assert.AreEqual("LONG TEXT", result.Entries[1].Long_Text, "result.Entries[1].Long_Text"); - Assert.AreEqual(3, result.Entries[1].Event.Textlist_Id, "result.Entries[1].Event.Textlist_Id"); - Assert.AreEqual(26315, result.Entries[1].Event.Text_Id, "result.Entries[1].Event.Text_Id"); - Assert.AreEqual(expected, result.Last_Modified, "result.Last_Modified"); - Assert.AreEqual(1234, result.Count_Current, "result.Count_Current"); - Assert.AreEqual(3200, result.Count_Max, "result.Count_Max"); - Assert.AreEqual("en-US", result.Language, "result.Language"); + Assert.That(result.Entries.Count, Is.EqualTo(2)); + Assert.That(result.Entries[0].Status, Is.EqualTo(ApiObjectDirectoryStatus.Outgoing)); + Assert.That(result.Entries[0].Short_Text, Is.EqualTo("Boot up - CPU changes from OFF to STOP (initialization) mode")); + Assert.That(result.Entries[1].Long_Text, Is.EqualTo("LONG TEXT")); + Assert.That(result.Entries[1].Event.Textlist_Id, Is.EqualTo(3)); + Assert.That(result.Entries[1].Event.Text_Id, Is.EqualTo(26315)); + Assert.That(result.Last_Modified, Is.EqualTo(expected)); + Assert.That(result.Count_Current, Is.EqualTo(1234)); + Assert.That(result.Count_Max, Is.EqualTo(3200)); + Assert.That(result.Language, Is.EqualTo("en-US")); }); } } diff --git a/tests/Webserver.API.UnitTests/ModelTests.cs b/tests/Webserver.API.UnitTests/ModelTests.cs index 4804a18..f692411 100644 --- a/tests/Webserver.API.UnitTests/ModelTests.cs +++ b/tests/Webserver.API.UnitTests/ModelTests.cs @@ -765,11 +765,11 @@ public void PlcDate_EqualsCheck() var equalsPD2 = new PlcDate(11, 5, ApiDayOfWeek.Sun, 2, 24); var notEqualsPD1 = new PlcDate(12, 5, ApiDayOfWeek.Sun, 2, 24); - Assert.IsTrue(equalsPD1.Equals(equalsPD2)); - Assert.IsTrue(equalsPD2.Equals(equalsPD1)); + Assert.That(equalsPD1.Equals(equalsPD2)); + Assert.That(equalsPD2.Equals(equalsPD1)); - Assert.IsFalse(equalsPD1.Equals(notEqualsPD1)); - Assert.IsFalse(equalsPD2.Equals(notEqualsPD1)); + Assert.That(notEqualsPD1, Is.Not.EqualTo(equalsPD1)); + Assert.That(notEqualsPD1, Is.Not.EqualTo(equalsPD2)); } [Test] @@ -793,11 +793,11 @@ public void DaylightSavingTimeConfiguration_EqualsCheck() var notequalsDST1 = new DaylightSavingsTimeConfiguration(notEqualsPD2, TimeSpan.FromMinutes(60)); var notequalsDST2 = new DaylightSavingsTimeConfiguration(equalsPD1, TimeSpan.FromMinutes(120)); - Assert.IsTrue(equalsDST1.Equals(equalsDST2)); - Assert.IsTrue(equalsDST2.Equals(equalsDST1)); + Assert.That(equalsDST1.Equals(equalsDST2)); + Assert.That(equalsDST2.Equals(equalsDST1)); - Assert.IsFalse(equalsDST1.Equals(notequalsDST1)); - Assert.IsFalse(equalsDST2.Equals(notequalsDST2)); + Assert.That(notequalsDST1, Is.Not.EqualTo(equalsDST1)); + Assert.That(notequalsDST2, Is.Not.EqualTo(equalsDST2)); } [Test] @@ -811,10 +811,10 @@ public void StandardTimeConfiguration_EqualsCheck() var equalsSTD2 = new StandardTimeConfiguration(equalsPD2); var notequalsSTD1 = new StandardTimeConfiguration(notEqualsPD2); - Assert.IsTrue(equalsSTD1.Equals(equalsSTD2)); - Assert.IsTrue(equalsSTD2.Equals(equalsSTD1)); + Assert.That(equalsSTD1.Equals(equalsSTD2)); + Assert.That(equalsSTD2.Equals(equalsSTD1)); - Assert.IsFalse(equalsSTD1.Equals(notequalsSTD1)); + Assert.That(notequalsSTD1, Is.Not.EqualTo(equalsSTD1)); } [Test] @@ -827,21 +827,24 @@ public void ApiSyslog_EqualsCheck() ApiPlcSyslog not_equal1 = new ApiPlcSyslog() { Count_Lost = 4, Count_Total = 100, Entries = apiSyslog_Entries }; ApiPlcSyslog not_equal2 = new ApiPlcSyslog() { Count_Lost = 5, Count_Total = 99, Entries = apiSyslog_Entries }; ApiPlcSyslog not_equal3 = new ApiPlcSyslog() { Count_Lost = 5, Count_Total = 100, Entries = apiSyslog_Entries_other }; - Assert.True(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); - Assert.True(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal1), $"{equal1.ToString()} \nequal\n{not_equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal2), $"{equal1.ToString()} \nequal\n{not_equal2.ToString()}"); - Assert.False(equal1.Equals(not_equal3), $"{equal1.ToString()} \nequal\n{not_equal3.ToString()}"); + Assert.That(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); + Assert.That(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); + + Assert.That(equal1, Is.Not.EqualTo(not_equal1)); + Assert.That(equal1, Is.Not.EqualTo(not_equal2)); + Assert.That(equal1, Is.Not.EqualTo(not_equal3)); } + [Test] public void ApiSyslog_Entry_EqualsCheck() { ApiPlcSyslog_Entry equal1 = new ApiPlcSyslog_Entry() { Raw = "random text" }; ApiPlcSyslog_Entry equal2 = new ApiPlcSyslog_Entry() { Raw = "random text" }; ApiPlcSyslog_Entry not_equal1 = new ApiPlcSyslog_Entry() { Raw = "random txet" }; - Assert.True(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); - Assert.True(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal1), $"{equal1.ToString()} \nequal\n{not_equal1.ToString()}"); + Assert.That(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); + Assert.That(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); + + Assert.That(equal1, Is.Not.EqualTo(not_equal1)); } [Test] public void ApiSyslog_HashCodeCheck() @@ -853,11 +856,12 @@ public void ApiSyslog_HashCodeCheck() ApiPlcSyslog not_equal1 = new ApiPlcSyslog() { Count_Lost = 4, Count_Total = 100, Entries = apiSyslog_Entries }; ApiPlcSyslog not_equal2 = new ApiPlcSyslog() { Count_Lost = 5, Count_Total = 101, Entries = apiSyslog_Entries }; ApiPlcSyslog not_equal3 = new ApiPlcSyslog() { Count_Lost = 5, Count_Total = 100, Entries = apiSyslog_Entries_other }; - Assert.AreEqual(equal1.GetHashCode(), equal1.GetHashCode(), $"equal1.GetHashCode() not equal equal1.GetHashCode()"); - Assert.AreEqual(equal1.GetHashCode(), equal2.GetHashCode(), $"equal1.GetHashCode() not equal equal2.GetHashCode()"); - Assert.That(equal1.GetHashCode() == not_equal1.GetHashCode(), $"equal1.GetHashCode() equal not_equal1.GetHashCode()"); - Assert.False(equal1.GetHashCode() == not_equal2.GetHashCode(), $"equal1.GetHashCode() equal not_equal2.GetHashCode()"); - Assert.False(equal1.GetHashCode() == not_equal3.GetHashCode(), $"equal1.GetHashCode() equal not_equal3.GetHashCode()"); + Assert.That(equal1.GetHashCode(), Is.EqualTo(equal1.GetHashCode()), "GetHashcode was not equal altough it should be"); + Assert.That(equal1.GetHashCode(), Is.EqualTo(equal2.GetHashCode()), "GetHashcode was not equal altough it should be"); + + Assert.That(equal1.GetHashCode(), Is.Not.EqualTo(not_equal1.GetHashCode()), "GetHashcode was equal altough it should not be"); + Assert.That(equal1.GetHashCode(), Is.Not.EqualTo(not_equal2.GetHashCode()), "GetHashcode was equal altough it should not be"); + Assert.That(equal1.GetHashCode(), Is.Not.EqualTo(not_equal3.GetHashCode()), "GetHashcode was equal altough it should not be"); } [Test] public void ApiSyslog_Entry_HashCodeCheck() @@ -867,7 +871,8 @@ public void ApiSyslog_Entry_HashCodeCheck() ApiPlcSyslog_Entry not_equal1 = new ApiPlcSyslog_Entry() { Raw = "random txet" }; Assert.That(equal1.GetHashCode(), Is.EqualTo(equal1.GetHashCode()), $"equal1.GetHashCode() not equal equal1.GetHashCode()"); Assert.That(equal1.GetHashCode(), Is.EqualTo(equal2.GetHashCode()), $"equal1.GetHashCode() not equal equal2.GetHashCode()"); - Assert.False(equal1.GetHashCode() == not_equal1.GetHashCode(), $"equal1.GetHashCode() equal not_equal1.GetHashCode()"); + + Assert.That(equal1.GetHashCode(), Is.Not.EqualTo(not_equal1.GetHashCode()), "GetHashcode was equal altough it should not be"); } [Test] @@ -876,9 +881,10 @@ public void ApiAlarms_EqualsCheck() ApiAlarms equal1 = new ApiAlarms() { Count_Current = 10, Count_Max = 1000, Language = "en-US", Last_Modified = new DateTime(2023, 6, 15, 10, 33, 24, 123) }; ApiAlarms equal2 = new ApiAlarms() { Count_Current = 10, Count_Max = 1000, Language = "en-US", Last_Modified = new DateTime(2023, 6, 15, 10, 33, 24, 123) }; ApiAlarms not_equal = new ApiAlarms() { Count_Current = 11, Count_Max = 1000, Language = "en-US", Last_Modified = new DateTime(2023, 6, 15, 10, 33, 24, 123) }; - Assert.True(equal1.Equals(equal2), $"{equal1.ToString()} not equal\n{equal2.ToString()}"); - Assert.True(equal2.Equals(equal1), $"{equal2.ToString()} not equal\n{equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal), $"{equal1.ToString()} equal\n{equal2.ToString()}"); + Assert.That(equal1.Equals(equal2), $"{equal1.ToString()} not equal\n{equal2.ToString()}"); + Assert.That(equal2.Equals(equal1), $"{equal2.ToString()} not equal\n{equal1.ToString()}"); + + Assert.That(equal1, Is.Not.EqualTo(not_equal), "was equal altough it should not be"); } [Test] @@ -920,9 +926,9 @@ public void ApiAlarms_Entry_EqualsCheck() Info_Text = "word", Text_Inconsistent = false }; - Assert.True(equal1.Equals(equal2), $"{equal1.ToString()} not equal\n{equal2.ToString()}"); - Assert.True(equal2.Equals(equal1), $"{equal2.ToString()} not equal\n{equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal), $"{equal1.ToString()} equal\n{equal2.ToString()}"); + Assert.That(equal1.Equals(equal2), $"{equal1.ToString()} not equal\n{equal2.ToString()}"); + Assert.That(equal2.Equals(equal1), $"{equal2.ToString()} not equal\n{equal1.ToString()}"); + Assert.That(equal1, Is.Not.EqualTo(not_equal)); } [Test] @@ -931,9 +937,10 @@ public void ApiAlarms_EntryAcknowledgement_EqualsCheck() ApiAlarms_EntryAcknowledgement equal1 = new ApiAlarms_EntryAcknowledgement() { State = ApiAlarmAcknowledgementState.Not_Acknowledged }; ApiAlarms_EntryAcknowledgement equal2 = new ApiAlarms_EntryAcknowledgement() { State = ApiAlarmAcknowledgementState.Not_Acknowledged }; ApiAlarms_EntryAcknowledgement not_equal = new ApiAlarms_EntryAcknowledgement() { State = ApiAlarmAcknowledgementState.Acknowledged, Timestamp = new DateTime(2023, 6, 15, 10, 33, 24, 123) }; - Assert.True(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); - Assert.True(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); - Assert.False(equal1.Equals(not_equal), $"{equal1.ToString()} \nequal\n{equal2.ToString()}"); + Assert.That(equal1.Equals(equal2), $"{equal1.ToString()} \nnot equal\n{equal2.ToString()}"); + Assert.That(equal2.Equals(equal1), $"{equal2.ToString()} \nnot equal\n{equal1.ToString()}"); + + Assert.That(equal1, Is.Not.EqualTo(not_equal)); } [Test] @@ -947,10 +954,12 @@ public void ApiDiagnosticBuffer_EqualsCheck() ApiDiagnosticBuffer not_equals4 = new ApiDiagnosticBuffer() { Count_Current = 10, Count_Max = 2400, Language = "en-US", Last_Modified = new DateTime(2021, 6, 15, 10, 33, 24, 123) }; Assert.That(equals1.Equals(equals2), $"{equals1.ToString()} not equal to\n {equals2.ToString()}"); Assert.That(equals2.Equals(equals1), $"{equals2.ToString()} not equal to\n {equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals1), $"{equals1.ToString()} equal to\n {not_equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals2), $"{equals1.ToString()} equal to\n {not_equals2.ToString()}"); - Assert.False(equals1.Equals(not_equals3), $"{equals1.ToString()} equal to\n {not_equals3.ToString()}"); - Assert.False(equals1.Equals(not_equals4), $"{equals1.ToString()} equal to\n {not_equals4.ToString()}"); + + + Assert.That(equals1, Is.Not.EqualTo(not_equals1)); + Assert.That(equals1, Is.Not.EqualTo(not_equals2)); + Assert.That(equals1, Is.Not.EqualTo(not_equals3)); + Assert.That(equals1, Is.Not.EqualTo(not_equals4)); } [Test] public void ApiDiagnosticBuffer_Entry_EqualsCheck() @@ -1020,11 +1029,12 @@ public void ApiDiagnosticBuffer_Entry_EqualsCheck() }; Assert.That(equals1.Equals(equals2), $"{equals1.ToString()} not equal to\n {equals2.ToString()}"); Assert.That(equals2.Equals(equals1), $"{equals2.ToString()} not equal to\n {equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals1), $"{equals1.ToString()} equal to\n {not_equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals2), $"{equals1.ToString()} equal to\n {not_equals2.ToString()}"); - Assert.False(equals1.Equals(not_equals3), $"{equals1.ToString()} equal to\n {not_equals3.ToString()}"); - Assert.False(equals1.Equals(not_equals4), $"{equals1.ToString()} equal to\n {not_equals4.ToString()}"); - Assert.False(equals1.Equals(not_equals5), $"{equals1.ToString()} equal to\n {not_equals5.ToString()}"); + + Assert.That(equals1, Is.Not.EqualTo(not_equals1)); + Assert.That(equals1, Is.Not.EqualTo(not_equals2)); + Assert.That(equals1, Is.Not.EqualTo(not_equals3)); + Assert.That(equals1, Is.Not.EqualTo(not_equals4)); + Assert.That(equals1, Is.Not.EqualTo(not_equals5)); } [Test] public void ApiDiagnosticBuffer_EntryEvent_EqualsCheck() @@ -1035,8 +1045,9 @@ public void ApiDiagnosticBuffer_EntryEvent_EqualsCheck() ApiDiagnosticBuffer_EntryEvent not_equals2 = new ApiDiagnosticBuffer_EntryEvent() { Textlist_Id = 2, Text_Id = 6 }; Assert.That(equals1.Equals(equals2), $"{equals1.ToString()} \n not equal to\n {equals2.ToString()}"); Assert.That(equals2.Equals(equals1), $"{equals2.ToString()} \n not equal to\n {equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals1), $"{equals1.ToString()} \n equal to\n {not_equals1.ToString()}"); - Assert.False(equals1.Equals(not_equals2), $"{equals1.ToString()} \n equal to\n {not_equals2.ToString()}"); + + Assert.That(equals1, Is.Not.EqualTo(not_equals1)); + Assert.That(equals1, Is.Not.EqualTo(not_equals2)); } } }