* CachingFileStorage: Added more callbacks to provide user with more information what's going on
* Changed TestCacheSupervisor for easier use of the many callbacks * Adapted tests for new callbacks * GroupBaseActivity: Added sync menu command * Preferences: Added option to enable/disable offline caching * App: don't lock database when user wants to reload. This is done in PasswordActivity and should be done there after the password was filled into the pw field * CheckDatabaseForChanges.cs: used when syncing a non-cached database
This commit is contained in:
@@ -1,29 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KeePassLib.Serialization;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using keepass2android.Io;
|
||||
|
||||
namespace Kp2aUnitTests
|
||||
{
|
||||
class TestCacheSupervisor: ICacheSupervisor
|
||||
{
|
||||
public bool CouldntOpenFromRemoteCalled { get; set; }
|
||||
public bool CouldntSaveToRemoteCalled { get; set; }
|
||||
public bool NotifyOpenFromLocalDueToConflictCalled { get; set; }
|
||||
public const string CouldntOpenFromRemoteId = "CouldntOpenFromRemote";
|
||||
public const string CouldntSaveToRemoteId = "CouldntSaveToRemote";
|
||||
public const string NotifyOpenFromLocalDueToConflictId = "CouldntSaveToRemote";
|
||||
public const string UpdatedCachedFileOnLoadId = "UpdatedCachedFileOnLoad";
|
||||
public const string LoadedFromRemoteInSyncId = "LoadedFromRemoteInSync";
|
||||
public const string UpdatedRemoteFileOnLoadId = "UpdatedRemoteFileOnLoad";
|
||||
|
||||
private HashSet<string> _callsMade = new HashSet<string>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_callsMade.Clear();
|
||||
}
|
||||
|
||||
public void AssertNoCall()
|
||||
{
|
||||
string allCalls = _callsMade.Aggregate("", (current, s) => current + s + ",");
|
||||
Assert.AreEqual("", allCalls);
|
||||
}
|
||||
|
||||
public void AssertSingleCall(string id)
|
||||
{
|
||||
if ((_callsMade.Count == 1)
|
||||
&& _callsMade.Single() == id)
|
||||
{
|
||||
Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Assert.Fail("expected only "+id+", but received: "+_callsMade.Aggregate("", (current, s) => current + s + ","));
|
||||
|
||||
}
|
||||
|
||||
public void CouldntSaveToRemote(IOConnectionInfo ioc, Exception e)
|
||||
{
|
||||
CouldntSaveToRemoteCalled = true;
|
||||
_callsMade.Add(CouldntSaveToRemoteId);
|
||||
}
|
||||
|
||||
public void CouldntOpenFromRemote(IOConnectionInfo ioc, Exception ex)
|
||||
{
|
||||
CouldntOpenFromRemoteCalled = true;
|
||||
_callsMade.Add(CouldntOpenFromRemoteId);
|
||||
}
|
||||
|
||||
public void UpdatedCachedFileOnLoad(IOConnectionInfo ioc)
|
||||
{
|
||||
_callsMade.Add(UpdatedCachedFileOnLoadId);
|
||||
}
|
||||
|
||||
public void UpdatedRemoteFileOnLoad(IOConnectionInfo ioc)
|
||||
{
|
||||
_callsMade.Add(UpdatedRemoteFileOnLoadId);
|
||||
}
|
||||
|
||||
public void NotifyOpenFromLocalDueToConflict(IOConnectionInfo ioc)
|
||||
{
|
||||
NotifyOpenFromLocalDueToConflictCalled = true;
|
||||
_callsMade.Add(NotifyOpenFromLocalDueToConflictId);
|
||||
}
|
||||
|
||||
public void LoadedFromRemoteInSync(IOConnectionInfo ioc)
|
||||
{
|
||||
_callsMade.Add(LoadedFromRemoteInSyncId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user