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);
        }
Exemple #2
0
        public void ShouldGetCustomSettingsAsync()
        {
            // Arrange
            ICustomSettingsApi settingsApi = CreateSettingsApi();

            // Act
            IEnumerable <string> names = settingsApi.GetCustomSettingsAsync().Result;

            // Assert
            names.Single().ShouldBe("preferences");
        }
Exemple #3
0
        public void ShouldGetCustomSettingsAsync()
        {
            // Arrange
            ICustomSettingsApi settingsApi = CreateSettingsApi();

            // Act
            IEnumerable<string> names = settingsApi.GetCustomSettingsAsync().Result.Records.Select(x => x.Name);

            // Assert
            names.ShouldContain("preferences");
        }
        public async Task RunAsync(IRestContext context)
        {
            ICustomSettingsApi settingsApi = context.Factory.CreateUserCustomSettingsApi();

            // Setting some preferences
            List <CustomRequest> customSettings = new List <CustomRequest>
            {
                new CustomRequest
                {
                    Name  = "Language",
                    Value = "en-us"
                },
                new CustomRequest
                {
                    Name  = "TimeZone",
                    Value = "ET"
                }
            };

            if ((await settingsApi.SetCustomSettingsAsync(customSettings)).Records.Any())
            {
                Console.WriteLine("Created custom settings: preferences");
            }

            // Retrieving custom settings names
            IEnumerable <string> names = (await settingsApi.GetCustomSettingsAsync()).Records.Select(x => x.Name);
            string flatList            = string.Join(", ", names);

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

            // Retrieving preferences back
            CustomResponse custom = await settingsApi.GetCustomSettingAsync("Language");

            Console.WriteLine("Retrieved preferences back:");
            Console.WriteLine("\tName={0}, Value={1}", "Language", custom.Value);

            // Deleting preferences
            await settingsApi.DeleteCustomSettingAsync("Language");

            Console.WriteLine("Deleted Language preferences!");
            await settingsApi.DeleteCustomSettingAsync("TimeZone");

            Console.WriteLine("Deleted TimeZone preferences!");
        }