Пример #1
0
        public async Task GetVariationIdAsync_DeserializeFailed_ShouldReturnsWithEmptyArray()
        {
            // Arrange

            configServiceMock.Setup(m => m.GetConfigAsync()).ReturnsAsync(ProjectConfig.Empty);
            var o = new SettingsWithPreferences();

            configDeserializerMock
            .Setup(m => m.TryDeserialize(It.IsAny <string>(), out o))
            .Returns(false);

            IConfigCatClient instance = new ConfigCatClient(
                configServiceMock.Object,
                loggerMock.Object,
                evaluatorMock.Object,
                configDeserializerMock.Object);

            // Act

            var actual = await instance.GetAllVariationIdAsync();

            // Assert

            Assert.IsNotNull(actual);
            Assert.AreEqual(0, actual.Count());
            loggerMock.Verify(m => m.Warning(It.IsAny <string>()), Times.Once);
        }
Пример #2
0
        public void GetAllKeys_DeserializerThrowException_ShouldReturnsWithEmptyArray()
        {
            // Arrange

            configServiceMock.Setup(m => m.GetConfigAsync()).ReturnsAsync(ProjectConfig.Empty);
            var o = new SettingsWithPreferences();

            configDeserializerMock
            .Setup(m => m.TryDeserialize(It.IsAny <string>(), out o))
            .Throws <Exception>();

            IConfigCatClient instance = new ConfigCatClient(
                configServiceMock.Object,
                loggerMock.Object,
                evaluatorMock.Object,
                configDeserializerMock.Object);

            // Act

            var actualKeys = instance.GetAllKeys();

            // Assert

            Assert.IsNotNull(actualKeys);
            Assert.AreEqual(0, actualKeys.Count());
            loggerMock.Verify(m => m.Error(It.IsAny <string>()), Times.Once);
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Creating the ConfigCat client instance using the SDK Key
            var client = new ConfigCatClient("PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ");

            // Setting log level to Info to show detailed feature flag evaluation
            client.LogLevel = LogLevel.Info;

            // Creating a user object to identify the user (optional)
            User user = new User("<SOME USERID>")
            {
                Country = "US",
                Email   = "*****@*****.**",
                Custom  =
                {
                    { "SubscriptionType", "Pro"   },
                    { "Role",             "Admin" },
                    { "version",          "1.0.0" }
                }
            };

            // Accessing feature flag or setting value
            var value = client.GetValue("isPOCFeatureEnabled", false, user);

            Console.WriteLine($"isPOCFeatureEnabled: {value}");
        }
Пример #4
0
        public static IServiceCollection AddConfigCat(this IServiceCollection serviceCollection, ConfigCatConfig configCatConfig)
        {
            var client = new ConfigCatClient(configCatConfig.Key);

            serviceCollection.AddSingleton <IConfigCatClient>(client);
            return(serviceCollection);
        }
