2013-06-25 15:27:41 -04:00
|
|
|
|
using System.Collections.Generic;
|
2013-06-18 15:12:34 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Java.IO;
|
|
|
|
|
using KeePassLib;
|
2013-06-25 15:27:41 -04:00
|
|
|
|
using KeePassLib.Interfaces;
|
2013-06-18 15:12:34 -04:00
|
|
|
|
using KeePassLib.Keys;
|
|
|
|
|
using KeePassLib.Serialization;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using keepass2android;
|
|
|
|
|
|
|
|
|
|
namespace Kp2aUnitTests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2013-06-25 15:27:41 -04:00
|
|
|
|
class TestCreateDb: TestBase
|
2013-06-18 15:12:34 -04:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void CreateAndSaveLocal()
|
|
|
|
|
{
|
|
|
|
|
IKp2aApp app = new TestKp2aApp();
|
2013-06-25 15:27:41 -04:00
|
|
|
|
IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};
|
2013-06-18 15:12:34 -04:00
|
|
|
|
|
2013-06-25 15:27:41 -04:00
|
|
|
|
File outputDir = new File(DefaultDirectory);
|
2013-06-18 15:12:34 -04:00
|
|
|
|
outputDir.Mkdirs();
|
|
|
|
|
File targetFile = new File(ioc.Path);
|
|
|
|
|
if (targetFile.Exists())
|
|
|
|
|
targetFile.Delete();
|
|
|
|
|
|
|
|
|
|
bool createSuccesful = false;
|
|
|
|
|
//create the task:
|
|
|
|
|
CreateDb createDb = new CreateDb(app, Application.Context, ioc, new ActionOnFinish((success, message) =>
|
2013-06-28 14:22:28 -04:00
|
|
|
|
{ createSuccesful = success;
|
2013-06-18 15:12:34 -04:00
|
|
|
|
}), false);
|
|
|
|
|
//run it:
|
|
|
|
|
createDb.Run();
|
|
|
|
|
//check expectations:
|
|
|
|
|
Assert.IsTrue(createSuccesful);
|
|
|
|
|
Assert.IsNotNull(app.GetDb());
|
|
|
|
|
Assert.IsNotNull(app.GetDb().KpDatabase);
|
|
|
|
|
//the create task should create two groups:
|
|
|
|
|
Assert.AreEqual(2, app.GetDb().KpDatabase.RootGroup.Groups.Count());
|
|
|
|
|
|
|
|
|
|
//ensure the the database can be loaded from file:
|
|
|
|
|
PwDatabase loadedDb = new PwDatabase();
|
|
|
|
|
loadedDb.Open(ioc, new CompositeKey(), null);
|
|
|
|
|
|
2013-06-25 15:27:41 -04:00
|
|
|
|
//Check whether the databases are equal
|
|
|
|
|
AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase);
|
|
|
|
|
|
|
|
|
|
|
2013-06-18 15:12:34 -04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|