Skip to content

Commit

Permalink
fix: fixed tests and synchronization context check
Browse files Browse the repository at this point in the history
  • Loading branch information
iadonkey committed Oct 16, 2024
1 parent 4ff8006 commit ae4ba91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions TwinpackCore/Core/AutomationInterface4024.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override async Task<string> 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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<string?, string?>(projectName, plcName);
Expand Down Expand Up @@ -256,7 +256,7 @@ public override async Task<bool> 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))
Expand Down
2 changes: 1 addition & 1 deletion TwinpackCore/Core/VisualStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");

}
Expand Down
18 changes: 9 additions & 9 deletions TwinpackTests/TwinpackServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit ae4ba91

Please sign in to comment.