Esempio n. 1
0
        static void Main(string[] args)
        {
            var client = UnlaunchClient.Create(SdkKey);

            try
            {
                client.AwaitUntilReady(TimeSpan.FromSeconds(6));
            }
            catch (TimeoutException e)
            {
                Console.WriteLine($"Client wasn't ready, {e.Message}");
            }

            PrintBanner();

            var targetedCountriesOnVariation  = 0;
            var targetedCountriesOffVariation = 0;
            var offVariation = 0;
            var random       = new Random();

            for (var i = 0; i < NumIterations; i++)
            {
                var country    = Countries[random.Next(Countries.Length)];
                var attributes = new[]
                {
                    UnlaunchAttribute.NewSet(CountryAttributeName, new[] { country })
                };

                var feature   = client.GetFeature(FlagKey, $"user{i}", attributes);
                var variation = feature.GetVariation();
                if (variation == "on")
                {
                    targetedCountriesOnVariation++;
                    var price = feature.GetVariationConfig().GetDouble(country);
                    Console.WriteLine($"The promotion price for {country} is {price}");
                }

                if (variation == "off")
                {
                    if (country == Usa || country == Deu || country == Jpn)
                    {
                        targetedCountriesOffVariation++;
                    }
                    offVariation++;
                }

                if (country != Usa && country != Deu && country != Jpn && variation == "on")
                {
                    Console.WriteLine("This won't happen");
                }
            }

            // We select country randomly so number of on variations would not be exactly 2%
            // but it should be very small compare to number off variations
            Console.WriteLine($"Number of on variations for targeted countries: {targetedCountriesOnVariation}");
            Console.WriteLine($"Number of off variations for targeted countries: {targetedCountriesOffVariation}");
            Console.WriteLine($"Number of off variations for all countries: {offVariation}");

            client.Shutdown();
        }
Esempio n. 2
0
        public void Initialize()
        {
            var client = UnlaunchClient.Create(System.Guid.NewGuid().ToString());

            var variation = client.GetVariation("flagKey", "userId123");

            variation.Should().Be(UnlaunchConstants.FlagDefaultReturnType);

            client.Shutdown();
        }