public async Task TestOpen() { var file = await _fileProxy.OpenBinaryFile(Path.Combine(Directory.GetCurrentDirectory(), "Data", "TestDatabase.kdbx")); await _database.Open(file, _credentials); var rootGroup = _database.GetGroup(_database.RootGroupId); Assert.That(_database.Name, Is.EqualTo("TestDatabase")); Assert.That(rootGroup.Entries.Count, Is.EqualTo(2)); }
public void SetUp() { var dateTime = Substitute.For <IDateTime>(); _fileProxy = Substitute.For <IFileProxy>(); _fileProxy.OpenBinaryFile(Arg.Any <string>()).Returns(async parameters => { await using var stream = File.Open((string)parameters[0], FileMode.OpenOrCreate); var contents = new byte[stream.Length]; await stream.ReadAsync(contents, 0, (int)stream.Length); return(contents); }); _fileProxy.WriteBinaryContentsToFile(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(async parameters => { await using var stream = File.Open((string)parameters[0], FileMode.OpenOrCreate); var contents = (byte[])parameters[1]; await stream.WriteAsync(contents, 0, contents.Length); }); var mapper = new Mapper(new MapperConfiguration(cfg => { cfg.AddProfile(typeof(EntryMappingProfile)); })); _database = new KeePassDatabaseClient(mapper, dateTime); }