public async Task StopAsync() { Mock <DocumentServiceLeaseStore> leaseStore = new Mock <DocumentServiceLeaseStore>(); leaseStore.Setup(l => l.IsInitializedAsync()).ReturnsAsync(true); Mock <DocumentServiceLeaseContainer> leaseContainer = new Mock <DocumentServiceLeaseContainer>(); leaseContainer.Setup(l => l.GetOwnedLeasesAsync()).Returns(Task.FromResult(Enumerable.Empty <DocumentServiceLease>())); leaseContainer.Setup(l => l.GetAllLeasesAsync()).Returns(Task.FromResult((IReadOnlyList <DocumentServiceLease>)Enumerable.Empty <DocumentServiceLease>())); Mock <DocumentServiceLeaseStoreManager> leaseStoreManager = new Mock <DocumentServiceLeaseStoreManager>(); leaseStoreManager.Setup(l => l.LeaseContainer).Returns(leaseContainer.Object); leaseStoreManager.Setup(l => l.LeaseManager).Returns(Mock.Of <DocumentServiceLeaseManager>); leaseStoreManager.Setup(l => l.LeaseStore).Returns(leaseStore.Object); leaseStoreManager.Setup(l => l.LeaseCheckpointer).Returns(Mock.Of <DocumentServiceLeaseCheckpointer>); ChangeFeedProcessorCore <MyDocument> processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory <MyDocument> > factory, out Mock <ChangeFeedObserver <MyDocument> > observer); processor.ApplyBuildConfiguration( leaseStoreManager.Object, null, "something", "instanceName", new ChangeFeedLeaseOptions(), new ChangeFeedProcessorOptions(), ChangeFeedProcessorCoreTests.GetMockedContainer("monitored")); await processor.StartAsync(); await processor.StopAsync(); Mock.Get(leaseContainer.Object) .Verify(store => store.GetAllLeasesAsync(), Times.Once); }
public async Task ObserverIsCreated() { IEnumerable <DocumentServiceLease> ownedLeases = new List <DocumentServiceLease>() { new DocumentServiceLeaseCore() { LeaseId = "0", LeaseToken = "0" } }; Mock <DocumentServiceLeaseStore> leaseStore = new Mock <DocumentServiceLeaseStore>(); leaseStore.Setup(l => l.IsInitializedAsync()).ReturnsAsync(true); Mock <DocumentServiceLeaseContainer> leaseContainer = new Mock <DocumentServiceLeaseContainer>(); leaseContainer.Setup(l => l.GetOwnedLeasesAsync()).Returns(Task.FromResult(ownedLeases)); Mock <DocumentServiceLeaseStoreManager> leaseStoreManager = new Mock <DocumentServiceLeaseStoreManager>(); leaseStoreManager.Setup(l => l.LeaseContainer).Returns(leaseContainer.Object); leaseStoreManager.Setup(l => l.LeaseManager).Returns(Mock.Of <DocumentServiceLeaseManager>); leaseStoreManager.Setup(l => l.LeaseStore).Returns(leaseStore.Object); leaseStoreManager.Setup(l => l.LeaseCheckpointer).Returns(Mock.Of <DocumentServiceLeaseCheckpointer>); ChangeFeedProcessorCore processor = null; try { processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory> factory, out Mock <ChangeFeedObserver> observer); processor.ApplyBuildConfiguration( leaseStoreManager.Object, null, "instanceName", new ChangeFeedLeaseOptions(), new ChangeFeedProcessorOptions(), ChangeFeedProcessorCoreTests.GetMockedContainer("monitored")); await processor.StartAsync(); Mock.Get(factory.Object) .Verify(mock => mock.CreateObserver(), Times.Once); Mock.Get(observer.Object) .Verify(mock => mock.OpenAsync(It.Is <string>((lt) => lt == ownedLeases.First().CurrentLeaseToken)), Times.Once); } finally { if (processor != null) { await processor.StopAsync(); } } }