public void UpsertUpdatesPersistentStore()
        {
            var flag1a = new FeatureFlagBuilder().Version(1).Value(true).Build();
            var flag1b = new FeatureFlagBuilder().Version(2).Value(true).Build();
            var flag2  = new FeatureFlagBuilder().Version(1).Value(false).Build();
            var data1a = new DataSetBuilder().Add("flag1", flag1a).Add("flag2", flag2).Build();
            var data1b = new DataSetBuilder().Add("flag1", flag1b).Add("flag2", flag2).Build();

            var store = MakeStore(1);

            store.Init(BasicUser, data1a, true);

            var updated = store.Upsert("flag1", flag1b.ToItemDescriptor());

            Assert.True(updated);

            var item = store.Get("flag1"); // this is reading only from memory, not the persistent store

            Assert.Equal(flag1b.ToItemDescriptor(), item);

            var data = _persistentStore.InspectUserData(BasicMobileKey, BasicUser.Key);

            Assert.NotNull(data);
            AssertHelpers.DataSetsEqual(data1b, data.Value);
        }
        public void UpsertPassesDataToStore()
        {
            var flag1a   = new FeatureFlagBuilder().Version(100).Value(LdValue.Of(false)).Build();
            var initData = new DataSetBuilder().Add("key1", flag1a).Build();

            _updateSink.Init(_basicUser, initData);

            var flag1b = new FeatureFlagBuilder().Version(101).Value(LdValue.Of(true)).Build();

            _updateSink.Upsert(_basicUser, "key1", flag1b.ToItemDescriptor());

            Assert.Equal(flag1b.ToItemDescriptor(), _store.Get("key1"));
        }
        public void UpsertUndeletesFlag()
        {
            var initData = new DataSetBuilder()
                           .AddDeleted("flag1", 100)
                           .Build();

            _store.Init(BasicUser, initData, false);

            var flag1 = new FeatureFlagBuilder().Version(101).Value(LdValue.Of(true)).Build();

            var updated = _store.Upsert("flag1", flag1.ToItemDescriptor());

            Assert.True(updated);

            Assert.Equal(flag1.ToItemDescriptor(), _store.Get("flag1"));
        }
        public void GetKnownFlag()
        {
            var flag1    = new FeatureFlagBuilder().Version(100).Value(LdValue.Of(true)).Build();
            var initData = new DataSetBuilder()
                           .Add("flag1", flag1)
                           .Build();

            _store.Init(BasicUser, initData, false);

            Assert.Equal(flag1.ToItemDescriptor(), _store.Get("flag1"));
        }
        public void PatchUpdatesFlag()
        {
            var flag       = new FeatureFlagBuilder().Version(1).Build();
            var patchEvent = PatchEvent(flag.ToJsonString("flag1"));

            WithDataSourceAndServer(StreamWithEmptyInitialDataAndThen(patchEvent), (dataSource, s, t) =>
            {
                _updateSink.ExpectInit(BasicUser);

                var receivedItem = _updateSink.ExpectUpsert(BasicUser, "flag1");
                AssertHelpers.DataItemsEqual(flag.ToItemDescriptor(), receivedItem);
            });
        }
        public void UpsertDoesNotDeleteFlagWithEqualOrLowerVersion(int previousVersion, int newVersion)
        {
            var flag1a   = new FeatureFlagBuilder().Version(previousVersion).Value(LdValue.Of(true)).Build();
            var initData = new DataSetBuilder()
                           .Add("flag1", flag1a)
                           .Build();

            _store.Init(BasicUser, initData, false);

            var deletedDesc = new ItemDescriptor(newVersion, null);

            var updated = _store.Upsert("flag1", deletedDesc);

            Assert.False(updated);

            Assert.Equal(flag1a.ToItemDescriptor(), _store.Get("flag1"));
        }
        public void GetDoesNotReadFromPersistentStore()
        {
            var flag1a = new FeatureFlagBuilder().Version(1).Value(true).Build();
            var flag1b = new FeatureFlagBuilder().Version(2).Value(false).Build();
            var data1a = new DataSetBuilder().Add("flag1", flag1a).Build();
            var data1b = new DataSetBuilder().Add("flag1", flag1b).Build();

            var store = MakeStore(1);

            store.Init(BasicUser, data1a, true);

            // Hack the underlying store to change the data so we can verify it isn't being reread
            _persistentStore.SetupUserData(BasicMobileKey, BasicUser.Key, data1b);

            var item = store.Get("flag1");

            Assert.Equal(flag1a.ToItemDescriptor(), item);
        }