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 SaveObjectThrowsExceptionIfObjectIsInvalid()
        {
            var storage = new FileTransmissionStorage(this.engine);
            var obj     = new Mock <IFileTransmissionObject>();

            // argument cannot be null
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(null));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.LocalPath cannot be null
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.LocalPath cannot be empty string
            obj.Setup(m => m.LocalPath).Returns(string.Empty);
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.RemoteObjectId cannot be null
            obj.Setup(m => m.LocalPath).Returns("/LocalPath");
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.RemoteObjectId cannot be empty string
            obj.Setup(m => m.RemoteObjectId).Returns(string.Empty);
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // argument should be FileTransmissionObject
            obj.Setup(m => m.RemoteObjectId).Returns("RemoteObjectId");
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
        }
        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);
            }
        }
        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));
            }
        }
        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()));
            }
        }