Exemplo n.º 1
0
        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;

        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
 public void ChildGivesParent_Exists()
 {
     _app.Child("foo/bar/baz").Set("{ value: 'val1'}");
     Assert.AreEqual("bar", _app.Child("foo/bar/baz").Parent().Key);
 }
Exemplo n.º 5
0
 public void Delete(IFirebaseApp app)
 {
     var entity = app.Child(this.Path + "/" + this.Key);
     entity.Remove();
 }
Exemplo n.º 6
0

        
Exemplo n.º 7
0
 public void MultiChild()
 {
     Assert.AreEqual("/", _app.Child("foo/bar/baz").Root().Key);
 }
Exemplo n.º 8
0
        public void Delete(IFirebaseApp app)
        {
            var entity = app.Child(this.Path + "/" + this.Key);

            entity.Remove();
        }
Exemplo n.º 9
0
 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());
 }