Пример #5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            Microsoft.Extensions.Logging.ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            var clientConfiguration = new LazyLoadConfiguration
            {
                SdkKey = "f3vYCGwC00OC4a_P2E5x4w/U6mbty2Tq0aCDCws85-xvw", // <-- This is the actual SDK Key for your Production environment
                CacheTimeToLiveSeconds = 1
            };
            IConfigCatClient client = new ConfigCatClient(clientConfiguration);

            User user = new User("returning"); // Unique identifier is required. Could be UserID, Email address or SessionID.

            var costumerflag            = client.GetValue("costumerflag", false, user);
            var isAwesomeFeatureEnabled = client.GetValue("isAwesomeFeatureEnabled", false, user);

            Console.WriteLine("costumerflag's value from ConfigCat: " + costumerflag);
            Console.WriteLine("isAwesomeFeatureEnabled's value from ConfigCat: " + isAwesomeFeatureEnabled);

            string responseMessage = costumerflag
                ? $"Welcome back, {name}!"
                : $"Welcome {name}!";

            return(new OkObjectResult(responseMessage));
        }
 public ConfigService(string apiKey)
 {
     _configClient = new ConfigCatClient(new LazyLoadConfiguration
     {
         ApiKey = apiKey, // <-- This is the actual API key for your Production environment
         CacheTimeToLiveSeconds = 720 * 60,
     });
 }
        public void LazyLoadDeadLockCheck()
        {
            var client = new ConfigCatClient(new LazyLoadConfiguration
            {
                SdkKey = SDKKEY,
                Logger = new ConsoleLogger(LogLevel.Off)
            });

            ClientDeadlockCheck(client);
        }
        public void ManualPollDeadLockCheck()
        {
            var client = new ConfigCatClient(new ManualPollConfiguration
            {
                SdkKey = SDKKEY,
                Logger = new ConsoleLogger(LogLevel.Off)
            });

            ClientDeadlockCheck(client);
        }
        public IActionResult Index()
        {
            var userEmail = HttpContext.User.Claims.Where(claim => claim.Type == "email").Select(claim => claim.Value).FirstOrDefault();
            var user      = new User(userEmail)
            {
                Email = userEmail
            };
            var client             = new ConfigCatClient("tNHYCC8Nm0OPXt2LxXT4zQ/k-5ZmLLd10isguXVF6PrTw");
            var twitterFeedVisible = client.GetValue("twitterFeedVisible", false, user);

            return(View(twitterFeedVisible));
        }
Пример #10
0
        protected virtual void ConfigureFeatureFlags(IServiceCollection services)
        {
            var clientConfiguration = new ManualPollConfiguration()
            {
                ApiKey = Configuration.GetSection("ConfigCat")["ApiKey"]
            };

            var configCatClient = new ConfigCatClient(clientConfiguration);

            services.AddSingleton <IConfigCatClient>(configCatClient);
            services.AddFeatureManagement(new ConfigCatConfiguration(configCatClient, null));
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var configCatClient = new ConfigCatClient(new LazyLoadConfiguration
            {
                SdkKey = Configuration["ConfigCatSdkKey"],
                CacheTimeToLiveSeconds = 120
            });

            configCatClient.LogLevel = LogLevel.Info;

            services.AddSingleton <IConfigCatClient>(configCatClient);
        }
Пример #12
0
        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();
        }
Пример #13
0
        public async Task GetAllVariationIdAsync_ConfigServiceThrowException_ShouldReturnEmptyEnumerable()
        {
            // Arrange

            configServiceMock
            .Setup(m => m.GetConfigAsync())
            .Throws <Exception>();

            var client = new ConfigCatClient(configServiceMock.Object, loggerMock.Object, evaluatorMock.Object, configDeserializerMock.Object);

            // Act

            var actual = await client.GetAllVariationIdAsync(null);

            // Assert

            Assert.AreEqual(Enumerable.Empty <string>(), actual);
        }
Пример #14
0
        public MainViewModel()
        {
            ToggleA = false;
            ToggleB = false;

            VerificarCommand = new Command(ExecuteVerificarCommand);
            AutoCommand      = new Command(ExecuteAutoCommand);
            ManualCommand    = new Command(ExecuteManualCommand);
            LazyCommand      = new Command(ExecuteLazyCommand);


            //Verificar Toggle A
            client_verificar = new ConfigCatClient(Session.ApiKey);


            //Verificar Toggle B - Auto Pooling
            AutoPollConfiguration autoConfiguration = new AutoPollConfiguration
            {
                ApiKey = Session.ApiKey,
                PollIntervalSeconds = 20
            };

            client_auto = new ConfigCatClient(autoConfiguration);


            //Verificar Toggle B - Manual Pooling
            ManualPollConfiguration manualConfiguration = new ManualPollConfiguration
            {
                ApiKey = Session.ApiKey
            };

            client_manual = new ConfigCatClient(manualConfiguration);


            //Verificar Toggle B - Lazy Pooling
            LazyLoadConfiguration lazyConfiguration = new LazyLoadConfiguration
            {
                ApiKey = Session.ApiKey,
                CacheTimeToLiveSeconds = 40
            };

            client_lazy = new ConfigCatClient(lazyConfiguration);
        }
