Exemple #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);
        }
        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);
        }