public void IgnoreDuplicatedContentChangesEventTestDeleted() { var queue = new Mock<ISyncEventQueue>(); Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken(); Mock<ISession> session = MockSessionUtil.GetSessionMockReturning3Changesin2Batches(DotCMIS.Enums.ChangeType.Deleted, true); var startSyncEvent = new StartNextSyncEvent(false); var changes = new ContentChanges(session.Object, storage.Object, queue.Object, this.maxNumberOfContentChanges, this.isPropertyChangesSupported); Assert.IsTrue(changes.Handle(startSyncEvent)); queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Exactly(3)); }
public void ExtendCrawlSyncEvent() { var start = new StartNextSyncEvent(true); var repositoryService = new Mock<IRepositoryService>(); repositoryService.Setup(r => r.GetRepositoryInfos(null)).Returns((IList<IRepositoryInfo>)null); repositoryService.Setup(r => r.GetRepositoryInfo(It.IsAny<string>(), It.IsAny<IExtensionsData>()).LatestChangeLogToken).Returns(this.latestChangeLogToken); var session = new Mock<ISession>(); session.Setup(s => s.Binding.GetRepositoryService()).Returns(repositoryService.Object); session.Setup(s => s.RepositoryInfo.Id).Returns(this.repoId); var manager = new Mock<ISyncEventManager>().Object; var storage = new Mock<IMetaDataStorage>(); storage.Setup(db => db.ChangeLogToken).Returns((string)null); var queue = new Mock<ISyncEventQueue>(); var changes = new ContentChanges(session.Object, storage.Object, queue.Object); Assert.IsFalse(changes.Handle(start)); Assert.AreEqual(this.latestChangeLogToken, start.LastTokenOnServer); }
public void GivesCorrectContentChangeEvent() { ContentChangeEvent contentChangeEvent = null; var queue = new Mock<ISyncEventQueue>(); queue.Setup(q => q.AddEvent(It.IsAny<ContentChangeEvent>())).Callback((ISyncEvent f) => { contentChangeEvent = f as ContentChangeEvent; }); string id = "myId"; Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken(); var session = MockSessionUtil.PrepareSessionMockForSingleChange(DotCMIS.Enums.ChangeType.Created, id); var changes = new ContentChanges(session.Object, storage.Object, queue.Object, this.maxNumberOfContentChanges, this.isPropertyChangesSupported); var startSyncEvent = new StartNextSyncEvent(false); Assert.IsTrue(changes.Handle(startSyncEvent)); queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Once()); Assert.That(contentChangeEvent.Type, Is.EqualTo(DotCMIS.Enums.ChangeType.Created)); Assert.That(contentChangeEvent.ObjectId, Is.EqualTo(id)); }
public void HandleStartSyncEventOnNoRemoteChange() { var startSyncEvent = new StartNextSyncEvent(false); var session = new Mock<ISession>(); session.SetupSessionDefaultValues(); session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken); var storage = new Mock<IMetaDataStorage>(); storage.Setup(db => db.ChangeLogToken).Returns(this.changeLogToken); var queue = new Mock<ISyncEventQueue>(); var changes = new ContentChanges(session.Object, storage.Object, queue.Object); Assert.IsTrue(changes.Handle(startSyncEvent)); }
public void ExecuteCrawlSyncOnNoLocalTokenAvailable() { var startSyncEvent = new StartNextSyncEvent(false); var session = new Mock<ISession>(); session.SetupSessionDefaultValues(); session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken); var storage = new Mock<IMetaDataStorage>(); storage.Setup(db => db.ChangeLogToken).Returns((string)null); var queue = new Mock<ISyncEventQueue>(); var changes = new ContentChanges(session.Object, storage.Object, queue.Object); Assert.IsTrue(changes.Handle(startSyncEvent)); queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once()); }
private void DelayNextSyncEvent(StartNextSyncEvent startNextSyncEvent) { this.syncHasBeenDelayed = true; if (!this.lastDelayedSyncWasFullSync && startNextSyncEvent.FullSyncRequested == true) { this.lastDelayedSyncWasFullSync = true; } }
public void HandleFullSyncCompletedEvent() { var startSyncEvent = new StartNextSyncEvent(false); startSyncEvent.LastTokenOnServer = this.changeLogToken; var completedEvent = new FullSyncCompletedEvent(startSyncEvent); var storage = new Mock<IMetaDataStorage>(); storage.SetupProperty(db => db.ChangeLogToken); var queue = new Mock<ISyncEventQueue>(); var session = new Mock<ISession>(); var changes = new ContentChanges(session.Object, storage.Object, queue.Object); Assert.IsFalse(changes.Handle(completedEvent)); storage.VerifySet(db => db.ChangeLogToken = this.changeLogToken); Assert.AreEqual(this.changeLogToken, storage.Object.ChangeLogToken); }
public void ConstructorWithTrueParamSetsFullSyncRequestedFlagToTrue() { var start = new StartNextSyncEvent(true); Assert.IsTrue(start.FullSyncRequested); }
private void Sync() { // Get last change log token on server side. this.session.Binding.GetRepositoryService().GetRepositoryInfos(null); // refresh string lastTokenOnServer = this.session.Binding.GetRepositoryService().GetRepositoryInfo(this.session.RepositoryInfo.Id, null).LatestChangeLogToken; // Get last change token that had been saved on client side. string lastTokenOnClient = this.storage.ChangeLogToken; if (lastTokenOnClient == null) { // Token is null, which means no content change sync has ever happened yet, so just sync everything from remote. // Force full sync var fullsyncevent = new StartNextSyncEvent(true); Queue.AddEvent(fullsyncevent); return; } do { // Check which files/folders have changed. IChangeEvents changes = this.session.GetContentChanges(lastTokenOnClient, this.isPropertyChangesSupported, this.maxNumberOfContentChanges); // Replicate each change to the local side. bool first = true; foreach (IChangeEvent change in changes.ChangeEventList) { // ignore first event when lists overlapp if (first) { first = false; if (this.lastChange != null && (this.lastChange.ChangeType == DotCMIS.Enums.ChangeType.Created || this.lastChange.ChangeType == DotCMIS.Enums.ChangeType.Deleted)) { if (change != null && change.ChangeType == this.lastChange.ChangeType && change.ObjectId == this.lastChange.ObjectId) { continue; } } } this.lastChange = change; Queue.AddEvent(new ContentChangeEvent(change.ChangeType, change.ObjectId)); } // Save change log token locally. if (changes.HasMoreItems == true) { lastTokenOnClient = changes.LatestChangeLogToken; } else { lastTokenOnClient = lastTokenOnServer; } this.storage.ChangeLogToken = lastTokenOnClient; // refresh this.session.Binding.GetRepositoryService().GetRepositoryInfos(null); lastTokenOnServer = this.session.Binding.GetRepositoryService().GetRepositoryInfo(this.session.RepositoryInfo.Id, null).LatestChangeLogToken; } while (!lastTokenOnServer.Equals(lastTokenOnClient)); }
public void ConstructorWithFalseParamSetsFullSyncRequestedFlagToFalse() { var start = new StartNextSyncEvent(false); Assert.IsFalse(start.FullSyncRequested); }
/// <summary> /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.FullSyncCompletedEvent"/> class. /// </summary> /// <param name="startEvent">Start event, which is completed.</param> public FullSyncCompletedEvent(StartNextSyncEvent startEvent) : base(startEvent) { }
public void RunStartSyncEvent() { var startSyncEvent = new StartNextSyncEvent(false); this.AddEvent(startSyncEvent); this.Run(); }
public void HandlesStartNextSyncEventAndReportsOnQueueIfDone() { var crawler = this.CreateCrawler(); var startEvent = new StartNextSyncEvent(); Assert.That(crawler.Handle(startEvent), Is.True); this.queue.Verify(q => q.AddEvent(It.Is<FullSyncCompletedEvent>(e => e.StartEvent.Equals(startEvent))), Times.Once()); this.VerifyThatListenerHasBeenUsed(); }