/// <summary>
        /// Saves the plugin's options.
        /// </summary>
        /// <param name="plugin"></param>
        /// <param name="options"></param>
        public void Save(Plugin plugin, Options options)
        {
            var storage = Factory.Singleton.Resolve<IPluginSettingsStorage>().Singleton;

            var pluginSettings = storage.Load();
            pluginSettings.Write(plugin, EnabledField, options.Enabled);
            pluginSettings.Write(plugin, AllowUpdateOfOtherDatabasesField, options.AllowUpdateOfOtherDatabases);

            storage.Save(pluginSettings);
        }
        /// <summary>
        /// Loads the plugin's options.
        /// </summary>
        /// <param name="plugin"></param>
        /// <returns></returns>
        public Options Load(Plugin plugin)
        {
            var storage = Factory.Singleton.Resolve<IPluginSettingsStorage>().Singleton;
            var pluginSettings = storage.Load();

            return new Options() {
                Enabled = pluginSettings.ReadBool(plugin, EnabledField).GetValueOrDefault(),
                AllowUpdateOfOtherDatabases = pluginSettings.ReadBool(plugin, AllowUpdateOfOtherDatabasesField).GetValueOrDefault(),
            };
        }
        public void TestInitialise()
        {
            _AutoConfigMessageListener = TestUtilities.CreateMockSingleton<IAutoConfigListener>();
            _Listener = TestUtilities.CreateMockImplementation<IListener>();
            _AutoConfigMessageListener.Setup(r => r.Listener).Returns(_Listener.Object);

            _StartupParameters = new PluginStartupParameters(null, null, null, null);
            _ClassFactorySnapshot = Factory.TakeSnapshot();
            _PluginSettingsStorage = TestUtilities.CreateMockSingleton<IPluginSettingsStorage>();
            _PluginSettings = new PluginSettings();
            _PluginSettingsStorage.Setup(s => s.Load()).Returns(_PluginSettings);
            _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>();
            _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true);

            _BaseStationDatabase = new Mock<IBaseStationDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _BaseStationDatabase.Object.FileName = "fn";
            _AutoConfigBaseStationDatabase = TestUtilities.CreateMockSingleton<IAutoConfigBaseStationDatabase>();
            _AutoConfigBaseStationDatabase.Setup(a => a.Database).Returns(_BaseStationDatabase.Object);

            _BaseStationDatabase.Setup(d => d.GetLocations()).Returns(new List<BaseStationLocation>() { new BaseStationLocation() { LocationID = 9821 } } );
            SetDBHistory(true);

            _StandingDataManager = TestUtilities.CreateMockSingleton<IStandingDataManager>();
            _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>();
            _Log = TestUtilities.CreateMockSingleton<ILog>();

            _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>();
            _Configuration = new Configuration();
            _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration);

            _StatusChangedEvent = new EventRecorder<EventArgs>();

            _Plugin = new PluginNS.Plugin();
            _Provider = new Mock<PluginNS.IPluginProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _Provider.Setup(p => p.FileExists(It.IsAny<string>())).Returns(true);
            _Provider.Setup(p => p.LocalNow).Returns(new DateTime(2001, 2, 3, 4, 5, 6));
            _Provider.Setup(p => p.FileSize(It.IsAny<string>())).Returns(1000000L);
            _OptionsView = new Mock<PluginNS.IOptionsView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _Provider.Setup(p => p.CreateOptionsView()).Returns(_OptionsView.Object);
            _Plugin.Provider = _Provider.Object;
        }
        public void Plugin_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            _Plugin = new PluginNS.Plugin();
            Assert.IsNotNull(_Plugin.Provider);
            TestUtilities.TestProperty(_Plugin, r => r.Provider, _Plugin.Provider, _Provider.Object);

            Assert.AreEqual("VirtualRadar.Plugin.BaseStationDatabaseWriter", _Plugin.Id);
            Assert.IsFalse(String.IsNullOrEmpty(_Plugin.Name));
            Assert.IsFalse(String.IsNullOrEmpty(_Plugin.Version));
            Assert.AreEqual("Disabled", _Plugin.Status);
            Assert.AreEqual(null, _Plugin.StatusDescription);
            Assert.IsTrue(_Plugin.HasOptions);
        }