Esempio n. 1
0
        public async Task RunAsync(IRestContext context)
        {
            ICustomSettingsApi settingsApi = context.Factory.CreateUserCustomSettingsApi();

            // Setting some preferences
            UserPreferences preferences = new UserPreferences
            {
                flag   = true,
                array  = new[] { "a", "b", "c" },
                entity = new UserPreferences.Entity {
                    rank = 4, role = "user"
                }
            };

            if (await settingsApi.SetCustomSettingAsync("preferences", preferences))
            {
                Console.WriteLine("Created custom settings: preferences");
            }

            // Retrieving custom settings names
            IEnumerable <string> names = await settingsApi.GetCustomSettingsAsync();

            string flatList = string.Join(", ", names);

            Console.WriteLine("Retrieved available setting names: [{0}]", flatList);

            // Retrieving preferences back
            UserPreferences instance = await settingsApi.GetCustomSettingAsync <UserPreferences>("preferences");

            Console.WriteLine("Retrieved preferences back:");
            Console.WriteLine("\tpreferences.flag={0}, preferences.entity.rank={1}", instance.flag, instance.entity.rank);
        }
Esempio n. 2
0
        public void ShouldSetCustomSettingAsync()
        {
            // Arrange
            ICustomSettingsApi settingsApi = CreateSettingsApi();
            UserPreferences    preferences = CreateUserPreferences();

            // Act
            bool ok = settingsApi.SetCustomSettingAsync("preferences", preferences).Result;

            // Assert
            ok.ShouldBe(true);
        }