public void GetMobileAppSettings_SetsAllKnownProperties()
        {
            // Arrange
            MobileAppSettingsProvider settingsProvider = new MobileAppSettingsProvider();

            // Act
            MobileAppSettingsDictionary actual = settingsProvider.GetMobileAppSettings();

            // Assert
            PropertyInfo[] properties = typeof(MobileAppSettingsDictionary).GetProperties();
            foreach (PropertyInfo p in properties)
            {
                // Skipping dictionary accessors
                if (p.Name == "Item")
                {
                    continue;
                }

                if (p.CanWrite)
                {
                    MethodInfo isSet  = isSetMethod.MakeGenericMethod(p.PropertyType);
                    bool       result = (bool)isSet.Invoke(this, new object[] { p.GetValue(actual) });
                    Assert.True(result, string.Format("Property '{0}' was not set. Please ensure that the value is present in app.config for this test project and that the MobileAppSettingsProvider sets the value.", p.Name));
                }
            }

            Assert.True(actual.Connections.Count > 0);
        }
        public void GetMobileAppSettings_SetsCustomProperties()
        {
            // Arrange
            MobileAppSettingsProvider settingsProvider = new MobileAppSettingsProvider();

            // Act
            MobileAppSettingsDictionary actual = settingsProvider.GetMobileAppSettings();

            // Assert
            Assert.Equal(actual["SampleKey"], "SampleValue");
        }
        public void GetMobileAppSettings_ReturnsSameInstance()
        {
            // Arrange
            MobileAppSettingsProvider settingsProvider = new MobileAppSettingsProvider();

            // Act
            MobileAppSettingsDictionary settings1 = settingsProvider.GetMobileAppSettings();
            MobileAppSettingsDictionary settings2 = settingsProvider.GetMobileAppSettings();

            // Assert
            Assert.Same(settings1, settings2);
        }
        public void SetMobileAppSettingsProvider_Roundtrips()
        {
            // Arrange
            MobileAppSettingsProvider provider = new MobileAppSettingsProvider();
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.SetMobileAppSettingsProvider(provider);
            IMobileAppSettingsProvider actual = config.GetMobileAppSettingsProvider();

            // Assert
            Assert.Same(provider, actual);
        }
        /// <summary>
        /// Gets the <see cref="Microsoft.Azure.Mobile.Server.Config.IMobileAppSettingsProvider"/> registered with the current <see cref="System.Web.Http.HttpConfiguration" />.
        /// </summary>
        /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param>
        /// <returns>The registered instance.</returns>
        public static IMobileAppSettingsProvider GetMobileAppSettingsProvider(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            IMobileAppSettingsProvider provider = null;
            if (!config.Properties.TryGetValue(MobileAppSettingsProviderKey, out provider))
            {
                provider = new MobileAppSettingsProvider();
                config.Properties[MobileAppSettingsProviderKey] = provider;
            }

            return provider;
        }