diff --git a/SafeExamBrowser.Configuration.UnitTests/ConfigurationRepositoryTests.cs b/SafeExamBrowser.Configuration.UnitTests/ConfigurationRepositoryTests.cs index 96283c33..777a1515 100644 --- a/SafeExamBrowser.Configuration.UnitTests/ConfigurationRepositoryTests.cs +++ b/SafeExamBrowser.Configuration.UnitTests/ConfigurationRepositoryTests.cs @@ -54,6 +54,8 @@ namespace SafeExamBrowser.Configuration.UnitTests fileSaver.Setup(f => f.CanSave(It.IsAny())).Returns(u => u.IsFile); networkLoader.Setup(n => n.CanLoad(It.IsAny())).Returns(u => u.Scheme.Equals("http") || u.Scheme.Equals("seb")); + SetEntryAssembly(); + sut = new ConfigurationRepository(certificateStore.Object, hashAlgorithm.Object, logger.Object); sut.InitializeAppConfig(); } @@ -327,5 +329,22 @@ namespace SafeExamBrowser.Configuration.UnitTests sut.Register(xmlParser.Object); sut.Register(xmlSerializer.Object); } + + /// + /// Hack required for unit tests to be able to retrieve the while executing. + /// + public void SetEntryAssembly() + { + var assembly = Assembly.GetCallingAssembly(); + var manager = new AppDomainManager(); + var entryAssemblyfield = manager.GetType().GetField("m_entryAssembly", BindingFlags.Instance | BindingFlags.NonPublic); + + entryAssemblyfield.SetValue(manager, assembly); + + var domain = AppDomain.CurrentDomain; + var domainManagerField = domain.GetType().GetField("_domainManager", BindingFlags.Instance | BindingFlags.NonPublic); + + domainManagerField.SetValue(domain, manager); + } } }