Example #1
0
        public void TestSimpleSyncCases()
        {
            //create the default database:
            TestKp2aApp app = SetupAppWithDefaultDatabase();


            IOConnection.DeleteFile(new IOConnectionInfo {
                Path = DefaultFilename
            });
            //save it and reload it so we have a base version ("remote" and in the cache)
            SaveDatabase(app);
            app = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
            _testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.LoadedFromRemoteInSyncId);

            string resultMessage;
            bool   wasSuccessful;

            //sync without changes on any side:
            Synchronize(app, out wasSuccessful, out resultMessage);
            Assert.IsTrue(wasSuccessful);
            Assert.AreEqual(resultMessage, app.GetResourceString(UiStringKey.FilesInSync));

            //go offline:
            TestFileStorage.Offline = true;

            //sync when offline (->error)
            Synchronize(app, out wasSuccessful, out resultMessage);
            Assert.IsFalse(wasSuccessful);
            Assert.AreEqual(resultMessage, "offline");

            //modify the database by adding a group:
            app.GetDb().KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "TestGroup", PwIcon.Apple), true);
            //save the database again (will be saved locally only)
            SaveDatabase(app);

            _testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.CouldntSaveToRemoteId);

            //go online again:
            TestFileStorage.Offline = false;

            //sync with local changes only (-> upload):
            Synchronize(app, out wasSuccessful, out resultMessage);
            Assert.IsTrue(wasSuccessful);
            Assert.AreEqual(resultMessage, app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));

            //ensure both files are identical and up to date now:
            TestFileStorage.Offline = true;
            var appOfflineLoaded = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);

            _testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.CouldntOpenFromRemoteId);
            TestFileStorage.Offline = false;
            var appRemoteLoaded = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);

            _testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.LoadedFromRemoteInSyncId);

            AssertDatabasesAreEqual(app.GetDb().KpDatabase, appOfflineLoaded.GetDb().KpDatabase);
            AssertDatabasesAreEqual(app.GetDb().KpDatabase, appRemoteLoaded.GetDb().KpDatabase);
        }
Example #2
0
        public void TestSyncWhenRemoteDeleted()
        {
            //create the default database:
            TestKp2aApp app = SetupAppWithDefaultDatabase();

            IOConnection.DeleteFile(new IOConnectionInfo {
                Path = DefaultFilename
            });
            //save it and reload it so we have a base version ("remote" and in the cache)
            SaveDatabase(app);
            app = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
            _testCacheSupervisor.AssertSingleCall(TestCacheSupervisor.LoadedFromRemoteInSyncId);

            //delete remote:
            IOConnection.DeleteFile(new IOConnectionInfo {
                Path = DefaultFilename
            });

            string resultMessage;
            bool   wasSuccessful;

            //sync:
            Synchronize(app, out wasSuccessful, out resultMessage);
            Assert.IsTrue(wasSuccessful);
            Assert.AreEqual(resultMessage, app.GetResourceString(UiStringKey.SynchronizedDatabaseSuccessfully));

            //ensure the file is back here:
            var app2 = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);

            AssertDatabasesAreEqual(app.GetDb().KpDatabase, app2.GetDb().KpDatabase);
        }