From d35218da39688e0778af91de9e0e0287e5a80ffe Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Sat, 6 Jul 2013 16:12:00 +0200 Subject: [PATCH] Changed logging, Added test --- src/Kp2aUnitTests/TestBase.cs | 2 +- src/Kp2aUnitTests/TestSaveDb.cs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Kp2aUnitTests/TestBase.cs b/src/Kp2aUnitTests/TestBase.cs index 298c42de..8e7f9340 100644 --- a/src/Kp2aUnitTests/TestBase.cs +++ b/src/Kp2aUnitTests/TestBase.cs @@ -69,7 +69,7 @@ namespace Kp2aUnitTests LoadDb task = new LoadDb(app, new IOConnectionInfo() { Path = filename }, password, keyfile, new ActionOnFinish((success, message) => { if (!success) - Android.Util.Log.Debug("KP2ATest", message); + Kp2aLog.Log(message); loadSuccesful = success; }) diff --git a/src/Kp2aUnitTests/TestSaveDb.cs b/src/Kp2aUnitTests/TestSaveDb.cs index fda6c4bd..a07eb665 100644 --- a/src/Kp2aUnitTests/TestSaveDb.cs +++ b/src/Kp2aUnitTests/TestSaveDb.cs @@ -38,6 +38,39 @@ namespace Kp2aUnitTests AssertDatabasesAreEqual(app.GetDb().KpDatabase, resultApp.GetDb().KpDatabase); } + [TestMethod] + public void TestLoadEditSaveWithSync() + { + //create the default database: + IKp2aApp app = SetupAppWithDefaultDatabase(); + //save it and reload it so we have a base version + SaveDatabase(app); + app = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile); + //load it once again: + IKp2aApp app2 = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile); + + //modify the database by adding a group in both databases: + app.GetDb().KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "TestGroup", PwIcon.Apple), true); + var group2 = new PwGroup(true, true, "TestGroup2", PwIcon.Energy); + app2.GetDb().KpDatabase.RootGroup.AddGroup(group2, true); + //save the database from app 1: + SaveDatabase(app); + + //save the database from app 2: This save operation must detect the changes made from app 1 and ask if it should sync: + SaveDatabase(app2); + + //add group 2 to app 1: + app.GetDb().KpDatabase.RootGroup.AddGroup(group2, true); + + //load database to a new app instance: + IKp2aApp resultApp = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile); + + //ensure the sync was successful: + AssertDatabasesAreEqual(app.GetDb().KpDatabase, resultApp.GetDb().KpDatabase); + + Assert.IsTrue(false, "todo: test for sync question, test overwrite or cancel!"); + } + [TestMethod] public void TestLoadAndSave_TestIdenticalFiles() {