Create DB works correctly

Sample data moved to application
Tests updated (still not working - splat)
WIP
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-07 17:29:03 +02:00
parent 1fa799bdf8
commit 4863eb9fae
20 changed files with 205 additions and 159 deletions

View File

@@ -34,6 +34,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|ARM' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<None Include="project.json" />

View File

@@ -20,7 +20,7 @@ namespace ModernKeePass.Application.Common.Interfaces
Task Open(byte[] file, Credentials credentials);
Task ReOpen(byte[] file);
Task Create(byte[] file, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
Task Create(Credentials credentials, string name, DatabaseVersion version = DatabaseVersion.V2);
Task<byte[]> SaveDatabase();
Task<byte[]> SaveDatabase(byte[] newFileContents);
void UpdateCredentials(Credentials credentials);
@@ -35,7 +35,7 @@ namespace ModernKeePass.Application.Common.Interfaces
Task RemoveGroup(string parentGroupId, string groupId);
void DeleteEntity(string entityId);
EntryEntity CreateEntry(string parentGroupId);
GroupEntity CreateGroup(string parentGroupId, string nameId, bool isRecycleBin = false);
GroupEntity CreateGroup(string parentGroupId, string name, bool isRecycleBin = false);
void SortEntries(string groupId);
void SortSubGroups(string groupId);
EntryEntity GetEntry(string id);

View File

@@ -7,7 +7,7 @@ namespace ModernKeePass.Application.Common.Interfaces
public interface IRecentProxy
{
int EntryCount { get; }
Task<FileInfo> Get(string token);
Task<FileInfo> Get(string token, bool updateAccessTime = false);
Task<IEnumerable<FileInfo>> GetAll();
Task Add(FileInfo recentItem);
void ClearAll();

View File

@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Exceptions;
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Application.Database.Commands.CreateDatabase
{
@@ -11,6 +12,8 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
public string FilePath { get; set; }
public string Password { get; set; }
public string KeyFilePath { get; set; }
public string Name { get; set; }
public bool CreateSampleData { get; set; }
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand>
{
@@ -27,16 +30,33 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
{
if (_database.IsOpen) throw new DatabaseOpenException();
var file = await _file.OpenBinaryFile(message.FilePath);
await _database.Create(file,
new Credentials
await _database.Create(new Credentials
{
KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath) : null,
Password = message.Password
});
}, message.Name);
_database.FileAccessToken = message.FilePath;
}
if (message.CreateSampleData)
{
var bankingGroup = _database.CreateGroup(_database.RootGroupId, "Banking");
var emailGroup = _database.CreateGroup(_database.RootGroupId, "Email");
var internetGroup = _database.CreateGroup(_database.RootGroupId, "Internet");
var sample1 = _database.CreateEntry(_database.RootGroupId);
_database.UpdateEntry(sample1.Id, EntryFieldName.Title, "Sample Entry" );
_database.UpdateEntry(sample1.Id, EntryFieldName.UserName, "Username" );
_database.UpdateEntry(sample1.Id, EntryFieldName.Password, "Password" );
_database.UpdateEntry(sample1.Id, EntryFieldName.Url, "https://keepass.info/" );
_database.UpdateEntry(sample1.Id, EntryFieldName.Notes, "You may safely delete this sample" );
var sample2 = _database.CreateEntry(_database.RootGroupId);
_database.UpdateEntry(sample2.Id, EntryFieldName.Title, "Sample Entry #2" );
_database.UpdateEntry(sample2.Id, EntryFieldName.UserName, "Michael321" );
_database.UpdateEntry(sample2.Id, EntryFieldName.Password, "12345" );
_database.UpdateEntry(sample2.Id, EntryFieldName.Url, "https://keepass.info/help/kb/testform.html" );
}
}
}
}
}