Exemplo n.º 1
0
        public void ChildPathTests()
        {
            string json = @"
{
    'foo': {
        'bar': {
            'baz': {
            }
        }
    }
}
";

            using (FirebaseApp app = AppFactory.FromJson(json))
            {
                ManualResetEvent done = new ManualResetEvent(false);

                var query = app.Child("foo/bar/baz");
                query.On("value", (snap, child, context) =>
                {
                    Assert.AreEqual("baz", snap.Key);
                    Assert.AreEqual("baz", snap.Ref().Key);

                    // new ref should be at
                    // http://<app root>/foo/bar/baz
                    Assert.AreEqual(
                        string.Format("{0}{1}", app.RootUri, "foo/bar/baz"),
                        snap.Ref().AbsoluteUri.ToString());

                    var pipo = snap.Child("pipo");

                    Assert.AreEqual("pipo", pipo.Key);
                    Assert.AreEqual("pipo", pipo.Ref().Key);

                    Assert.AreEqual(
                        string.Format("{0}{1}", app.RootUri, "foo/bar/baz/pipo"),
                        pipo.Ref().AbsoluteUri.ToString());

                    var bar3 = pipo.Child("bar1/bar2/bar3");

                    Assert.AreEqual("bar3", bar3.Key);
                    Assert.AreEqual("bar3", bar3.Ref().Key);

                    Assert.AreEqual(
                        string.Format("{0}{1}", app.RootUri, "foo/bar/baz/pipo/bar1/bar2/bar3"),
                        bar3.Ref().AbsoluteUri.ToString());


                    done.Set();
                });

                Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(5)), "The callback never fired");
            }
        }
Exemplo n.º 2
0
        public void SetPriorityTest()
        {
            string json = @"
{
    'aaa': {
    },
    'bbb': {
    },
    'ccc': {
    },
}
";

            using (var app = AppFactory.FromJson(json))
            {
                ManualResetEvent called = new ManualResetEvent(false);

                var root = app.Child("/");

                // check start stat
                root.OrderByPriority().Once("value", (snap, child, context) =>
                {
                    var children = snap.Children.ToArray();
                    Assert.AreEqual("aaa", children[0].Key);
                    Assert.AreEqual("bbb", children[1].Key);
                    Assert.AreEqual("ccc", children[2].Key);
                    called.Set();
                });

                Assert.IsTrue(called.WaitOne(TimeSpan.FromSeconds(5)), "callback was never fired");

                // now update the priorites
                root.Child("aaa").SetPriority(3);
                root.Child("bbb").SetPriority(2);
                root.Child("ccc").SetPriority(1);

                called.Reset();
                // check start stat
                root.OrderByPriority().Once("value", (snap, child, context) =>
                {
                    var children = snap.Children.ToArray();
                    Assert.AreEqual("ccc", children[0].Key);
                    Assert.AreEqual("bbb", children[1].Key);
                    Assert.AreEqual("aaa", children[2].Key);
                    called.Set();
                });

                Assert.IsTrue(called.WaitOne(TimeSpan.FromSeconds(5)), "callback was never fired");
            }
        }
Exemplo n.º 3
0
        public void OrderByPriorityMixed()
        {
            string json = @"
{  
    'users':{  
        'aaa':{  
            '.priority': 5,
            'name':'AAA'
        },
        'bbb':{  
            '.priority': 'qbert',
            'name':'BBB'
        },
        'ccc':{  
            '.priority': 'zzyzx',
            'name':'CCC'
        },
        'ddd':{  
            'name':'DDD'
        },
        'eee':{  
            '.priority': '3',
            'name':'EEE'
        },
    }
}
";

            using (FirebaseApp app = AppFactory.FromJson(json))
            {
                ManualResetEvent done = new ManualResetEvent(false);

                var root  = app.Child("users");
                var query = root.OrderByPriority().Once("value", (snap, child, context) =>
                {
                    var list = snap.Children.ToList();
                    Assert.AreEqual("ddd", list[0].Key);
                    Assert.AreEqual("eee", list[1].Key);
                    Assert.AreEqual("aaa", list[2].Key);
                    Assert.AreEqual("bbb", list[3].Key);
                    Assert.AreEqual("ccc", list[4].Key);

                    done.Set();
                });

                Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(10)), "callback did not fire");
            }
        }
Exemplo n.º 4
0
        public void ChildrenValues()
        {
            string json = @"
{
  'messages': {
    '-JqpIO567aKezufthrn8': {
      'uid': 'barney',
      'text': 'Welcome to Bedrock City!'
    },
      '-JqpIP5tIy-gMbdTmIg7': {
      'uid': 'fred',
      'text': 'Yabba dabba doo!'
    }
  }
}

";

            using (FirebaseApp app = AppFactory.FromJson(json))
            {
                ManualResetEvent done = new ManualResetEvent(false);

                var query = app.Child("messages");
                query.Once("value", (snap, child, context) =>
                {
                    var ca = snap.Children.ToArray();
                    Assert.AreEqual("-JqpIO567aKezufthrn8", ca[0].Key);
                    Assert.AreEqual("barney", ca[0].Child("uid").Value());
                    Assert.AreEqual("Welcome to Bedrock City!", ca[0].Child("text").Value());

                    Assert.AreEqual("-JqpIP5tIy-gMbdTmIg7", ca[1].Key);
                    Assert.AreEqual("fred", ca[1].Child("uid").Value());
                    Assert.AreEqual("Yabba dabba doo!", ca[1].Child("text").Value());

                    done.Set();
                });

                Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(5)), "callback never fired");
            }
        }
Exemplo n.º 5
0
        public void OrderByPriorityStringNumerics()
        {
            string json = @"
{  
    'users':{  
        'gracehop':{  
            '.priority': '1',
            'name':'Grace Hopper'
        },
        'physicsmarie':{  
            '.priority': 2,
            'name':'Marie Curie'
        },
        'adalovelave':{  
            '.priority': '3',
            'name':'Ada Lovelace'
        },
    }
}
";

            using (FirebaseApp app = AppFactory.FromJson(json))
            {
                ManualResetEvent done = new ManualResetEvent(false);

                var root  = app.Child("users");
                var query = root.OrderByPriority().Once("value", (snap, child, context) =>
                {
                    var list = snap.Children.ToList();
                    Assert.AreEqual("gracehop", list[0].Key);
                    Assert.AreEqual("physicsmarie", list[1].Key);
                    Assert.AreEqual("adalovelave", list[2].Key);

                    done.Set();
                });

                Assert.IsTrue(done.WaitOne(TimeSpan.FromSeconds(10)), "callback did not fire");
            }
        }