public void InitializeTest()
        {
            var keeShare = new KeeShare.KeeShare();
            var database = TestHelper.CreateDatabase();
            keeShare.Initialize(database);

            Assert.IsTrue(keeShare.IsInitialized());
        }
        public void InitializeTest()
        {
            var keeShare = new KeeShare.KeeShare();
            var database = TestHelper.CreateDatabase();

            keeShare.Initialize(database);

            Assert.IsTrue(keeShare.IsInitialized());
        }
        public void ShouldHandleExportAndImportOfDifferentDatabasesSuccessfully()
        {
            var exportKeeShare = new KeeShare.KeeShare();
            var exportDatabase = TestHelper.CreateDatabase();

            exportKeeShare.Initialize(exportDatabase);

            var treeManagerAccessor = new TreeManagerAccessor();

            treeManagerAccessor.Initialize(exportDatabase);
            treeManagerAccessor.CreateNewUser("MrX");
            exportKeeShare.EnsureValidTree(exportDatabase);

            var userNode        = TestHelper.GetUserRootNodeByNameFor(exportDatabase, "MrX");
            var userHome        = TestHelper.GetUserHomeNodeByNameFor(exportDatabase, "MrX");
            var exportRootEntry = new PwEntry(true, true);

            exportRootEntry.SetTitle("ExportRootEntry");
            exportDatabase.RootGroup.AddEntry(exportRootEntry, true);

            var exportPath = GetTestPath();
            var exportFile = exportPath + SyncSource.FileNameFor(userNode) + SyncExporter.FileExtension;

            exportKeeShare.AddExportPath(exportPath);
            var exportTarget = exportDatabase.GetExportGroup().Groups.GetAt(0);

            exportTarget.AddEntry(userNode.CreateProxyNode(), true);

            var exportHomeEntry = new PwEntry(true, true);

            exportHomeEntry.SetTitle("ExportHomeEntry");
            userHome.AddEntry(exportHomeEntry, true);
            exportDatabase.RootGroup.AddEntry(userNode.CreateProxyNode(), true);

            var importDatabase = TestHelper.CreateDatabase();
            var importKeeShare = new KeeShare.KeeShare();

            importKeeShare.Initialize(importDatabase);

            exportKeeShare.Export();

            importKeeShare.AddImportPath(exportFile);
            var importGroup  = importDatabase.GetImportGroup().Groups.GetAt(0);
            var importSource = importGroup.Entries.GetAt(0);

            importSource.SetPassword(userNode.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));

            importKeeShare.EnsureValidTree(importDatabase);

            Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportRootEntry"));
            Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportHomeEntry"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// The <c>Initialize</c> function is called by KeePass when
        /// you should initialize your plugin (create menu items, etc.).
        /// </summary>
        /// <param name="host">Plugin host interface. By using this
        /// interface, you can access the KeePass main window and the
        /// currently opened database.</param>
        /// <returns>You must return <c>true</c> in order to signal
        /// successful initialization. If you return <c>false</c>,
        /// KeePass unloads your plugin (without calling the
        /// <c>Terminate</c> function of your plugin).</returns>
        public override bool Initialize(IPluginHost host)
        {
            Debug.Assert(host != null);
            if (host == null)
            {
                return(false);
            }
            m_host     = host;
            m_keeShare = new KeeShare();

            InjectContextMenuEntries();
            InjectToToolsMenu();

            RegisterForChanges();

            return(true); // Initialization successful
        }
        public void ShouldHandleExportAndImportOfDifferentDatabasesSuccessfully()
        {
            var exportKeeShare = new KeeShare.KeeShare();
            var exportDatabase = TestHelper.CreateDatabase();
            exportKeeShare.Initialize(exportDatabase);

            var treeManagerAccessor = new TreeManagerAccessor();
            treeManagerAccessor.Initialize(exportDatabase);
            treeManagerAccessor.CreateNewUser("MrX");
            exportKeeShare.EnsureValidTree(exportDatabase);

            var userNode = TestHelper.GetUserRootNodeByNameFor(exportDatabase, "MrX");
            var userHome = TestHelper.GetUserHomeNodeByNameFor(exportDatabase, "MrX");
            var exportRootEntry = new PwEntry(true, true);
            exportRootEntry.SetTitle("ExportRootEntry");
            exportDatabase.RootGroup.AddEntry(exportRootEntry, true);

            var exportPath = GetTestPath();
            var exportFile = exportPath + SyncSource.FileNameFor(userNode) + SyncExporter.FileExtension;
            exportKeeShare.AddExportPath(exportPath);
            var exportTarget = exportDatabase.GetExportGroup().Groups.GetAt(0);
            exportTarget.AddEntry(PwNode.CreateProxyNode(userNode), true);

            var exportHomeEntry = new PwEntry(true, true);
            exportHomeEntry.SetTitle("ExportHomeEntry");
            userHome.AddEntry(exportHomeEntry, true);
            exportDatabase.RootGroup.AddEntry(PwNode.CreateProxyNode(userNode), true);

            var importDatabase = TestHelper.CreateDatabase();
            var importKeeShare = new KeeShare.KeeShare();
            importKeeShare.Initialize(importDatabase);

            exportKeeShare.Export();

            importKeeShare.AddImportPath(exportFile);
            var importGroup = importDatabase.GetImportGroup().Groups.GetAt(0);
            var importSource = importGroup.Entries.GetAt(0);
            importSource.SetPassword(userNode.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));

            importKeeShare.EnsureValidTree(importDatabase);

            Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportRootEntry"));
            Assert.AreEqual(1, importDatabase.RootGroup.GetEntries(true).CloneShallowToList().Count(e => e.GetTitle() == "ExportHomeEntry"));
        }