本文整理汇总了C#中ConfigurationManager.RequestRefresh方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationManager.RequestRefresh方法的具体用法?C# ConfigurationManager.RequestRefresh怎么用?C# ConfigurationManager.RequestRefresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigurationManager
的用法示例。
在下文中一共展示了ConfigurationManager.RequestRefresh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigurationManager_GetSets
public void ConfigurationManager_GetSets()
{
ConfigurationManager<OpenIdConnectConfiguration> configManager = new ConfigurationManager<OpenIdConnectConfiguration>("OpenIdConnectMetadata.json");
Type type = typeof(ConfigurationManager<OpenIdConnectConfiguration>);
PropertyInfo[] properties = type.GetProperties();
if (properties.Length != 2)
Assert.Fail("Number of properties has changed from 2 to: " + properties.Length + ", adjust tests");
TimeSpan defaultAutomaticRefreshInterval = ConfigurationManager<OpenIdConnectConfiguration>.DefaultAutomaticRefreshInterval;
TimeSpan defaultRefreshInterval = ConfigurationManager<OpenIdConnectConfiguration>.DefaultRefreshInterval;
GetSetContext context =
new GetSetContext
{
PropertyNamesAndSetGetValue = new List<KeyValuePair<string, List<object>>>
{
new KeyValuePair<string, List<object>>("AutomaticRefreshInterval", new List<object>{defaultAutomaticRefreshInterval, TimeSpan.FromHours(1), TimeSpan.FromHours(10)}),
new KeyValuePair<string, List<object>>("RefreshInterval", new List<object>{defaultRefreshInterval, TimeSpan.FromHours(1), TimeSpan.FromHours(10)}),
},
Object = configManager,
};
TestUtilities.GetSet(context);
TestUtilities.AssertFailIfErrors(MethodInfo.GetCurrentMethod().Name, context.Errors);
TestUtilities.SetGet(configManager, "AutomaticRefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10107:"));
TestUtilities.SetGet(configManager, "RefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10106:"));
TestUtilities.SetGet(configManager, "RefreshInterval", Timeout.InfiniteTimeSpan, ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10106:"));
// AutomaticRefreshInterval interval should return same config.
OpenIdConnectConfiguration configuration = configManager.GetConfigurationAsync().Result;
TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json");
OpenIdConnectConfiguration configuration2 = configManager.GetConfigurationAsync().Result;
Assert.IsTrue(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
Assert.IsTrue(object.ReferenceEquals(configuration, configuration2));
// AutomaticRefreshInterval should pick up new bits.
configManager = new ConfigurationManager<OpenIdConnectConfiguration>("OpenIdConnectMetadata.json");
TestUtilities.SetField(configManager, "_automaticRefreshInterval", TimeSpan.FromMilliseconds(1));
configuration = configManager.GetConfigurationAsync().Result;
Thread.Sleep(1);
TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json");
configuration2 = configManager.GetConfigurationAsync().Result;
Assert.IsFalse(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
Assert.IsFalse(object.ReferenceEquals(configuration, configuration2));
// RefreshInterval is set to MaxValue
configManager = new ConfigurationManager<OpenIdConnectConfiguration>("OpenIdConnectMetadata.json");
configuration = configManager.GetConfigurationAsync().Result;
configManager.RefreshInterval = TimeSpan.MaxValue;
TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json");
configuration2 = configManager.GetConfigurationAsync().Result;
Assert.IsTrue(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
Assert.IsTrue(object.ReferenceEquals(configuration, configuration2));
// Refresh should have no effect
configManager = new ConfigurationManager<OpenIdConnectConfiguration>("OpenIdConnectMetadata.json");
configuration = configManager.GetConfigurationAsync().Result;
configManager.RefreshInterval = TimeSpan.FromHours(10);
configManager.RequestRefresh();
configuration2 = configManager.GetConfigurationAsync().Result;
Assert.IsTrue(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
Assert.IsTrue(object.ReferenceEquals(configuration, configuration2));
// Refresh should force pickup of new config
configManager = new ConfigurationManager<OpenIdConnectConfiguration>("OpenIdConnectMetadata.json");
configuration = configManager.GetConfigurationAsync().Result;
TestUtilities.SetField(configManager, "_refreshInterval", TimeSpan.FromMilliseconds(1));
Thread.Sleep(1);
configManager.RequestRefresh();
TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json");
configuration2 = configManager.GetConfigurationAsync().Result;
Assert.IsFalse(object.ReferenceEquals(configuration, configuration2));
Assert.IsFalse(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
// Refresh set to MaxValue
configManager.RefreshInterval = TimeSpan.MaxValue;
configuration = configManager.GetConfigurationAsync().Result;
Assert.IsTrue(object.ReferenceEquals(configuration, configuration2));
Assert.IsTrue(IdentityComparer.AreEqual<OpenIdConnectConfiguration>(configuration, configuration2));
}
开发者ID:vebin,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:81,代码来源:ConfigurationManagerTests.cs