public IEnumerator FirestoreSettings_ShouldWork() { FirebaseFirestore db = FirebaseFirestore.DefaultInstance; DocumentReference doc = db.Collection("coll").Document(); var data = new Dictionary <string, object> { { "f1", "v1" }, }; yield return(AwaitSuccess(doc.SetAsync(data))); // Verify it can get snapshot from cache. This is the behavior when // persistence is set to true in settings, which is the default setting. yield return(AwaitSuccess(doc.GetSnapshotAsync(Source.Cache))); // Terminate the current instance and create a new one (via DefaultInstance) such that // we can apply a new FirebaseFirestoreSettings. yield return(AwaitSuccess(db.TerminateAsync())); db = FirebaseFirestore.DefaultInstance; db.Settings = new FirebaseFirestoreSettings { PersistenceEnabled = false }; doc = db.Collection("coll").Document(); yield return(AwaitSuccess(doc.SetAsync(data))); // Verify it cannot get snapshot from cache. This behavior only exists with memory // persistence. var getTask = doc.GetSnapshotAsync(Source.Cache); yield return(AwaitCompletion(getTask)); AssertTaskFaulted(getTask, FirestoreError.Unavailable); // Restart SDK again to test mutating existing settings. yield return(AwaitSuccess(db.TerminateAsync())); db = FirebaseFirestore.DefaultInstance; Assert.That(db.Settings.PersistenceEnabled, Is.True); db.Settings.PersistenceEnabled = false; doc = db.Collection("coll").Document(); data = new Dictionary <string, object> { { "f1", "v1" }, }; yield return(AwaitSuccess(doc.SetAsync(data))); // Verify it cannot get snapshot from cache. This behavior only exists with memory // persistence. getTask = doc.GetSnapshotAsync(Source.Cache); yield return(AwaitCompletion(getTask)); AssertTaskFaulted(getTask, FirestoreError.Unavailable); yield return(AwaitSuccess(db.TerminateAsync())); db = FirebaseFirestore.DefaultInstance; // There is no way to actually verify the cache size is applied, we simply // verify the size is set properly in the settings object. long fiveMb = 5 * 1024 * 1024; db.Settings = new FirebaseFirestoreSettings { CacheSizeBytes = fiveMb }; Assert.That(db.Settings.CacheSizeBytes, Is.EqualTo(fiveMb)); }
public void Shutdown() { db.TerminateAsync(); db.ClearPersistenceAsync(); }