private void TestPlaceholders(Action <PlaceholderTable, Mock <IDbCommand> > testCode) { Mock <IDbCommand> mockCommand = new Mock <IDbCommand>(MockBehavior.Strict); mockCommand.Setup(x => x.Dispose()); Mock <IDbConnection> mockConnection = new Mock <IDbConnection>(MockBehavior.Strict); mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object); mockConnection.Setup(x => x.Dispose()); Mock <IGVFSConnectionPool> mockConnectionPool = new Mock <IGVFSConnectionPool>(MockBehavior.Strict); mockConnectionPool.Setup(x => x.GetConnection()).Returns(mockConnection.Object); PlaceholderTable placeholders = new PlaceholderTable(mockConnectionPool.Object); testCode(placeholders, mockCommand); mockCommand.Verify(x => x.Dispose(), Times.Once); mockCommand.VerifyAll(); mockConnection.Verify(x => x.Dispose(), Times.Once); mockConnection.VerifyAll(); mockConnectionPool.VerifyAll(); }
public void ConstructorTest() { Mock <IGVFSConnectionPool> mockConnectionPool = new Mock <IGVFSConnectionPool>(MockBehavior.Strict); PlaceholderTable placeholders = new PlaceholderTable(mockConnectionPool.Object); mockConnectionPool.VerifyAll(); }
/// <summary> /// Get two lists of placeholders, one containing the files and the other the directories /// Goes to the SQLite database for the placeholder lists /// </summary> /// <param name="enlistment">The current GVFS enlistment being operated on</param> /// <param name="filePlaceholders">Out parameter where the list of file placeholders will end up</param> /// <param name="folderPlaceholders">Out parameter where the list of folder placeholders will end up</param> private void GetPlaceholdersFromDatabase(GVFSEnlistment enlistment, EnlistmentPathData pathData) { List <IPlaceholderData> filePlaceholders = new List <IPlaceholderData>(); List <IPlaceholderData> folderPlaceholders = new List <IPlaceholderData>(); using (GVFSDatabase database = new GVFSDatabase(new PhysicalFileSystem(), enlistment.EnlistmentRoot, new SqliteDatabase())) { PlaceholderTable placeholderTable = new PlaceholderTable(database); placeholderTable.GetAllEntries(out filePlaceholders, out folderPlaceholders); } pathData.PlaceholderFilePaths.AddRange(filePlaceholders.Select(placeholderData => placeholderData.Path)); pathData.PlaceholderFolderPaths.AddRange(folderPlaceholders.Select(placeholderData => placeholderData.Path)); }
public void CreateTableTest() { Mock <IDbCommand> mockCommand = new Mock <IDbCommand>(MockBehavior.Strict); mockCommand.SetupSet(x => x.CommandText = "CREATE TABLE IF NOT EXISTS [Placeholder] (path TEXT PRIMARY KEY COLLATE NOCASE, pathType TINYINT NOT NULL, sha char(40) ) WITHOUT ROWID;"); mockCommand.Setup(x => x.ExecuteNonQuery()).Returns(1); mockCommand.Setup(x => x.Dispose()); Mock <IDbConnection> mockConnection = new Mock <IDbConnection>(MockBehavior.Strict); mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object); PlaceholderTable.CreateTable(mockConnection.Object); mockCommand.VerifyAll(); mockConnection.VerifyAll(); }
public void CreateTableThrowsExceptionNotWrappedInGVFSDatabaseException() { Mock <IDbCommand> mockCommand = new Mock <IDbCommand>(MockBehavior.Strict); mockCommand.SetupSet(x => x.CommandText = "CREATE TABLE IF NOT EXISTS [Placeholder] (path TEXT PRIMARY KEY COLLATE NOCASE, pathType TINYINT NOT NULL, sha char(40) ) WITHOUT ROWID;"); mockCommand.Setup(x => x.ExecuteNonQuery()).Throws(new Exception(DefaultExceptionMessage)); mockCommand.Setup(x => x.Dispose()); Mock <IDbConnection> mockConnection = new Mock <IDbConnection>(MockBehavior.Strict); mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object); Exception ex = Assert.Throws <Exception>(() => PlaceholderTable.CreateTable(mockConnection.Object)); ex.Message.ShouldEqual(DefaultExceptionMessage); mockCommand.VerifyAll(); mockConnection.VerifyAll(); }
public override bool TryUpgrade(ITracer tracer, string enlistmentRoot) { string dotGVFSRoot = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot); try { PhysicalFileSystem fileSystem = new PhysicalFileSystem(); string error; LegacyPlaceholderListDatabase placeholderList; if (!LegacyPlaceholderListDatabase.TryCreate( tracer, Path.Combine(dotGVFSRoot, GVFSConstants.DotGVFS.Databases.PlaceholderList), fileSystem, out placeholderList, out error)) { tracer.RelatedError("Failed to open placeholder list database: " + error); return(false); } using (placeholderList) using (GVFSDatabase database = new GVFSDatabase(fileSystem, enlistmentRoot, new SqliteDatabase())) { PlaceholderTable placeholders = new PlaceholderTable(database); List <IPlaceholderData> oldPlaceholderEntries = placeholderList.GetAllEntries(); foreach (IPlaceholderData entry in oldPlaceholderEntries) { placeholders.AddPlaceholderData(entry); } } } catch (Exception ex) { tracer.RelatedError("Error updating placeholder list database to SQLite: " + ex.ToString()); return(false); } if (!this.TryIncrementMajorVersion(tracer, enlistmentRoot)) { return(false); } return(true); }