From ae4ba91360e0c651c93dfc4b76d3af2a7d118edc Mon Sep 17 00:00:00 2001 From: Donkey Date: Wed, 16 Oct 2024 22:23:10 +0200 Subject: [PATCH] fix: fixed tests and synchronization context check --- TwinpackCore/Core/AutomationInterface4024.cs | 8 ++++---- TwinpackCore/Core/VisualStudio.cs | 2 +- TwinpackTests/TwinpackServiceTest.cs | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/TwinpackCore/Core/AutomationInterface4024.cs b/TwinpackCore/Core/AutomationInterface4024.cs index 818a3d2..37dc503 100644 --- a/TwinpackCore/Core/AutomationInterface4024.cs +++ b/TwinpackCore/Core/AutomationInterface4024.cs @@ -69,7 +69,7 @@ public override async Task ResolveEffectiveVersionAsync(string projectNa protected ITcPlcLibrary ResolvePlaceholder(ITcPlcLibraryManager libManager, string placeholderName, out string distributorName, out string effectiveVersion) { - if (_thread != System.Threading.Thread.CurrentThread) + if (_thread != System.Threading.Thread.CurrentThread && _synchronizationContext != SynchronizationContext.Current) throw new Exception("Invalid synchronization context!"); // getter references might throw (Starting from TC3.1.4024.35) @@ -135,7 +135,7 @@ protected ITcPlcLibrary ResolvePlaceholder(ITcPlcLibraryManager libManager, stri protected ITcSysManager SystemManager(string projectName = null) { - if (_thread != System.Threading.Thread.CurrentThread) + if (_thread != System.Threading.Thread.CurrentThread && _synchronizationContext != SynchronizationContext.Current) throw new Exception("Invalid synchronization context!"); var ready = false; @@ -178,7 +178,7 @@ protected ITcSysManager SystemManager(string projectName = null) protected ITcPlcLibraryManager LibraryManager(string projectName = null, string plcName = null) { - if (_thread != System.Threading.Thread.CurrentThread) + if (_thread != System.Threading.Thread.CurrentThread && _synchronizationContext != SynchronizationContext.Current) throw new Exception("Invalid synchronization context!"); var key = new Tuple(projectName, plcName); @@ -256,7 +256,7 @@ public override async Task IsPackageInstalledAsync(PackageItem package) public override bool IsPackageInstalled(PackageItem package) { - if (_thread != System.Threading.Thread.CurrentThread) + if (_thread != System.Threading.Thread.CurrentThread && _synchronizationContext != SynchronizationContext.Current) throw new Exception("Invalid synchronization context!"); if (_referenceCache.Any(x => x.Name == package.PackageVersion.Title && x.DistributorName == package.PackageVersion.DistributorName && x.Version == package.PackageVersion.Version)) diff --git a/TwinpackCore/Core/VisualStudio.cs b/TwinpackCore/Core/VisualStudio.cs index 7876f1a..553bc92 100644 --- a/TwinpackCore/Core/VisualStudio.cs +++ b/TwinpackCore/Core/VisualStudio.cs @@ -61,7 +61,7 @@ public VisualStudio(DTE2 dte, EnvDTE.Solution solution) public void ThrowIfNotMainThread() { - if (_thread != System.Threading.Thread.CurrentThread) + if (_thread != System.Threading.Thread.CurrentThread && _synchronizationContext != SynchronizationContext.Current) throw new Exception("Invalid synchronization context!"); } diff --git a/TwinpackTests/TwinpackServiceTest.cs b/TwinpackTests/TwinpackServiceTest.cs index 626e902..6d17b91 100644 --- a/TwinpackTests/TwinpackServiceTest.cs +++ b/TwinpackTests/TwinpackServiceTest.cs @@ -639,12 +639,12 @@ public async Task DownloadPackageVersionAsync_PackagesWithDependencies() Assert.IsTrue(downloadedPackageVersions.Any(x => x.PackageVersion.Name == "ExternalLib2")); Assert.IsTrue(downloadedPackageVersions.Any(x => x.PackageVersion.Name == "ExternalLib3")); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZCore").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZPlatform").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZAux").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib1").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib2").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib3").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZCore").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZPlatform").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ZAux").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib1").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib2").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib3").PackageServer); Assert.IsTrue(downloadedPackageVersions.Select(x => x.Package.Branches).FirstOrDefault()?.Count() == 2); } @@ -765,9 +765,9 @@ public async Task DownloadPackageVersionAsync_IgnoreProvidedPackages() Assert.IsTrue(downloadedPackageVersions.Any(x => x.PackageVersion.Name == "ExternalLib2")); Assert.IsTrue(downloadedPackageVersions.Any(x => x.PackageVersion.Name == "ExternalLib3")); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib1").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib2").PackageServer); - Assert.Equals(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib3").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib1").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib2").PackageServer); + Assert.AreEqual(packageServer, downloadedPackageVersions.FirstOrDefault(x => x.PackageVersion.Name == "ExternalLib3").PackageServer); } [TestMethod]