示例#1
0
 bool IsIdentifierWithinPercentage(ToggleConfig toggleConfig, string identifier)
 {
     var bytes = hasher.Hash(identifier);
     var group = toggleConfig.PercentGroup % bytes.Length;
     var result = bytes[group] / 256d;
     return result < toggleConfig.Percent;
 }
        public void When_parsing_a_between_config(string config, string expectedStartString, string expectedEndString)
        {
            var result = new ToggleConfig(config);

            Assert.That(result.ConfigType, Is.EqualTo(ToggleConfigType.Between));
            Assert.That(result.StartUtc, Is.EqualTo(DateTime.Parse(expectedStartString).ToUniversalTime()));
            Assert.That(result.EndUtc, Is.EqualTo(DateTime.Parse(expectedEndString).ToUniversalTime()));
        }
示例#3
0
        public bool IsFeatureOn(string config, string identifier)
        {
            var toggleConfig = new ToggleConfig(config);

            switch (toggleConfig.ConfigType)
            {
                case ToggleConfigType.Off:
                    return false;
                case ToggleConfigType.On:
                    return true;
                case ToggleConfigType.Percent:
                    return IsIdentifierWithinPercentage(toggleConfig, identifier);
                case ToggleConfigType.Start:
                    return HasTimeArrived(toggleConfig.StartUtc);
                case ToggleConfigType.End:
                    return !HasTimeArrived(toggleConfig.EndUtc);
                case ToggleConfigType.Between:
                    return HasTimeArrived(toggleConfig.StartUtc) && !HasTimeArrived(toggleConfig.EndUtc);
                default:
                    throw new NotImplementedException();
            }
        }
        public void When_parsing_a_end_timestamp(string config, string expectedEndString)
        {
            var result = new ToggleConfig(config);

            Assert.That(result.ConfigType, Is.EqualTo(ToggleConfigType.End));
            Assert.That(result.EndUtc, Is.EqualTo(DateTime.Parse(expectedEndString).ToUniversalTime()));
        }
        public void When_parsing_ON(string config)
        {
            var result = new ToggleConfig(config);

            Assert.That(result.ConfigType, Is.EqualTo(ToggleConfigType.On));
        }
        public void When_parsing_a_percent_with_a_group(string config, double expectedPercent, int expectedGroup)
        {
            var result = new ToggleConfig(config);

            Assert.That(result.ConfigType, Is.EqualTo(ToggleConfigType.Percent));
            Assert.That(result.Percent, Is.EqualTo(expectedPercent));
            Assert.That(result.PercentGroup, Is.EqualTo(expectedGroup));
        }