Exemple #1
0
        private bool Initialize()
        {
            IConfiguration configuration = GetConfiguration(SettingsLocation);

            if (configuration == null)
            {
                return(false);
            }

            _configuration = configuration;
            IConfigurationSectionGroup userGroup = this._configuration.GetSectionGroup(UserSettingsGroupName);

            if (userGroup == null)
            {
                userGroup = configuration.AddSectionGroup(UserSettingsGroupName);
            }

            ClientSettingsSection clientSettings = userGroup.Get(SettingsSection) as ClientSettingsSection;

            if (clientSettings == null)
            {
                clientSettings = new ClientSettingsSection();
                clientSettings.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
                clientSettings.SectionInformation.RequirePermission  = false;
                userGroup.Add(SettingsSection, clientSettings);
            }

            _clientSettings = clientSettings;
            return(true);
        }
Exemple #2
0
        public void RoundTripTest(string value)
        {
            // Ensure values round trip successfully
            IConfigurationSectionGroup sectionGroup  = Substitute.For <IConfigurationSectionGroup>();
            IConfiguration             configuration = Substitute.For <IConfiguration>();

            configuration.GetSectionGroup("userSettings").Returns(sectionGroup);
            IConfigurationManager configurationManager = Substitute.For <IConfigurationManager>();

            configurationManager.OpenConfiguration(ConfigurationUserLevel.None).ReturnsForAnyArgs(configuration);

            var testView = TestClientSettingsView.Create("Foo", SettingsLocation.Executable, configurationManager, null);

            testView.SaveSetting("foo", value).Should().BeTrue();
            testView.GetSetting("foo").Should().Be(value);
        }
Exemple #3
0
        public void InitializeCreatesClientSettingsSection()
        {
            // Ensure initialization creates a client settings section if it doesn't have one
            IConfigurationSectionGroup sectionGroup  = Substitute.For <IConfigurationSectionGroup>();
            IConfiguration             configuration = Substitute.For <IConfiguration>();

            configuration.GetSectionGroup("userSettings").Returns(sectionGroup);
            IConfigurationManager configurationManager = Substitute.For <IConfigurationManager>();

            configurationManager.OpenConfiguration(ConfigurationUserLevel.None).ReturnsForAnyArgs(configuration);

            var testView = TestClientSettingsView.Create("Foo", SettingsLocation.Executable, configurationManager, null);

            configuration.DidNotReceiveWithAnyArgs().AddSectionGroup("");
            sectionGroup.Received().Add("Foo", Arg.Any <ClientSettingsSection>());
        }