コード例 #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();
        }
コード例 #2
0
        public void Enumerable()
        {
            CreateNotAllOfCondition(AttributeType.Set, "2,1,3,9");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new [] { "1", "3", "2", "6" })
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #3
0
        public void Set()
        {
            CreateNotAllOfCondition(AttributeType.Set, "2,3,6,8");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new HashSet <string>(new [] { "1", "3", "2", "6" }))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #4
0
        public void Set_userSet_is_disjoint()
        {
            CreateNhaCondition(AttributeType.Set, "0,8,9");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new HashSet <string>(new [] { "1", "3", "2", "6" }))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #5
0
        public void Set_userSet_is_super_set()
        {
            CreateNpoCondition(AttributeType.Set, "0,3");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new HashSet <string>(new [] { "0", "3", "6" }))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #6
0
        public void Set_userSet_is_sub_set()
        {
            CreateNotEqualsCondition(AttributeType.Set, "value1");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new[] { "value2", "value1" })
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #7
0
        public void Enumerable()
        {
            CreatePartOfCondition(AttributeType.Set, "1,2,3");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new [] { "1", "3" })
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #8
0
        public void Set_userSet_is_same()
        {
            CreatePartOfCondition(AttributeType.Set, "1,2,3");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new HashSet <string>(new [] { "1", "3", "2" }))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #9
0
        public void Set_userSet_has_some_item()
        {
            CreateAnyOfCondition(AttributeType.Set, "3,5,9");

            var attributes = new[]
            {
                UnlaunchAttribute.NewSet(AttributeKey, new HashSet <string>(new [] { "5" }))
            };

            OnVariationTargetingRulesMatch(attributes);
        }
コード例 #10
0
        public void Set_userSet_is_empty()
        {
            Assert.Throws <ArgumentException>(() => UnlaunchAttribute.NewSet("attributeKey", new HashSet <string>()));

            Assert.Throws <ArgumentException>(() => UnlaunchAttribute.NewSet("attributeKey", Enumerable.Empty <string>()));
        }
コード例 #11
0
 public void UserSet_is_null()
 {
     Assert.Throws <ArgumentException>(() => UnlaunchAttribute.NewSet("attributeKey", null));
 }