Ejemplo n.º 1
0
        public override Task<SynchronizationReport> PerformAsync(RavenFileSystemClient.SynchronizationClient destination)
		{
			FileAndPages fileAndPages = null;
			Storage.Batch(accessor => fileAndPages = accessor.GetFile(FileName, 0, 0));

            return destination.DeleteAsync(FileName, fileAndPages.Metadata, ServerInfo);
		}
Ejemplo n.º 2
0
        public async Task NotificationReceivedWhenFileDeleted()
        {
            await client.UploadAsync("abc.txt", new MemoryStream());

            var notificationTask = client.Changes().ForFolder("/")
                                   .Timeout(TimeSpan.FromSeconds(2))
                                   .Take(1).ToTask();

            await client.DeleteAsync("abc.txt");

            var fileChange = await notificationTask;

            Assert.Equal("/abc.txt", fileChange.File);
            Assert.Equal(FileChangeAction.Delete, fileChange.Action);
        }
        public async Task NotificationsAreReceivedOnSourceWhenSynchronizationsAreStartedAndFinished()
        {
            // content update
            await source.UploadAsync("test.bin", new MemoryStream(new byte[] { 1, 2, 3 }));

            var notificationTask =
                source.Changes().ForSynchronization()
                .Where(s => s.SynchronizationDirection == SynchronizationDirection.Outgoing)
                .Timeout(TimeSpan.FromSeconds(20)).Take(2).ToArray().
                ToTask();

            var report = await source.Synchronization.StartAsync("test.bin", destination);

            Assert.Null(report.Exception);

            var synchronizationUpdates = await notificationTask;

            Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action);
            Assert.Equal("test.bin", synchronizationUpdates[0].FileName);
            Assert.Equal(SynchronizationType.ContentUpdate, synchronizationUpdates[0].Type);
            Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action);
            Assert.Equal("test.bin", synchronizationUpdates[1].FileName);
            Assert.Equal(SynchronizationType.ContentUpdate, synchronizationUpdates[1].Type);

            // metadata update
            await source.UpdateMetadataAsync("test.bin", new RavenJObject { { "key", "value" } });

            notificationTask = source.Changes().ForSynchronization()
                               .Where(s => s.SynchronizationDirection == SynchronizationDirection.Outgoing)
                               .Timeout(TimeSpan.FromSeconds(20))
                               .Take(2).ToArray()
                               .ToTask();

            report = await source.Synchronization.StartAsync("test.bin", destination);

            Assert.Null(report.Exception);

            synchronizationUpdates = await notificationTask;

            Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action);
            Assert.Equal("test.bin", synchronizationUpdates[0].FileName);
            Assert.Equal(SynchronizationType.MetadataUpdate, synchronizationUpdates[0].Type);
            Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action);
            Assert.Equal("test.bin", synchronizationUpdates[1].FileName);
            Assert.Equal(SynchronizationType.MetadataUpdate, synchronizationUpdates[1].Type);

            // rename update
            await source.RenameAsync("test.bin", "rename.bin");

            notificationTask = source.Changes().ForSynchronization()
                               .Where(s => s.SynchronizationDirection == SynchronizationDirection.Outgoing)
                               .Timeout(TimeSpan.FromSeconds(20))
                               .Take(2).ToArray()
                               .ToTask();

            report = await source.Synchronization.StartAsync("test.bin", destination);

            Assert.Null(report.Exception);

            synchronizationUpdates = await notificationTask;

            Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action);
            Assert.Equal("test.bin", synchronizationUpdates[0].FileName);
            Assert.Equal(SynchronizationType.Rename, synchronizationUpdates[0].Type);
            Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action);
            Assert.Equal("test.bin", synchronizationUpdates[1].FileName);
            Assert.Equal(SynchronizationType.Rename, synchronizationUpdates[1].Type);

            // delete update
            await source.DeleteAsync("rename.bin");

            notificationTask = source.Changes().ForSynchronization()
                               .Where(s => s.SynchronizationDirection == SynchronizationDirection.Outgoing)
                               .Timeout(TimeSpan.FromSeconds(20))
                               .Take(2).ToArray()
                               .ToTask();

            report = await source.Synchronization.StartAsync("rename.bin", destination);

            Assert.Null(report.Exception);

            synchronizationUpdates = await notificationTask;

            Assert.Equal(SynchronizationAction.Start, synchronizationUpdates[0].Action);
            Assert.Equal("rename.bin", synchronizationUpdates[0].FileName);
            Assert.Equal(SynchronizationType.Delete, synchronizationUpdates[0].Type);
            Assert.Equal(SynchronizationAction.Finish, synchronizationUpdates[1].Action);
            Assert.Equal("rename.bin", synchronizationUpdates[1].FileName);
            Assert.Equal(SynchronizationType.Delete, synchronizationUpdates[1].Type);
        }