Esempio n. 1
0
        public void UpdateRootMatchesInput()
        {
            var expected = JToken.Parse(_weather);
            var client = A.Fake<IFirebaseNetworkConnection>();

            A.CallTo(() => client.Send(A<FirebaseMessage>._)).Invokes((FirebaseMessage message) =>
            {
                Assert.AreEqual(WriteBehavior.Merge, message.Behavior);
                Assert.AreEqual(new FirebasePath(), message.Path);
                Assert.IsTrue(JToken.DeepEquals(expected, JToken.Parse(message.Value)),
                    "The contents being written did not match the provided contents");

                message.Callback(null);
            });

            var jc = new SyncDatabase(null, client);

            using (var mre = new ManualResetEvent(false))
            {
                jc.Update(new FirebasePath(), _weather, (error) => { mre.Set(); });

                Assert.IsTrue(mre.WaitOne(TimeSpan.FromSeconds(5)),
                    "Time out waiting for cache callback");
            }

            Assert.IsTrue(JToken.DeepEquals(expected, JToken.Parse(jc.Dump())),
                "The cache contents did not match the expected structure");
        }
Esempio n. 2
0
 public FirebaseApp(Uri root, string auth = null)
 {
     _rootUri = root;
     _cache = new SyncDatabase(this, new FirebaseNetworkConnection(root, auth));
     _cache.Changed += FireChangeEvents;
     _subscriptions = new SubscriptionDatabase(this, _cache);
     _subProcessor = new SubscriptionProcessor(_shutdownToken.Token);
     GoOnline();
 }
Esempio n. 3
0
 internal FirebaseApp(Uri rootUri, IFirebaseNetworkConnection connection)
 {
     _rootUri = rootUri;
     _cache = new SyncDatabase(this, connection);
     _cache.Changed += FireChangeEvents;
     _subscriptions = new SubscriptionDatabase(this, _cache);
     _subProcessor = new SubscriptionProcessor(_shutdownToken.Token);
     GoOnline();
 }
Esempio n. 4
0
 public FirebaseApp(Uri root, string auth = null)
 {
     _rootUri        = root;
     _cache          = new SyncDatabase(this, new FirebaseNetworkConnection(root, auth));
     _cache.Changed += FireChangeEvents;
     _subscriptions  = new SubscriptionDatabase(this, _cache);
     _subProcessor   = new SubscriptionProcessor(_shutdownToken.Token);
     GoOnline();
 }
Esempio n. 5
0
 internal FirebaseApp(Uri rootUri, IFirebaseNetworkConnection connection)
 {
     _rootUri        = rootUri;
     _cache          = new SyncDatabase(this, connection);
     _cache.Changed += FireChangeEvents;
     _subscriptions  = new SubscriptionDatabase(this, _cache);
     _subProcessor   = new SubscriptionProcessor(_shutdownToken.Token);
     GoOnline();
 }
Esempio n. 6
0
        public void Process(SyncDatabase root)
        {
            JToken last;
            JToken snap;

            lock (_lock)
            {
                last = _lastRead;
                snap = ApplyFilters(root.SnapFor(Path).Token);

                // store the state for next time
                _lastRead = snap != null ? snap.DeepClone() : null;
            }

            FireEvents(snap, last);
        }
Esempio n. 7
0
        public void Process(SyncDatabase root)
        {
            JToken last;
            JToken snap;

            lock (_lock)
            {
                last = _lastRead;
                snap = ApplyFilters(root.SnapFor(Path).Token);

                // store the state for next time
                _lastRead = snap != null?snap.DeepClone() : null;
            }

            FireEvents(snap, last);
        }
 public SubscriptionDatabase(FirebaseApp app, SyncDatabase syncDb)
 {
     _app    = app;
     _syncDb = syncDb;
 }
Esempio n. 9
0
        public void MultiSetMatchesOutput()
        {
            var data = new List<Tuple<Tuple<string, string>, string>>()
            {
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/me",
                        "{\"name\": \"Robert\"}"),
                    "{\"people\": { \"me\": {\"name\": \"Robert\"}}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/me/name",
                        "Bob"),
                    "{\"people\": { \"me\": {\"name\": \"Bob\"}}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/you",
                        "{\"name\": \"Susan\"}"),
                    "{\"people\": { \"me\": {\"name\": \"Bob\"}, \"you\": {\"name\": \"Susan\"}}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/me/age",
                        "38"),
                    "{\"people\": { \"me\": {\"name\": \"Bob\", \"age\": \"38\"}, \"you\": {\"name\": \"Susan\"}}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/me",
                        "{\"name\": \"Bobby\"}"),
                    "{\"people\": { \"me\": {\"name\": \"Bobby\" }, \"you\": {\"name\": \"Susan\"}}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/",
                        "{ \"me\": {\"name\": \"Bobert\"}}"),
                    "{\"people\": { \"me\": {\"name\": \"Bobert\" }}}"),
                new Tuple<Tuple<string, string>, string>(
                    new Tuple<string, string>(
                        "/people/me/name",
                        null),
                    "{\"people\": { \"me\": {}}}"),
            };

            var client = A.Fake<IFirebaseNetworkConnection>();
            A.CallTo(() => client.Send(A<FirebaseMessage>._))
                .Invokes((FirebaseMessage message) => { message.Callback(null); });


            var jc = new SyncDatabase(null, client);
            ManualResetEvent called = new ManualResetEvent(false);

            foreach (var item in data)
            {
                called.Reset();
                string path = item.Item1.Item1;
                string value = item.Item1.Item2;
                var expected = JToken.Parse(item.Item2);
                jc.Set(new FirebasePath(path), value, error =>
                {
                    JToken actual = JToken.Parse(jc.Dump());
                    Assert.IsTrue(JToken.DeepEquals(expected, actual),
                        "The cache state did not match the expected cache state");
                    called.Set();
                });

                Assert.IsTrue(called.WaitOne(TimeSpan.FromSeconds(2)), "The callback never fired");
            }
        }
Esempio n. 10
0
 public SubscriptionDatabase(FirebaseApp app, SyncDatabase syncDb)
 {
     _app = app;
     _syncDb = syncDb;
 }