Esempio n. 1
0
        public void Sync()
        {
            // create initial state
            var initialState = new List <DocumentIdAndPath>
            {
                new DocumentIdAndPath
                {
                    Id       = Guid.NewGuid(),
                    FilePath = "/a",
                },
                new DocumentIdAndPath
                {
                    Id       = Guid.NewGuid(),
                    FilePath = "/b",
                },
                new DocumentIdAndPath
                {
                    Id       = Guid.NewGuid(),
                    FilePath = "/c",
                },
            };

            // setup storage mock
            List <Document> addedDocuments, updatedDocuments, removedDocuments;
            var             storageProviderMock = CreateStorageProviderMock(initialState, out addedDocuments, out updatedDocuments, out removedDocuments);

            DropBoxClientFactory clientFactory =
                (token) => new Client(new HttpClientFactory(), new RequestGenerator(), new Options()
            {
                AccessToken = token, UseSandbox = true
            });

            var options = new DropBoxSyncOptions
            {
                Path = "/Tests",
                IncludeSharedFolders        = false,
                WithThumbnailsOnly          = false,
                ItemsPerBatch               = 100,
                DownloadThumbnails          = true,
                NumberOfConcurrentDownloads = 10,
                MaxRetryAttempts            = 5,
                RetryDelaySeconds           = 10,
            };

            var service = new DropBoxSyncService(clientFactory, options);

            var contextMock = new Mock <ISyncContext>();

            contextMock.SetupGet(c => c.AccessToken).Returns(ConfigurationManager.AppSettings["DropBoxAccessToken"]);

            var result = service.Sync(contextMock.Object, storageProviderMock.Object).Result;

            Assert.IsNotNull(result);

            Assert.AreEqual(addedDocuments.Count, result.Added);
            Assert.AreEqual(removedDocuments.Count, result.Deleted);
            Assert.AreEqual(updatedDocuments.Count, result.Updated);
        }
Esempio n. 2
0
        public DropBoxSyncService(DropBoxClientFactory clientFactory, DropBoxSyncOptions options)
        {
            if (clientFactory == null)
            {
                throw new ArgumentNullException("clientFactory");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _clientFactory = clientFactory;
            _options       = options;
        }