Пример #15
0
        public void GetValue_ConfigServiceThrowException_ShouldReturnDefaultValue()
        {
            // Arrange

            const string defaultValue = "Victory for the Firstborn!";

            configServiceMock
            .Setup(m => m.GetConfigAsync())
            .Throws <Exception>();

            var client = new ConfigCatClient(configServiceMock.Object, loggerMock.Object, evaluatorMock.Object, configDeserializerMock.Object);

            // Act

            var actual = client.GetValue(null, defaultValue);

            // Assert

            Assert.AreEqual(defaultValue, actual);
        }
        public void GetValue_EvaluateServiceThrowException_ShouldReturnDefaultValue()
        {
            // Arrange

            const string defaultValue = "Victory for the Firstborn!";

            evaluateMock
            .Setup(m => m.Evaluate(It.IsAny <ProjectConfig>(), It.IsAny <string>(), defaultValue, null))
            .Throws <Exception>();

            var client = new ConfigCatClient(configService.Object, loggerMock.Object, evaluateMock.Object);

            // Act

            var actual = client.GetValue(null, defaultValue);

            // Assert

            Assert.AreEqual(defaultValue, actual);
        }
Пример #17
0
        public async Task GetVariationIdAsync_EvaluateServiceThrowException_ShouldReturnDefaultValue()
        {
            // Arrange

            const string defaultValue = "Victory for the Firstborn!";

            evaluatorMock
            .Setup(m => m.EvaluateVariationId(It.IsAny <ProjectConfig>(), It.IsAny <string>(), defaultValue, null))
            .Throws <Exception>();

            var client = new ConfigCatClient(configServiceMock.Object, loggerMock.Object, evaluatorMock.Object, configDeserializerMock.Object);

            // Act

            var actual = await client.GetVariationIdAsync(null, defaultValue);

            // Assert

            Assert.AreEqual(defaultValue, actual);
        }
Пример #18
0
        public void Dispose_ConfigServiceIsDisposable_ShouldInvokeDispose()
        {
            // Arrange

            var myMock = new FakeConfigService(Mock.Of <IConfigFetcher>(), new CacheParameters(), Mock.Of <ILogger>());

            IConfigCatClient instance = new ConfigCatClient(
                myMock,
                loggerMock.Object,
                evaluatorMock.Object,
                configDeserializerMock.Object);

            // Act

            instance.Dispose();

            // Assert

            Assert.AreEqual(1, myMock.DisposeCount);
        }
Пример #19
0
        public async Task ForceRefreshAsync_ShouldInvokeConfigServiceRefreshConfigAsync()
        {
            // Arrange

            configServiceMock.Setup(m => m.RefreshConfigAsync()).Returns(Task.CompletedTask);

            IConfigCatClient instance = new ConfigCatClient(
                configServiceMock.Object,
                loggerMock.Object,
                evaluatorMock.Object,
                configDeserializerMock.Object);

            // Act

            await instance.ForceRefreshAsync();

            // Assert

            configServiceMock.Verify(m => m.RefreshConfigAsync(), Times.Once);
        }
Пример #20
0
        public async Task ForceRefreshAsync_ConfigServiceThrowException_ShouldNotReThrowTheExceptionAndLogsError()
        {
            // Arrange

            configServiceMock.Setup(m => m.RefreshConfigAsync()).Throws <Exception>();

            IConfigCatClient instance = new ConfigCatClient(
                configServiceMock.Object,
                loggerMock.Object,
                evaluatorMock.Object,
                configDeserializerMock.Object);

            // Act

            await instance.ForceRefreshAsync();

            // Assert

            loggerMock.Verify(m => m.Error(It.IsAny <string>()), Times.Once);
        }
Пример #21
0
        public void CreateConfigurationBuilderInstance_ShouldCreateAnInstance()
        {
            var builder = ConfigCatClient.Create("SDKKEY");

            Assert.IsNotNull(builder);
        }