public async Task ClientIsEuOnlyAndOrgSettingIsGlobal_FirstRequestInvokesEuAfterAllRequestsInvokeGlobal() { // Arrange var fetchConfig = new AutoPollConfiguration { SdkKey = "SDK-KEY", DataGovernance = DataGovernance.EuOnly }; var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { GlobalCdnUri.Host, CreateResponse() }, { EuOnlyCdnUri.Host, CreateResponse() } }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3, requests.Count); Assert.AreEqual(EuOnlyCdnUri.Host, requests[1].RequestUri.Host); Assert.IsTrue(requests.Values.Skip(1).All(message => message.RequestUri.Host == GlobalCdnUri.Host)); }
public async Task ClientIsEuOnlyAndOrgIsForced_AllRequestInvokeForcedUri() { // Arrange var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { EuOnlyCdnUri.Host, CreateResponse(ForcedCdnUri.ToString(), RedirectMode.Force, false) }, { ForcedCdnUri.Host, CreateResponse(ForcedCdnUri.ToString(), RedirectMode.Force, true) } }; var fetchConfig = new AutoPollConfiguration { DataGovernance = DataGovernance.EuOnly }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3 + 1, requests.Count); Assert.AreEqual(EuOnlyCdnUri.Host, requests[1].RequestUri.Host); Assert.IsTrue(requests.Values.Skip(1).All(m => m.RequestUri.Host == ForcedCdnUri.Host)); }
public async Task ClientIsGlobalAndOrgSettingIsEuOnly_FirstRequestInvokesGlobalAndRedirectToEuAfterAllRequestsInvokeEu() { // Arrange var fetchConfig = new AutoPollConfiguration { SdkKey = "SDK-KEY", DataGovernance = DataGovernance.Global }; var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { GlobalCdnUri.Host, CreateResponse(ConfigurationBase.BaseUrlEu, RedirectMode.Should, false) }, { EuOnlyCdnUri.Host, CreateResponse(ConfigurationBase.BaseUrlEu, RedirectMode.No, true) } }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3 + 1, requests.Count); Assert.AreEqual(GlobalCdnUri.Host, requests[1].RequestUri.Host); Assert.AreEqual(EuOnlyCdnUri.Host, requests[2].RequestUri.Host); Assert.IsTrue(requests.Values.Skip(2).All(m => m.RequestUri.Host == EuOnlyCdnUri.Host)); }
public async Task ClientIsGlobalAndHasCustomBaseUriAndOrgIsForced_FirstRequestInvokeCustomAndRedirectToForceUriAndAllRequestInvokeForcedUri() { // Arrange var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { CustomCdnUri.Host, CreateResponse(ForcedCdnUri.ToString(), RedirectMode.Force, false) }, { ForcedCdnUri.Host, CreateResponse(ForcedCdnUri.ToString(), RedirectMode.Force, true) } }; var fetchConfig = new AutoPollConfiguration { DataGovernance = DataGovernance.Global, BaseUrl = CustomCdnUri }; // Act var responses = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3 + 1, responses.Count); Assert.AreEqual(CustomCdnUri.Host, responses[1].RequestUri.Host); Assert.IsTrue(responses.Values.Skip(1).All(m => m.RequestUri.Host == ForcedCdnUri.Host)); }
public void CreateAnInstance_WithValidConfiguration_ShouldCreateAnInstance() { var config = new AutoPollConfiguration { ProjectSecret = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf" }; new BetterConfigClient(config); }
public void CreateAnInstance_WhenConfigurationProjectSecretIsEmpty_ShouldThrowArgumentNullException() { var clientConfiguration = new AutoPollConfiguration { ProjectSecret = string.Empty }; new BetterConfigClient(clientConfiguration); }
public void CreateAnInstance_WhenConfigurationSdkKeyIsEmpty_ShouldThrowArgumentNullException() { var clientConfiguration = new AutoPollConfiguration { SdkKey = string.Empty }; new ConfigCatClient(clientConfiguration); }
public void CreateAnInstance_WithValidConfiguration_ShouldCreateAnInstance() { var config = new AutoPollConfiguration { SdkKey = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf" }; new ConfigCatClient(config); }
public void CreateAnInstance_WhenAutoPollConfigurationApiKeyIsNull_ShouldThrowArgumentNullException() { var clientConfiguration = new AutoPollConfiguration { ApiKey = null }; new ConfigCatClient(clientConfiguration); }
public void CreateAnInstance_WhenAutoPollConfigurationPollIntervalsZero_ShouldThrowArgumentOutOfRangeException() { var clientConfiguration = new AutoPollConfiguration { SdkKey = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf", PollIntervalSeconds = 0 }; new ConfigCatClient(clientConfiguration); }
public void CreateAnInstance_WhenLoggerIsNull_ShouldThrowArgumentNullException() { var clientConfiguration = new AutoPollConfiguration { SdkKey = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf", Logger = null }; new ConfigCatClient(clientConfiguration); }
public void CreateAnInstance_WhenLoggerFactoryIsNull_ShouldThrowArgumentNullException() { var clientConfiguration = new AutoPollConfiguration { ProjectSecret = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf", LoggerFactory = null }; new BetterConfigClient(clientConfiguration); }
public static void AddConfigCat(this IServiceCollection services, string apiKey) { var clientConfiguration = new AutoPollConfiguration { ApiKey = apiKey, PollIntervalSeconds = 15 }; services.AddSingleton <IConfigCatClient>(new ConfigCatClient(clientConfiguration)); }
public async Task WithDataGovernanceSetting_ShouldUseProperCdnUrl(DataGovernance dataGovernance, string expectedUrl) { // Arrange var configuration = new AutoPollConfiguration { SdkKey = "DEMO", DataGovernance = dataGovernance }; byte requestCount = 0; var requests = new SortedList <byte, HttpRequestMessage>(); var handlerMock = new Mock <HttpClientHandler>(MockBehavior.Strict); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) .Callback <HttpRequestMessage, CancellationToken>((message, _) => { requests.Add(requestCount++, message); }) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent("{\"p\": {\"u\": \"http://example.com\", \"r\": 0}}"), }) .Verifiable(); IConfigFetcher fetcher = new HttpConfigFetcher( configuration.CreateUri(), "DEMO", Mock.Of <ILogger>(), handlerMock.Object, Mock.Of <IConfigDeserializer>(), configuration.IsCustomBaseUrl); // Act await fetcher.Fetch(ProjectConfig.Empty); // Assert handlerMock.VerifyAll(); Assert.AreEqual(1, requestCount); Assert.AreEqual(new Uri(expectedUrl).Host, requests[0].RequestUri.Host); }
static void Main(string[] args) { string filePath = System.IO.Path.Combine(Environment.CurrentDirectory, "configcat.log"); LogLevel logLevel = LogLevel.Warning; // I would like to log only WARNING and higher entires (Warnings and Errors). var clientConfiguration = new AutoPollConfiguration { SdkKey = "YOUR-SDK-KEY", Logger = new MyFileLogger(filePath, logLevel), PollIntervalSeconds = 5 }; IConfigCatClient client = new ConfigCatClient(clientConfiguration); var feature = client.GetValue("keyNotExists", "N/A"); Console.ReadKey(); }
public async Task ClientIsGlobalAndOrgSettingIsGlobal_AllRequestsInvokeGlobalCdn() { // Arrange var fetchConfig = new AutoPollConfiguration { SdkKey = "SDK-KEY", DataGovernance = DataGovernance.Global }; var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { GlobalCdnUri.Host, CreateResponse() } }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.IsTrue(requests.Values.All(message => message.RequestUri.Host == GlobalCdnUri.Host)); }
public async Task TestCircuitBreaker_WhenClientIsGlobalRedirectToEuAndRedirectToGlobal_MaximumInvokeCountShouldBeThree() { // Arrange var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { GlobalCdnUri.Host, CreateResponse(EuOnlyCdnUri.ToString(), RedirectMode.Should, false) }, { EuOnlyCdnUri.Host, CreateResponse(GlobalCdnUri.ToString(), RedirectMode.Should, false) } }; var fetchConfig = new AutoPollConfiguration { DataGovernance = DataGovernance.Global }; // Act var responses = await Fetch(fetchConfig, responsesRegistry); // Assert Assert.AreEqual(3, responses.Count); }
public async Task ClientIsEuOnlyAndHasCustomBaseUri_AllRequestInvokeCustomUri() { // Arrange var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { CustomCdnUri.Host, CreateResponse() } }; var fetchConfig = new AutoPollConfiguration { DataGovernance = DataGovernance.EuOnly, BaseUrl = CustomCdnUri }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3, requests.Count); Assert.IsTrue(requests.Values.All(m => m.RequestUri.Host == CustomCdnUri.Host)); }
public async Task ClientIsEuOnlyAndOrgSettingIsEuOnly_AllRequestsInvokeEu() { // Arrange var fetchConfig = new AutoPollConfiguration { SdkKey = "SDK-KEY", DataGovernance = DataGovernance.EuOnly }; var responsesRegistry = new Dictionary <string, SettingsWithPreferences> { { EuOnlyCdnUri.Host, CreateResponse(ConfigurationBase.BaseUrlEu) } }; // Act var requests = await Fetch(fetchConfig, responsesRegistry, 3); // Assert Assert.AreEqual(3, requests.Count); Assert.IsTrue(requests.Values.All(m => m.RequestUri.Host == EuOnlyCdnUri.Host)); }
public void CreateAnInstance_WhenAutoPollConfigurationIsNull_ShouldThrowArgumentNullException() { AutoPollConfiguration config = null; new ConfigCatClient(config); }