public IFirebase Save(IFirebaseApp app) { if (this.Key != null && this.Key != "") { //remove old version first (not very pretty but Firebase change events are pain in tha butt) var entity = app.Child(this.Path + "/" + this.Key); entity.Remove(); } else { this.CreatedAt = DateTime.Now; } var newEntity = app.Child(this.Path); this.UpdatedAt = DateTime.Now; this.Revision = Guid.NewGuid().ToString(); IFirebase result = newEntity.Push(this); this.Key = result.Key; return result; }
public IFirebase Save(IFirebaseApp app) { if (this.Key != null && this.Key != "") { //remove old version first (not very pretty but Firebase change events are pain in tha butt) var entity = app.Child(this.Path + "/" + this.Key); entity.Remove(); } else { this.CreatedAt = DateTime.Now; } var newEntity = app.Child(this.Path); this.UpdatedAt = DateTime.Now; this.Revision = Guid.NewGuid().ToString(); IFirebase result = newEntity.Push(this); this.Key = result.Key; return(result); }
public void Basic() { List <Tuple <string, string, string> > expected = new List <Tuple <string, string, string> > { new Tuple <string, string, string>("put", @"{'foo': 'bar'}", "bar"), new Tuple <string, string, string>("patch", @"{'foo': 'baz'}", "baz"), new Tuple <string, string, string>("put", @"{'foo': 'pipo'}", "pipo"), }; ManualResetEvent done = new ManualResetEvent(false); int[] counter = new[] { 0 }; var loc = _app.Child("/").On("child_changed", (snap, child, context) => { Assert.AreEqual("foo", snap.Key); Assert.AreEqual(expected[counter[0]].Item3, snap.Value()); if (++counter[0] == 3) { done.Set(); } }); foreach (var test in expected) { switch (test.Item1) { case "put": loc.Ref().Set(test.Item2); break; case "patch": loc.Ref().Update(test.Item2); break; default: Assert.Fail("Unknown action: {0}", test.Item1); break; } } Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(5)), "Callback did not fire enough: " + counter.ToString()); }
public void ChildGivesParent_Exists() { _app.Child("foo/bar/baz").Set("{ value: 'val1'}"); Assert.AreEqual("bar", _app.Child("foo/bar/baz").Parent().Key); }
public void Delete(IFirebaseApp app) { var entity = app.Child(this.Path + "/" + this.Key); entity.Remove(); }
public void MultiChild() { Assert.AreEqual("/", _app.Child("foo/bar/baz").Root().Key); }
public void SingleChild() { Assert.AreEqual("https://example.com/foo", _app.Child("foo").ToString()); Assert.AreEqual("https://example.com/foo", _app.Child("/foo").ToString()); Assert.AreEqual("https://example.com/foo", _app.Child("foo/").ToString()); Assert.AreEqual("https://example.com/foo", _app.Child("/foo/").ToString()); }