Esempio n. 1
0
        public void SyncRemoteUpdate()
        {
            var serverUri = "http://localhost:8081";

            SimpleServerMethods.ResetData();

            using (var server = new SimpleServer(serverUri,
                                                 getMethod: SimpleServerMethods.GetMultiplePeople))
            {
                server.Start();

                DfdsJsonSerializer serializer = new DfdsJsonSerializer();

                var settings = new DfdsServiceSettings();
                settings.DefaultSyncPeriodSeconds = 5;

                settings.LocalStore  = new MemoryStore();
                settings.RemoteStore = new RestBasedStore(serverUri, serializer);

                bool syncComplete = false;

                var svc = new DeviceFirstDataService(settings);
                svc.SyncCompleted += delegate { syncComplete = true; };

                svc.Register <Person>("PersonID");
                // local store will be empty
                Assert.AreEqual(0, settings.LocalStore.Count <Person>());

                // when sync happens, we'll have 3
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                // get a remote store person and directly modify it
                var person = SimpleServerMethods.People.First(p => p.PersonID == 1);
                person.Name        = "Billy Jean";
                person.LastChanged = DateTime.Now;

                // wait for the change to sync
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                // does the local match?
                var check = svc.GetSingle <Person>(1);

                Assert.AreEqual(person.Name, check.Name);

                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }

                Assert.AreEqual(3, settings.LocalStore.Count <Person>());
            }
        }
Esempio n. 2
0
        public void SyncLocalDeleteAll()
        {
            var serverUri = "http://localhost:8081";

            SimpleServerMethods.ResetData();

            using (var server = new SimpleServer(serverUri,
                                                 getMethod: SimpleServerMethods.GetMultiplePeople,
                                                 deleteMethod: SimpleServerMethods.DeletePerson))
            {
                server.Start();

                DfdsJsonSerializer serializer = new DfdsJsonSerializer();

                var settings = new DfdsServiceSettings();
                settings.DefaultSyncPeriodSeconds = 5;

                settings.LocalStore  = new MemoryStore();
                settings.RemoteStore = new RestBasedStore(serverUri, serializer);

                bool syncComplete = false;

                var svc = new DeviceFirstDataService(settings);
                svc.SyncCompleted += delegate { syncComplete = true; };

                svc.Register <Person>("PersonID");
                // local store will be empty
                Assert.AreEqual(0, settings.LocalStore.Count <Person>());

                // when sync happens, we'll have 3
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                svc.RemoveAll <Person>();
                Assert.AreEqual(0, settings.LocalStore.Count <Person>());

                // wait for the change to sync
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                Assert.AreEqual(0, SimpleServerMethods.People.Count());
                Assert.AreEqual(0, settings.LocalStore.Count <Person>());

                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }

                Assert.AreEqual(0, settings.LocalStore.Count <Person>());
            }
        }
Esempio n. 3
0
        public void SyncLocalInsert()
        {
            var serverUri = "http://localhost:8081";

            SimpleServerMethods.ResetData();

            using (var server = new SimpleServer(serverUri,
                                                 getMethod: SimpleServerMethods.GetMultiplePeople,
                                                 postMethod: SimpleServerMethods.PostPeople))
            {
                server.Start();

                DfdsJsonSerializer serializer = new DfdsJsonSerializer();

                var settings = new DfdsServiceSettings();
                settings.DefaultSyncPeriodSeconds = 5;

                settings.LocalStore  = new MemoryStore();
                settings.RemoteStore = new RestBasedStore(serverUri, serializer);

                bool syncComplete = false;

                var svc = new DeviceFirstDataService(settings);
                svc.SyncCompleted += delegate { syncComplete = true; };

                svc.Register <Person>("PersonID");
                // local store will be empty
                Assert.AreEqual(0, settings.LocalStore.Count <Person>());

                // when sync happens, we'll have 3
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                svc.Store(new Person("Lola L-O-L-A Lola"));

                // initial population of the store is 3
                Assert.AreEqual(4, settings.LocalStore.Count <Person>());

                // the query above triggers an insert on the remote, local still will be 3
                while (!syncComplete)
                {
                    Thread.Sleep(500);
                }
                syncComplete = false;

                Assert.AreEqual(4, settings.LocalStore.Count <Person>());
            }
        }
Esempio n. 4
0
        public void TestGetMultiple()
        {
            var serverUri = "http://localhost:8081";

            var server = new SimpleServer(serverUri,
                                          getMethod: GetMultipleItems);

            server.Start();

            var serializer = new DfdsJsonSerializer();

            var settings = new DfdsServiceSettings()
            {
                LocalStore  = new MemoryStore(),
                RemoteStore = new RestBasedStore(serverUri, serializer)
            };

            var svc = new DeviceFirstDataService(settings);

            // this is an internal call test - client will never actually use it
            var people = svc.RemoteStore.GetMultiple(typeof(Person), null);
        }