private void RunSolverToDeleteLocalCacheBeforeContinue(
AbstractEnhancedSolver solver,
ContentChangeType localContent = ContentChangeType.NONE,
ContentChangeType remoteContent = ContentChangeType.NONE) {
this.cacheFile.Setup(f => f.Exists).Returns(false);
Mock<MemoryStream> stream = new Mock<MemoryStream>();
stream.SetupAllProperties();
stream.Setup(f => f.CanWrite).Returns(true); // required for System.Security.Cryptography.CryptoStream
this.localFileLength = 0;
stream.Setup(f => f.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Callback((byte[] buffer, int offset, int count) => this.localFileLength += count);
this.cacheFile.Setup(f => f.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)).Returns(() => {
this.cacheFile.Setup(f => f.Exists).Returns(true);
return stream.Object;
});
Mock<IDocument> remoteObject = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, this.objectId, this.objectName, this.parentId, this.fileContent.Length, this.fileContent, this.changeToken);
remoteObject.Setup(f => f.LastModificationDate).Returns((DateTime?)this.creationDate);
solver.Solve(this.localFile.Object, remoteObject.Object, localContent, remoteContent);
Assert.That(this.localFileLength, Is.EqualTo(this.fileContent.Length));
this.cacheFile.Verify(f => f.Open(It.IsAny<FileMode>(), It.IsAny<FileAccess>(), It.IsAny<FileShare>()), Times.Exactly(2)); // first open in SetupToAbortThePreviousDownload, second open to download
this.localFile.VerifySet(d => d.LastWriteTimeUtc = It.Is<DateTime>(date => date.Equals(this.creationDate)), Times.Once());
this.storage.VerifySavedMappedObject(MappedObjectType.File, this.objectId, this.objectName, this.parentId, this.changeToken, true, this.creationDate, this.creationDate, this.fileHash, this.fileContent.Length);
this.transmissionStorage.Verify(f => f.GetObjectByRemoteObjectId(this.objectId), Times.Exactly(2));
this.transmissionStorage.Verify(f => f.SaveObject(It.IsAny<IFileTransmissionObject>()), Times.AtLeastOnce());
this.transmissionStorage.Verify(f => f.RemoveObjectByRemoteObjectId(this.objectId), Times.Once());
}