public void Constructor_WhenFileIsValid_InitializesPreferenceSetFile()
            {
                var file = new FileInfo(@"C:\Foo\Prefs.gallioprefs");

                var preferenceSet = new FilePreferenceSet(file);

                Assert.AreEqual(file, preferenceSet.PreferenceSetFile);
            }
            public void Constructor_WhenFileIsValid_InitializesPreferenceSetFile()
            {
                var file = new FileInfo(@"C:\Foo\Prefs.gallioprefs");

                var preferenceSet = new FilePreferenceSet(file);

                Assert.AreEqual(file, preferenceSet.PreferenceSetFile);
            }
            public void ShouldMigrateSettingsAcrossInstancesWhenFileModifiedExternally()
            {
                var firstPreferenceSet  = CreateFilePreferenceSetWithNonExistantTempFile();
                var secondPreferenceSet = new FilePreferenceSet(firstPreferenceSet.PreferenceSetFile);

                firstPreferenceSet.Write(writer => writer.SetSetting(new Key <string>("name"), "value"));
                Assert.AreEqual("value", secondPreferenceSet.Read(reader => reader.GetSetting(new Key <string>("name"))),
                                "Setting written to first set should be reflected in second set.");

                secondPreferenceSet.Write(writer => writer.SetSetting(new Key <string>("name"), "newValue"));
                Assert.AreEqual("newValue", firstPreferenceSet.Read(reader => reader.GetSetting(new Key <string>("name"))),
                                "Setting written to second set should be reflected in first set.");
            }
        private IPreferenceSet GetPreferenceSet(string preferenceSetName)
        {
            lock (cachedPreferenceSets)
            {
                IPreferenceSet result;
                if (!cachedPreferenceSets.TryGetValue(preferenceSetName, out result))
                {
                    FileInfo preferenceSetFile = new FileInfo(Path.Combine(preferenceStoreDir.FullName,
                        FileUtils.EncodeFileName(preferenceSetName) + ".gallioprefs"));
                    result = new FilePreferenceSet(preferenceSetFile);
                    cachedPreferenceSets.Add(preferenceSetName, result);
                }

                return result;
            }
        }
            public void ShouldMigrateSettingsAcrossInstancesWhenFileModifiedExternally()
            {
                var firstPreferenceSet = CreateFilePreferenceSetWithNonExistantTempFile();
                var secondPreferenceSet = new FilePreferenceSet(firstPreferenceSet.PreferenceSetFile);

                firstPreferenceSet.Write(writer => writer.SetSetting(new Key<string>("name"), "value"));
                Assert.AreEqual("value", secondPreferenceSet.Read(reader => reader.GetSetting(new Key<string>("name"))),
                    "Setting written to first set should be reflected in second set.");

                secondPreferenceSet.Write(writer => writer.SetSetting(new Key<string>("name"), "newValue"));
                Assert.AreEqual("newValue", firstPreferenceSet.Read(reader => reader.GetSetting(new Key<string>("name"))),
                    "Setting written to second set should be reflected in first set.");
            }