mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Adding tests for App
WIP make VMs app agnostic
This commit is contained in:
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernKeePassLib.Test", "Mo
|
||||
EndProject
|
||||
Project("{F5034706-568F-408A-B7B3-4D38C6DB8A32}") = "Scripts", "Scripts\Scripts.pssproj", "{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModernKeePassApp.Test", "ModernKeePassApp.Test\ModernKeePassApp.Test.csproj", "{7E80F5E7-724A-4668-9333-B10F5D75C6D0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -103,6 +105,30 @@ Global
|
||||
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|x64.Build.0 = Release|Any CPU
|
||||
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|x86.Build.0 = Release|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x64.Build.0 = Debug|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x86.Build.0 = Debug|x86
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|ARM.Build.0 = Release|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x64.ActiveCfg = Release|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x64.Build.0 = Release|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x64.Deploy.0 = Release|x64
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x86.ActiveCfg = Release|x86
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x86.Build.0 = Release|x86
|
||||
{7E80F5E7-724A-4668-9333-B10F5D75C6D0}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
@@ -10,7 +11,7 @@ using ModernKeePassLib.Serialization;
|
||||
|
||||
namespace ModernKeePass.Common
|
||||
{
|
||||
public class DatabaseHelper
|
||||
public class DatabaseHelper: IDatabase
|
||||
{
|
||||
public enum DatabaseStatus
|
||||
{
|
||||
@@ -37,7 +38,7 @@ namespace ModernKeePass.Common
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseStatus Status { get; private set; } = DatabaseStatus.Closed;
|
||||
public int Status { get; set; } = (int)DatabaseStatus.Closed;
|
||||
public string Name => DatabaseFile?.Name;
|
||||
|
||||
public bool RecycleBinEnabled
|
||||
@@ -52,7 +53,7 @@ namespace ModernKeePass.Common
|
||||
set
|
||||
{
|
||||
_databaseFile = value;
|
||||
Status = DatabaseStatus.Opening;
|
||||
Status = (int)DatabaseStatus.Opening;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,24 +85,26 @@ namespace ModernKeePass.Common
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key == null) Status = DatabaseStatus.NoCompositeKey;
|
||||
if (key == null)
|
||||
{
|
||||
Status = (int)DatabaseStatus.NoCompositeKey;
|
||||
return;
|
||||
}
|
||||
var ioConnection = IOConnectionInfo.FromFile(DatabaseFile);
|
||||
if (createNew) _pwDatabase.New(ioConnection, key);
|
||||
else _pwDatabase.Open(ioConnection, key, new NullStatusLogger());
|
||||
|
||||
if (_pwDatabase.IsOpen)
|
||||
{
|
||||
Status = DatabaseStatus.Opened;
|
||||
RootGroup = new GroupVm(_pwDatabase.RootGroup, null, RecycleBinEnabled ? _pwDatabase.RecycleBinUuid : null);
|
||||
}
|
||||
if (!_pwDatabase.IsOpen) return;
|
||||
Status = (int)DatabaseStatus.Opened;
|
||||
RootGroup = new GroupVm(_pwDatabase.RootGroup, null, RecycleBinEnabled ? _pwDatabase.RecycleBinUuid : null);
|
||||
}
|
||||
catch (InvalidCompositeKeyException)
|
||||
{
|
||||
Status = DatabaseStatus.CompositeKeyError;
|
||||
Status = (int)DatabaseStatus.CompositeKeyError;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = DatabaseStatus.Error;
|
||||
Status = (int)DatabaseStatus.Error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,11 +112,19 @@ namespace ModernKeePass.Common
|
||||
/// Save the current database to another file and open it
|
||||
/// </summary>
|
||||
/// <param name="file">The new database file</param>
|
||||
internal void Save(StorageFile file)
|
||||
public bool Save(StorageFile file)
|
||||
{
|
||||
DatabaseFile = file;
|
||||
_pwDatabase.SaveAs(IOConnectionInfo.FromFile(DatabaseFile), true, new NullStatusLogger());
|
||||
Status = DatabaseStatus.Opened;
|
||||
try
|
||||
{
|
||||
_pwDatabase.SaveAs(IOConnectionInfo.FromFile(DatabaseFile), true, new NullStatusLogger());
|
||||
Status = (int)DatabaseStatus.Opened;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,9 +140,10 @@ namespace ModernKeePass.Common
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
// TODO: put this at a better place (e.g. in views)
|
||||
MessageDialogHelper.ShowErrorDialog(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -140,7 +152,7 @@ namespace ModernKeePass.Common
|
||||
public void Close()
|
||||
{
|
||||
_pwDatabase?.Close();
|
||||
Status = DatabaseStatus.Closed;
|
||||
Status = (int)DatabaseStatus.Closed;
|
||||
}
|
||||
|
||||
public void AddDeletedItem(PwUuid id)
|
||||
@@ -150,7 +162,7 @@ namespace ModernKeePass.Common
|
||||
|
||||
public void CreateRecycleBin()
|
||||
{
|
||||
RecycleBin = RootGroup.AddNewGroup("Recycle bin");
|
||||
RecycleBin = ((GroupVm)RootGroup).AddNewGroup("Recycle bin");
|
||||
RecycleBin.IsSelected = true;
|
||||
RecycleBin.IconSymbol = Symbol.Delete;
|
||||
}
|
||||
|
20
ModernKeePass/Interfaces/IDatabase.cs
Normal file
20
ModernKeePass/Interfaces/IDatabase.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Keys;
|
||||
|
||||
namespace ModernKeePass.Interfaces
|
||||
{
|
||||
public interface IDatabase
|
||||
{
|
||||
bool RecycleBinEnabled { get; set; }
|
||||
int Status { get; set; }
|
||||
GroupVm RootGroup { get; set; }
|
||||
GroupVm RecycleBin { get; set; }
|
||||
|
||||
void Open(CompositeKey key, bool createNew);
|
||||
void UpdateCompositeKey(CompositeKey key);
|
||||
bool Save();
|
||||
void CreateRecycleBin();
|
||||
void AddDeletedItem(PwUuid id);
|
||||
}
|
||||
}
|
@@ -123,6 +123,7 @@
|
||||
<Compile Include="Common\ToastNotificationHelper.cs" />
|
||||
<Compile Include="Converters\DiscreteIntToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="Converters\NullToBooleanConverter.cs" />
|
||||
<Compile Include="Interfaces\IDatabase.cs" />
|
||||
<Compile Include="Interfaces\IHasSelectableObject.cs" />
|
||||
<Compile Include="Interfaces\ISelectableModel.cs" />
|
||||
<Compile Include="Pages\BasePages\LayoutAwarePageBase.cs" />
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Serialization;
|
||||
@@ -18,7 +19,7 @@ namespace ModernKeePass.ViewModels
|
||||
Success = 5
|
||||
}
|
||||
|
||||
private readonly App _app = Application.Current as App;
|
||||
//private readonly App _app = Application.Current as App;
|
||||
private bool _hasPassword;
|
||||
private bool _hasKeyFile;
|
||||
private string _password = string.Empty;
|
||||
@@ -27,6 +28,8 @@ namespace ModernKeePass.ViewModels
|
||||
private StorageFile _keyFile;
|
||||
private string _keyFileText = "Select key file from disk...";
|
||||
|
||||
public IDatabase Database { get; set; }
|
||||
|
||||
public bool HasPassword
|
||||
{
|
||||
get { return _hasPassword; }
|
||||
@@ -90,15 +93,23 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
public GroupVm RootGroup { get; set; }
|
||||
|
||||
public double PasswordComplexityIndicator => QualityEstimation.EstimatePasswordBits(Password?.ToCharArray());
|
||||
|
||||
public CompositeKeyVm() : this((Application.Current as App)?.Database) { }
|
||||
|
||||
public CompositeKeyVm(IDatabase database)
|
||||
{
|
||||
Database = database;
|
||||
}
|
||||
|
||||
public bool OpenDatabase(bool createNew)
|
||||
{
|
||||
_app.Database.Open(CreateCompositeKey(), createNew);
|
||||
switch (_app.Database.Status)
|
||||
Database.Open(CreateCompositeKey(), createNew);
|
||||
switch ((DatabaseHelper.DatabaseStatus)Database.Status)
|
||||
{
|
||||
case DatabaseHelper.DatabaseStatus.Opened:
|
||||
RootGroup = _app.Database.RootGroup;
|
||||
RootGroup = Database.RootGroup;
|
||||
return true;
|
||||
case DatabaseHelper.DatabaseStatus.CompositeKeyError:
|
||||
var errorMessage = new StringBuilder("Error: wrong ");
|
||||
@@ -113,7 +124,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void UpdateKey()
|
||||
{
|
||||
_app.Database.UpdateCompositeKey(CreateCompositeKey());
|
||||
Database.UpdateCompositeKey(CreateCompositeKey());
|
||||
UpdateStatus("Database composite key updated.", StatusTypes.Success);
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryVm : INotifyPropertyChanged, IPwEntity
|
||||
{
|
||||
public IDatabase Database { get; set; }
|
||||
public GroupVm ParentGroup { get; private set; }
|
||||
|
||||
public GroupVm PreviousGroup { get; private set; }
|
||||
@@ -150,7 +151,6 @@ namespace ModernKeePass.ViewModels
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private readonly PwEntry _pwEntry;
|
||||
private readonly App _app = Application.Current as App;
|
||||
private bool _isEditMode;
|
||||
private bool _isRevealPassword;
|
||||
private double _passwordLength = 25;
|
||||
@@ -160,16 +160,20 @@ namespace ModernKeePass.ViewModels
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public EntryVm() { }
|
||||
public EntryVm(PwEntry entry, GroupVm parent)
|
||||
public EntryVm() : this(null, null) { }
|
||||
|
||||
internal EntryVm(PwEntry entry, GroupVm parent) : this(entry, parent, (Application.Current as App)?.Database) { }
|
||||
|
||||
public EntryVm(PwEntry entry, GroupVm parent, IDatabase database)
|
||||
{
|
||||
Database = database;
|
||||
_pwEntry = entry;
|
||||
ParentGroup = parent;
|
||||
}
|
||||
|
||||
public void GeneratePassword()
|
||||
{
|
||||
var pwProfile = new PwProfile()
|
||||
var pwProfile = new PwProfile
|
||||
{
|
||||
GeneratorType = PasswordGeneratorType.CharSet,
|
||||
Length = (uint)PasswordLength,
|
||||
@@ -208,9 +212,9 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void MarkForDelete()
|
||||
{
|
||||
if (_app.Database.RecycleBinEnabled && _app.Database.RecycleBin?.IdUuid == null)
|
||||
_app.Database.CreateRecycleBin();
|
||||
Move(_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected ? _app.Database.RecycleBin : null);
|
||||
if (Database.RecycleBinEnabled && Database.RecycleBin?.IdUuid == null)
|
||||
Database.CreateRecycleBin();
|
||||
Move(Database.RecycleBinEnabled && !ParentGroup.IsSelected ? Database.RecycleBin : null);
|
||||
}
|
||||
|
||||
public void UndoDelete()
|
||||
@@ -225,7 +229,7 @@ namespace ModernKeePass.ViewModels
|
||||
PreviousGroup.RemovePwEntry(_pwEntry);
|
||||
if (destination == null)
|
||||
{
|
||||
_app.Database.AddDeletedItem(IdUuid);
|
||||
Database.AddDeletedItem(IdUuid);
|
||||
return;
|
||||
}
|
||||
ParentGroup = destination;
|
||||
@@ -236,13 +240,13 @@ namespace ModernKeePass.ViewModels
|
||||
public void CommitDelete()
|
||||
{
|
||||
_pwEntry.ParentGroup.Entries.Remove(_pwEntry);
|
||||
if (_app.Database.RecycleBinEnabled && !PreviousGroup.IsSelected) _app.Database.RecycleBin.AddPwEntry(_pwEntry);
|
||||
else _app.Database.AddDeletedItem(IdUuid);
|
||||
if (Database.RecycleBinEnabled && !PreviousGroup.IsSelected) Database.RecycleBin.AddPwEntry(_pwEntry);
|
||||
else Database.AddDeletedItem(IdUuid);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_app.Database.Save();
|
||||
Database.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,14 +49,14 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var isDatabaseOpen = app.Database != null && app.Database.Status == DatabaseHelper.DatabaseStatus.Opened;
|
||||
var isDatabaseOpen = app.Database != null && app.Database.Status == (int) DatabaseHelper.DatabaseStatus.Opened;
|
||||
|
||||
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
||||
{
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = "Open", PageType = typeof(OpenDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Page2,
|
||||
IsSelected = app.Database.Status == DatabaseHelper.DatabaseStatus.Opening
|
||||
IsSelected = app.Database.Status == (int) DatabaseHelper.DatabaseStatus.Opening
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
@@ -69,7 +69,7 @@ namespace ModernKeePass.ViewModels
|
||||
},
|
||||
new MainMenuItemVm {
|
||||
Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Copy,
|
||||
IsSelected = (app.Database == null || app.Database.Status == DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
|
||||
IsSelected = (app.Database == null || app.Database.Status == (int) DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
@@ -78,7 +78,7 @@ namespace ModernKeePass.ViewModels
|
||||
};
|
||||
// Auto-select the Recent Items menu item if the conditions are met
|
||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
||||
if (app.Database != null && app.Database.Status == DatabaseHelper.DatabaseStatus.Opened)
|
||||
if (app.Database != null && app.Database.Status == (int) DatabaseHelper.DatabaseStatus.Opened)
|
||||
mainMenuItems.Add(new MainMenuItemVm
|
||||
{
|
||||
Title = app.Database.Name,
|
||||
|
@@ -10,7 +10,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public bool ShowPasswordBox
|
||||
{
|
||||
get { return ((App)Application.Current).Database.Status == DatabaseHelper.DatabaseStatus.Opening; }
|
||||
get { return ((App)Application.Current).Database.Status == (int) DatabaseHelper.DatabaseStatus.Opening; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
@@ -21,7 +21,7 @@ namespace ModernKeePass.ViewModels
|
||||
public OpenVm()
|
||||
{
|
||||
var app = Application.Current as App;
|
||||
if (app?.Database == null || app.Database.Status != DatabaseHelper.DatabaseStatus.Opening) return;
|
||||
if (app?.Database == null || app.Database.Status != (int) DatabaseHelper.DatabaseStatus.Opening) return;
|
||||
OpenFile(app.Database.DatabaseFile);
|
||||
}
|
||||
|
||||
|
64
ModernKeePassApp.Test/DatabaseTests.cs
Normal file
64
ModernKeePassApp.Test/DatabaseTests.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePassLib.Keys;
|
||||
|
||||
namespace ModernKeePassApp.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class DatabaseTests
|
||||
{
|
||||
private readonly DatabaseHelper _database = new DatabaseHelper();
|
||||
|
||||
[TestMethod]
|
||||
public void TestCreate()
|
||||
{
|
||||
Assert.AreEqual(_database.Status, (int) DatabaseHelper.DatabaseStatus.Closed);
|
||||
_database.DatabaseFile = ApplicationData.Current.TemporaryFolder.CreateFileAsync("NewDatabase.kdbx").GetAwaiter().GetResult();
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Opening);
|
||||
OpenOrCreateDatabase(true);
|
||||
_database.Close();
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Closed);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestOpen()
|
||||
{
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Closed);
|
||||
_database.DatabaseFile = Package.Current.InstalledLocation.GetFileAsync(@"Databases\TestDatabase.kdbx").GetAwaiter().GetResult();
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Opening);
|
||||
OpenOrCreateDatabase(false);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestSave()
|
||||
{
|
||||
TestOpen();
|
||||
Assert.IsTrue(_database.Save(ApplicationData.Current.TemporaryFolder.CreateFileAsync("SaveDatabase.kdbx").GetAwaiter().GetResult()));
|
||||
_database.Close();
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Closed);
|
||||
TestOpen();
|
||||
}
|
||||
|
||||
private void OpenOrCreateDatabase(bool createNew)
|
||||
{
|
||||
_database.Open(null, createNew);
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.NoCompositeKey);
|
||||
var compositeKey = new CompositeKey();
|
||||
if (!createNew)
|
||||
{
|
||||
_database.Open(compositeKey);
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.CompositeKeyError);
|
||||
}
|
||||
compositeKey.AddUserKey(new KcpPassword("test"));
|
||||
|
||||
_database.Open(compositeKey, createNew);
|
||||
/*var compositeKey = new CompositeKeyVm(_database);
|
||||
compositeKey.OpenDatabase(createNew);*/
|
||||
Assert.AreEqual(_database.Status, (int)DatabaseHelper.DatabaseStatus.Opened);
|
||||
}
|
||||
}
|
||||
}
|
BIN
ModernKeePassApp.Test/Databases/TestDatabase.kdbx
Normal file
BIN
ModernKeePassApp.Test/Databases/TestDatabase.kdbx
Normal file
Binary file not shown.
BIN
ModernKeePassApp.Test/Images/UnitTestLogo.scale-100.png
Normal file
BIN
ModernKeePassApp.Test/Images/UnitTestLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
BIN
ModernKeePassApp.Test/Images/UnitTestSmallLogo.scale-100.png
Normal file
BIN
ModernKeePassApp.Test/Images/UnitTestSmallLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 745 B |
BIN
ModernKeePassApp.Test/Images/UnitTestSplashScreen.scale-100.png
Normal file
BIN
ModernKeePassApp.Test/Images/UnitTestSplashScreen.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
ModernKeePassApp.Test/Images/UnitTestStoreLogo.scale-100.png
Normal file
BIN
ModernKeePassApp.Test/Images/UnitTestStoreLogo.scale-100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
191
ModernKeePassApp.Test/ModernKeePassApp.Test.csproj
Normal file
191
ModernKeePassApp.Test/ModernKeePassApp.Test.csproj
Normal file
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{7E80F5E7-724A-4668-9333-B10F5D75C6D0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ModernKeePassApp.Test</RootNamespace>
|
||||
<AssemblyName>ModernKeePassApp.Test</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformVersion>8.1</TargetPlatformVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PackageCertificateKeyFile>ModernKeePassApp.Test_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<AppxBundle>Never</AppxBundle>
|
||||
<AllowCrossPlatformRetargeting>False</AllowCrossPlatformRetargeting>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AppXPackage>True</AppXPackage>
|
||||
<AppxPackageIncludePrivateSymbols>true</AppxPackageIncludePrivateSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!--A reference to the entire .Net Framework and Windows SDK are automatically included-->
|
||||
<SDKReference Include="MSTestFramework, Version=14.0" />
|
||||
<SDKReference Include="TestPlatform, Version=14.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DatabaseTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<Content Include="Databases\TestDatabase.kdbx" />
|
||||
<None Include="ModernKeePassApp.Test_TemporaryKey.pfx" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\UnitTestLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestSmallLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestSplashScreen.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestStoreLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass\ModernKeePassApp.csproj">
|
||||
<Project>{A0CFC681-769B-405A-8482-0CDEE595A91F}</Project>
|
||||
<Name>ModernKeePassApp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.1.3\lib\netstandard1.0\BouncyCastle.Crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ModernKeePassLib, Version=2.37.0.2000, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ModernKeePassLib.2.37.7000\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Splat, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Splat.2.0.0\lib\Portable-Win81+Wpa81\Splat.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\win8\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Validation, Version=2.4.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Validation.2.4.18\lib\portable-net45+win8+wp8+wpa81\Validation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<Import Project="..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
BIN
ModernKeePassApp.Test/ModernKeePassApp.Test_TemporaryKey.pfx
Normal file
BIN
ModernKeePassApp.Test/ModernKeePassApp.Test_TemporaryKey.pfx
Normal file
Binary file not shown.
56
ModernKeePassApp.Test/Package.appxmanifest
Normal file
56
ModernKeePassApp.Test/Package.appxmanifest
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
|
||||
|
||||
<Identity Name="8106fa65-36b6-421d-9e78-cb568e22d6b1"
|
||||
Publisher="CN=GBE"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>ModernKeePassApp.Test</DisplayName>
|
||||
<PublisherDisplayName>GBE</PublisherDisplayName>
|
||||
<Logo>Images\UnitTestStoreLogo.png</Logo>
|
||||
<Description>ModernKeePassApp.Test</Description>
|
||||
</Properties>
|
||||
|
||||
<Prerequisites>
|
||||
<OSMinVersion>6.3.0</OSMinVersion>
|
||||
<OSMaxVersionTested>6.3.0</OSMaxVersionTested>
|
||||
</Prerequisites>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="vstest.executionengine.App"
|
||||
Executable="vstest.executionengine.appcontainer.exe"
|
||||
EntryPoint="vstest.executionengine.App">
|
||||
<VisualElements
|
||||
DisplayName="NoUIEntryPoints"
|
||||
Logo="Images\UnitTestLogo.png"
|
||||
SmallLogo="Images\UnitTestSmallLogo.png"
|
||||
Description="vstest.executionengine.App"
|
||||
ForegroundText="light"
|
||||
BackgroundColor="#0084FF">
|
||||
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
|
||||
</VisualElements>
|
||||
</Application>
|
||||
|
||||
<Application Id="vstest.executionengine.x86.App"
|
||||
Executable="vstest.executionengine.appcontainer.x86.exe"
|
||||
EntryPoint="vstest.executionengine.x86.App">
|
||||
<VisualElements
|
||||
DisplayName="NoUIEntryPoints"
|
||||
Logo="Images\UnitTestLogo.png"
|
||||
SmallLogo="Images\UnitTestSmallLogo.png"
|
||||
Description="vstest.executionengine.x86.App"
|
||||
ForegroundText="light"
|
||||
BackgroundColor="#0084FF">
|
||||
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
|
||||
</VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
</Capabilities>
|
||||
</Package>
|
28
ModernKeePassApp.Test/Properties/AssemblyInfo.cs
Normal file
28
ModernKeePassApp.Test/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ModernKeePassApp.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ModernKeePassApp.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
14
ModernKeePassApp.Test/packages.config
Normal file
14
ModernKeePassApp.Test/packages.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.NETCore.Platforms" version="2.0.1" targetFramework="win81" />
|
||||
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.2" targetFramework="win81" />
|
||||
<package id="ModernKeePassLib" version="2.37.7000" targetFramework="win81" />
|
||||
<package id="NETStandard.Library" version="2.0.1" targetFramework="win81" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.1.3" targetFramework="win81" />
|
||||
<package id="Splat" version="2.0.0" targetFramework="win81" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Runtime.WindowsRuntime" version="4.3.0" targetFramework="win81" />
|
||||
<package id="System.Xml.XmlSerializer" version="4.3.0" targetFramework="win81" />
|
||||
<package id="Validation" version="2.4.18" targetFramework="win81" />
|
||||
</packages>
|
Reference in New Issue
Block a user