public void DeleteDeletesFeature()
        {
            StreamProcessor sp = CreateAndStartProcessor();

            _mockEventSource.Raise(es => es.MessageReceived += null, EmptyPutEvent());
            _featureStore.Upsert(VersionedDataKind.Features, FEATURE);

            string path = "/flags/" + FEATURE_KEY;
            string data = "{\"path\":\"" + path + "\",\"version\":" + (FEATURE_VERSION + 1) + "}";
            MessageReceivedEventArgs e = new MessageReceivedEventArgs(new MessageEvent(data, null), "delete");

            _mockEventSource.Raise(es => es.MessageReceived += null, e);

            Assert.Null(_featureStore.Get(VersionedDataKind.Features, FEATURE_KEY));
        }
        public void OfflineClientGetsFlagFromFeatureStore()
        {
            var featureStore = new InMemoryFeatureStore();

            featureStore.Upsert(VersionedDataKind.Features,
                                new FeatureFlagBuilder("key").OffWithValue(new JValue(true)).Build());
            var config = Configuration.Default("SDK_KEY")
                         .WithOffline(true)
                         .WithFeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore));

            using (var client = new LdClient(config))
            {
                Assert.Equal(true, client.BoolVariation("key", User.WithKey("user"), false));
            }
        }
Beispiel #3
0
        public void AllFlagsReturnsNullIfNeitherClientNorFeatureStoreIsInited()
        {
            var featureStore = new InMemoryFeatureStore();
            var flag         = new FeatureFlagBuilder("key").OffWithValue(new JValue(1)).Build();

            featureStore.Upsert(VersionedDataKind.Features, flag); // but the store is still not inited

            var config = Configuration.Default("SDK_KEY").WithStartWaitTime(TimeSpan.Zero)
                         .WithFeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore))
                         .WithUpdateProcessorFactory(TestUtils.SpecificUpdateProcessor(updateProcessor))
                         .WithEventProcessorFactory(Components.NullEventProcessor);

            using (var client = new LdClient(config))
            {
                Assert.Null(client.AllFlags(User.WithKey("user")));
            }
        }
Beispiel #4
0
        public void EvaluationUsesFeatureStoreIfClientIsNotInitedButStoreIsInited()
        {
            var featureStore = new InMemoryFeatureStore();

            featureStore.Init(new Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> >());
            var flag = new FeatureFlagBuilder("key").OffWithValue(new JValue(1)).Build();

            featureStore.Upsert(VersionedDataKind.Features, flag);

            var config = Configuration.Default("SDK_KEY").WithStartWaitTime(TimeSpan.Zero)
                         .WithFeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore))
                         .WithUpdateProcessorFactory(TestUtils.SpecificUpdateProcessor(updateProcessor))
                         .WithEventProcessorFactory(Components.NullEventProcessor);

            using (var client = new LdClient(config))
            {
                Assert.Equal(1, client.IntVariation("key", User.WithKey("user"), 0));
            }
        }
Beispiel #5
0
        public void EvaluatingFlagWithNullUserGeneratesEvent()
        {
            IFeatureStore      featureStore = new InMemoryFeatureStore();
            MockEventProcessor ep           = new MockEventProcessor();
            LdClient           client       = MakeClient(featureStore, ep);

            FeatureFlag flag = new FeatureFlagBuilder("flagkey")
                               .OffVariation(0)
                               .Variations(new List <JToken> {
                new JValue("a"), new JValue("b")
            })
                               .Build();

            featureStore.Upsert(VersionedDataKind.Features, flag);

            client.StringVariation("flagkey", null, "default");

            Assert.Collection(ep.Events,
                              e => CheckFlagEvent(e, flag, flag.Version, null, null, new JValue("default"), new JValue("default")));
        }