public void DisposeTest()
        {
            var manager = new DynamicResourceManager("KGySoft.CoreLibraries.Resources.TestCompiledResource", GetType().Assembly, resXBaseName)
            {
                AutoSave = AutoSaveOptions.None
            };

            manager.Dispose();
            Throws <ObjectDisposedException>(() => manager.ReleaseAllResources());
            Throws <ObjectDisposedException>(() => manager.GetString("TestString"));
            manager.Dispose(); // this will not throw anything

            manager        = new DynamicResourceManager("KGySoft.CoreLibraries.Resources.TestCompiledResource", GetType().Assembly, resXBaseName);
            manager.Source = ResourceManagerSources.CompiledOnly;
            manager.Dispose();
            Throws <ObjectDisposedException>(() => manager.ReleaseAllResources());
            Throws <ObjectDisposedException>(() => manager.GetString("TestString"));
            manager.Dispose(); // this will not throw anything
        }
        public void AutoSaveTest()
        {
            LanguageSettings.DynamicResourceManagersAutoAppend = AutoAppendOptions.None;
            string key     = "testKey";
            string value   = "test value";
            var    manager = new DynamicResourceManager("KGySoft.CoreLibraries.Resources.TestCompiledResource", GetType().Assembly, resXBaseName)
            {
                AutoAppend = AutoAppendOptions.None,
            };
            CultureInfo testCulture = hu;

            void Cleanup()
            {
                //foreach (CultureInfo culture in cultures)
                File.Delete(Path.Combine(Path.Combine(Files.GetExecutingPath(), manager.ResXResourcesDir), $"{resXBaseName}.{testCulture.Name}.resx"));
            }

            try
            {
                // SourceChange, individual
                Cleanup();
                manager.Source = ResourceManagerSources.CompiledAndResX;
                manager.UseLanguageSettings = false;
                manager.AutoSave            = AutoSaveOptions.SourceChange;

                manager.SetObject(key, value, testCulture);
                manager.Source = ResourceManagerSources.ResXOnly;                   // save occurs
                manager.ReleaseAllResources();
                Assert.IsNull(manager.GetResourceSet(testCulture, false, false));   // not loaded after release
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false)); // but can be loaded from saved

                // SourceChange, central
                Cleanup();
                manager.ReleaseAllResources();
                LanguageSettings.DynamicResourceManagersSource = ResourceManagerSources.CompiledAndResX;
                manager.UseLanguageSettings = true;
                LanguageSettings.DynamicResourceManagersAutoSave = AutoSaveOptions.SourceChange;

                manager.SetObject(key, value, testCulture);
                LanguageSettings.DynamicResourceManagersSource = ResourceManagerSources.ResXOnly; // save occurs
                manager.ReleaseAllResources();
                Assert.IsNull(manager.GetResourceSet(testCulture, false, false));                 // not loaded after release
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false));               // but can be loaded from saved

                // LanguageChange, individual
                Cleanup();
                manager.ReleaseAllResources();
                manager.UseLanguageSettings      = false;
                LanguageSettings.DisplayLanguage = testCulture;
                manager.AutoSave = AutoSaveOptions.LanguageChange;

                manager.SetObject(key, value);                                      // null: uses DisplayLanguage, which is the same as CurrentUICulture
                LanguageSettings.DisplayLanguage = inv;                             // save occurs
                manager.ReleaseAllResources();
                Assert.IsNull(manager.GetResourceSet(testCulture, false, false));   // not loaded after release
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false)); // but can be loaded from saved

                // LanguageChange, central
                Cleanup();
                manager.ReleaseAllResources();
                manager.UseLanguageSettings      = true;
                LanguageSettings.DisplayLanguage = testCulture;
                LanguageSettings.DynamicResourceManagersAutoSave = AutoSaveOptions.LanguageChange;

                manager.SetObject(key, value);                                      // null: uses DisplayLanguage, which is the same as CurrentUICulture
                LanguageSettings.DisplayLanguage = inv;                             // save occurs
                manager.ReleaseAllResources();
                Assert.IsNull(manager.GetResourceSet(testCulture, false, false));   // not loaded after release
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false)); // but can be loaded from saved

#if !(NETCOREAPP2_0 || NETCOREAPP3_0)
                // DomainUnload, individual
                Cleanup();
                manager.ReleaseAllResources();
                Evidence     evidence      = new Evidence(AppDomain.CurrentDomain.Evidence);
                AppDomain    sandboxDomain = AppDomain.CreateDomain("SandboxDomain", evidence, AppDomain.CurrentDomain.BaseDirectory, null, false);
                AssemblyName selfName      = Assembly.GetExecutingAssembly().GetName();
                sandboxDomain.Load(selfName);

                RemoteDrmConsumer remote = (RemoteDrmConsumer)sandboxDomain.CreateInstanceAndUnwrap(selfName.FullName, typeof(RemoteDrmConsumer).FullName);
                remote.UseDrmRemotely(false, testCulture);
                AppDomain.Unload(sandboxDomain);
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false)); // can be loaded that has been saved in another domain

                // DomainUnload, central
                Cleanup();
                manager.ReleaseAllResources();
                evidence      = new Evidence(AppDomain.CurrentDomain.Evidence);
                sandboxDomain = AppDomain.CreateDomain("SandboxDomain", evidence, AppDomain.CurrentDomain.BaseDirectory, null, false);
                selfName      = Assembly.GetExecutingAssembly().GetName();
                sandboxDomain.Load(selfName);

                remote = (RemoteDrmConsumer)sandboxDomain.CreateInstanceAndUnwrap(selfName.FullName, typeof(RemoteDrmConsumer).FullName);
                remote.UseDrmRemotely(true, testCulture);
                AppDomain.Unload(sandboxDomain);
                Assert.IsNotNull(manager.GetResourceSet(testCulture, true, false)); // can be loaded that has been saved in another domain
#endif

                // Dispose, individual
                Cleanup();
                manager.UseLanguageSettings = false;
                manager.Source = ResourceManagerSources.CompiledAndResX;
                manager.UseLanguageSettings = false;
                manager.AutoSave            = AutoSaveOptions.Dispose;

                manager.SetObject(key, value, testCulture);
                manager.Dispose(); // save occurs
                Throws <ObjectDisposedException>(() => manager.GetResourceSet(testCulture, false, false));
                Assert.IsTrue(File.Exists(Path.Combine(Path.Combine(Files.GetExecutingPath(), manager.ResXResourcesDir), $"TestResourceResX.{testCulture.Name}.resx")));

                // Dispose, central
                LanguageSettings.DynamicResourceManagersSource   = ResourceManagerSources.CompiledAndResX;
                LanguageSettings.DynamicResourceManagersAutoSave = AutoSaveOptions.Dispose;
                manager = new DynamicResourceManager("KGySoft.CoreLibraries.Resources.TestCompiledResource", GetType().Assembly, resXBaseName)
                {
                    UseLanguageSettings = true
                };
                Cleanup();

                manager.SetObject(key, value, testCulture);
                LanguageSettings.DisplayLanguage = inv; // save occurs
                manager.Dispose();                      // save occurs
                Throws <ObjectDisposedException>(() => manager.GetResourceSet(testCulture, false, false));
                Assert.IsTrue(File.Exists(Path.Combine(Path.Combine(Files.GetExecutingPath(), manager.ResXResourcesDir), $"TestResourceResX.{testCulture.Name}.resx")));

                // final cleanup
                Cleanup();
            }
            finally
            {
                Cleanup();
            }
        }