public void GetObjectListOnPersistedStorage()
        {
            var conf = new DBreezeConfiguration {
                DBreezeDataFolderName = this.persistentDBreezePath,
                Storage = DBreezeConfiguration.eStorage.DISK
            };

            using (var engine = new DBreezeEngine(conf)) {
                var storage = new FileTransmissionStorage(engine);
                for (int i = 1; i <= 10; ++i)
                {
                    this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId" + i.ToString());
                    var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                    Assert.DoesNotThrow(() => storage.SaveObject(obj));
                    Assert.That(storage.GetObjectList().Count, Is.EqualTo(i));
                    Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
                }
            }

            using (var engine = new DBreezeEngine(conf)) {
                var storage = new FileTransmissionStorage(engine);
                for (int i = 1; i <= 10; ++i)
                {
                    Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
                }

                Assert.That(storage.GetObjectList().Count, Is.EqualTo(10));
            }
        }
        public void GetObjectByLocalPath()
        {
            var storage = new FileTransmissionStorage(this.engine);

            this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
            var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);

            Assert.DoesNotThrow(() => storage.SaveObject(obj));
            Assert.That(storage.GetObjectByLocalPath(this.localFile.Object.FullName).RemoteObjectId, Is.EqualTo("RemoteObjectId"));
            Assert.That(storage.GetObjectByLocalPath(this.localFile.Object.FullName + ".temp"), Is.Null);
        }
        public void SaveObjectBehaviorOverride()
        {
            var storage = new FileTransmissionStorage(this.engine);

            this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");

            for (int i = 1; i <= 10; ++i)
            {
                var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                Assert.DoesNotThrow(() => storage.SaveObject(obj));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(1));
                Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId"), Is.Not.Null);
                Assert.That(storage.GetObjectByRemoteObjectId("RemoteObjectId"), Is.Not.Null);
            }
        }
Пример #4
0
 public void InsertAndSelectFileTransmissionObjectData()
 {
     using (var tran = this.engine.GetTransaction()) {
         string key        = "key";
         var    remoteFile = new Mock <DotCMIS.Client.IDocument>();
         remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
         remoteFile.Setup(m => m.Paths).Returns(new List <string>()
         {
             "/RemoteFile"
         });
         var data = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.file.Object, remoteFile.Object);
         tran.Insert <string, DbCustomSerializer <FileTransmissionObject> >("objects", key, data);
         Assert.That((tran.Select <string, DbCustomSerializer <FileTransmissionObject> >("objects", key).Value.Get as FileTransmissionObject).Equals(data));
     }
 }
        public void ConstructorTakesData()
        {
            var remoteFile = new Mock <IDocument>();

            remoteFile.Setup(m => m.Paths).Returns(new List <string>()
            {
                "/RemoteFile"
            });
            remoteFile.Setup(m => m.Id).Returns("RemoteId");
            remoteFile.Setup(m => m.ChangeToken).Returns("ChangeToken");
            remoteFile.Setup(m => m.LastModificationDate).Returns(LocalFile.Object.LastWriteTimeUtc);
            remoteFile.Setup(m => m.VersionSeriesCheckedOutId).Returns("RemotePWCId");
            var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, LocalFile.Object, remoteFile.Object);

            Assert.AreEqual(TransmissionType.UPLOAD_NEW_FILE, obj.Type);
            Assert.AreEqual(LocalFile.Object.FullName, obj.LocalPath);
            Assert.AreEqual(LocalFile.Object.Length, obj.LastContentSize);
            Assert.AreEqual(null, obj.LastChecksum);
            Assert.AreEqual(null, obj.ChecksumAlgorithmName);
            Assert.AreEqual(LocalFile.Object.LastWriteTimeUtc, obj.LastLocalWriteTimeUtc);
            Assert.AreEqual("RemoteId", obj.RemoteObjectId);
            Assert.AreEqual("ChangeToken", obj.LastChangeToken);
            Assert.AreEqual("RemotePWCId", obj.RemoteObjectPWCId);
            Assert.AreEqual(LocalFile.Object.LastWriteTimeUtc, obj.LastRemoteWriteTimeUtc);
            var obj2 = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, LocalFile.Object, remoteFile.Object);

            Assert.IsTrue(obj.Equals(obj2));

            obj.ChecksumAlgorithmName = "SHA1";
            Assert.AreEqual("SHA1", obj.ChecksumAlgorithmName);
            obj.LastChecksum = new byte[32];
            using (var random = RandomNumberGenerator.Create()) {
                random.GetBytes(obj.LastChecksum);
            }

            Assert.IsFalse(obj.Equals(obj2));

            obj2.ChecksumAlgorithmName = "SHA1";
            obj2.LastChecksum          = new byte[32];
            using (var random = RandomNumberGenerator.Create()) {
                random.GetBytes(obj.LastChecksum);
            }

            Assert.IsFalse(obj.Equals(obj2));

            Buffer.BlockCopy(obj2.LastChecksum, 0, obj.LastChecksum, 0, 32);
            Assert.IsTrue(obj.Equals(obj2));
        }
Пример #6
0
        private void SaveCacheFile(IFileInfo target, IDocument remoteDocument, byte[] hash, long length, Transmission transmissionEvent)
        {
            if (this.TransmissionStorage == null)
            {
                return;
            }

            target.Refresh();
            IFileTransmissionObject obj = new FileTransmissionObject(transmissionEvent.Type, target, remoteDocument);

            obj.ChecksumAlgorithmName = "SHA-1";
            obj.LastChecksum          = hash;
            obj.LastContentSize       = length;

            this.TransmissionStorage.SaveObject(obj);
        }
        public void RemoveObjectOnMultipleTimesForSameRemoteObjectId()
        {
            var storage = new FileTransmissionStorage(this.engine);

            this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
            var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);

            Assert.DoesNotThrow(() => storage.SaveObject(obj));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(1));

            for (int i = 1; i <= 10; ++i)
            {
                Assert.DoesNotThrow(() => storage.RemoveObjectByRemoteObjectId("RemoteObjectId"));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
            }
        }
        private void SaveRemotePWCDocument(IFileInfo localFile, IDocument remoteDocument, IDocument remotePWCDocument, byte[] checksum, Transmission transmissionEvent)
        {
            if (remotePWCDocument == null)
            {
                return;
            }

            var obj = new FileTransmissionObject(transmissionEvent.Type, localFile, remoteDocument)
            {
                ChecksumAlgorithmName = "SHA-1",
                RemoteObjectPWCId     = remotePWCDocument.Id,
                LastChangeTokenPWC    = remotePWCDocument.ChangeToken,
                LastChecksumPWC       = checksum
            };

            this.TransmissionStorage.SaveObject(obj);
        }
        public void RemoveObjectOnMultipleTimes()
        {
            var storage = new FileTransmissionStorage(this.engine);

            for (int i = 1; i <= 10; ++i)
            {
                this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId" + i.ToString());
                var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                Assert.DoesNotThrow(() => storage.SaveObject(obj));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(i));
                Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
            }

            for (int i = 1; i <= 10; ++i)
            {
                Assert.DoesNotThrow(() => storage.RemoveObjectByRemoteObjectId("RemoteObjectId" + i.ToString()));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(10 - i));
                Assert.Throws <InvalidOperationException>(() => storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()));
            }
        }