keepass2android/src/Kp2aUnitTests/TestFileStorage.cs
Philipp Crocoll a44e8a9680 * added options to exclude libraries for faster build times (DEBUG only)
* implemented getFileEntry to get information about a single file
* password activity is launched automatically if there are recent files
2013-09-28 21:14:21 +02:00

125 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using KeePassLib.Serialization;
using keepass2android.Io;
namespace Kp2aUnitTests
{
internal class TestFileStorage: IFileStorage
{
private BuiltInFileStorage _builtIn = new BuiltInFileStorage();
public bool Offline { get; set; }
public IEnumerable<string> SupportedProtocols { get { yield return "test"; } }
public void DeleteFile(IOConnectionInfo ioc)
{
if (Offline)
throw new IOException("offline");
_builtIn.Delete(ioc);
}
public IFileStorageSetup RequiredSetup { get { return null; } }
public void Delete(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public bool CheckForFileChangeFast(IOConnectionInfo ioc, string previousFileVersion)
{
if (Offline)
return false;
return _builtIn.CheckForFileChangeFast(ioc, previousFileVersion);
}
public string GetCurrentFileVersionFast(IOConnectionInfo ioc)
{
if (Offline)
throw new IOException("offline");
return _builtIn.GetCurrentFileVersionFast(ioc);
}
public Stream OpenFileForRead(IOConnectionInfo ioc)
{
if (Offline)
throw new IOException("offline");
return _builtIn.OpenFileForRead(ioc);
}
public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
{
if (Offline)
throw new IOException("offline");
return new TestFileTransaction(ioc, useFileTransaction, Offline);
}
public class TestFileTransaction : IWriteTransaction
{
private readonly bool _offline;
private readonly FileTransactionEx _transaction;
public TestFileTransaction(IOConnectionInfo ioc, bool useFileTransaction, bool offline)
{
_offline = offline;
_transaction = new FileTransactionEx(ioc, useFileTransaction);
}
public void Dispose()
{
}
public Stream OpenFile()
{
if (_offline)
throw new IOException("offline");
return _transaction.OpenWrite();
}
public void CommitWrite()
{
if (_offline)
throw new IOException("offline");
_transaction.CommitWrite();
}
}
public bool CompleteIoId()
{
throw new NotImplementedException();
}
public bool? FileExists()
{
throw new NotImplementedException();
}
public string GetFilenameWithoutPathAndExt(IOConnectionInfo ioc)
{
return _builtIn.GetFilenameWithoutPathAndExt(ioc);
}
public bool RequiresCredentials(IOConnectionInfo ioc)
{
return _builtIn.RequiresCredentials(ioc);
}
public void CreateDirectory(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public FileDescription GetFileDescription(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
}
}