public void ShouldNotNotifyOnNextWhenDisposed() { var disposed = false; var onNextCalledAfterDispose = false; var done = true; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 2)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot"), TimeSpan.FromMilliseconds(5)); Action <ISnapshotStatusResponse> onNext = response => { done = true; if (disposed) { onNextCalledAfterDispose = true; } }; using (sut.Subscribe(new SnapshotObserver(onNext, exception => done = true, () => done = true))) { while (!done) { Thread.Sleep(10); } } disposed = true; Thread.Sleep(100); Assert.AreEqual(false, onNextCalledAfterDispose); }
public void OnError_SnapshotObservableShouldNotify() { var onErrorWasCalled = false; var done = false; var snapshotStatusReponseMock = new Mock <ISnapshotStatusResponse>(); snapshotStatusReponseMock.SetupGet(x => x.IsValid).Returns(false); var elastickClientMock = new Mock <IElasticClient>(); elastickClientMock.Setup(x => x.Snapshot(It.IsAny <ISnapshotRequest>())) .Returns(new SnapshotResponse()); elastickClientMock.Setup(x => x.SnapshotStatus(It.IsAny <ISnapshotStatusRequest>())) .Returns(snapshotStatusReponseMock.Object); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver(response => done = true, exception => onErrorWasCalled = done = true, () => done = true)); while (!done) { Thread.Sleep(10); } Assert.AreEqual(true, onErrorWasCalled); }
public void ObserverIsNull_Exception() { var elastickClientMock = new Mock <IElasticClient>(); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); using (sut.Subscribe(null)) { } }
public void ObserverIsNull_Exception() { var elastickClientMock = new Mock<IElasticClient>(); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); using (sut.Subscribe(null)) { } }
public void OnCompleted_SnapshotObservableShouldNotify() { var onCompletedWasCalled = false; var done = false; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 1)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver(response => done = true, exception => done = true, () => onCompletedWasCalled = done = true)); while (!done) { Thread.Sleep(10); } Assert.AreEqual(true, onCompletedWasCalled); }
public void ShouldCallSnapshotMethodOnce() { var elastickClientMock = new Mock<IElasticClient>(); elastickClientMock.Setup(x => x.Snapshot(It.IsAny<ISnapshotRequest>())) .Returns(new SnapshotResponse()); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver()); elastickClientMock.Verify(x => x .Snapshot( It.Is<ISnapshotRequest>( request => request.Repository == "repository" && request.Snapshot == "snapshot" && request.RequestParameters.ContainsKey("wait_for_completion") == true && request.RequestParameters.GetQueryStringValue<bool>("wait_for_completion") == false)), Times.Once); }
public void ShouldCallSnapshotMethodOnce() { var elastickClientMock = new Mock <IElasticClient>(); elastickClientMock.Setup(x => x.Snapshot(It.IsAny <ISnapshotRequest>())) .Returns(new SnapshotResponse()); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver()); elastickClientMock.Verify(x => x .Snapshot( It.Is <ISnapshotRequest>( request => request.Repository == "repository" && request.Snapshot == "snapshot" && request.RequestParameters.ContainsKey("wait_for_completion") == true && request.RequestParameters.GetQueryStringValue <bool>("wait_for_completion") == false)), Times.Once); }
public void OnNext_SnapshotObservableShouldNotify() { var onNextWasCalled = false; var done = false; var onNextCounter = 0; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 2)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot"), TimeSpan.FromMilliseconds(100)); sut.Subscribe(new SnapshotObserver(response => { onNextCounter++; onNextWasCalled = done = true; }, exception => done = true, () => done = true)); while (!done) { Thread.Sleep(10); } Assert.AreEqual(true, onNextWasCalled); Assert.AreEqual(1, onNextCounter); }
public void OnNext_SnapshotObservableShouldNotify() { var onNextWasCalled = false; var done = false; var onNextCounter = 0; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 2)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot"), TimeSpan.FromMilliseconds(100)); sut.Subscribe(new SnapshotObserver(response => { onNextCounter++; onNextWasCalled = done = true; }, exception => done = true, () => done = true)); while (!done) Thread.Sleep(10); Assert.AreEqual(true, onNextWasCalled); Assert.AreEqual(1, onNextCounter); }
public void OnError_SnapshotObservableShouldNotify() { var onErrorWasCalled = false; var done = false; var snapshotStatusReponseMock = new Mock<ISnapshotStatusResponse>(); snapshotStatusReponseMock.SetupGet(x => x.IsValid).Returns(false); var elastickClientMock = new Mock<IElasticClient>(); elastickClientMock.Setup(x => x.Snapshot(It.IsAny<ISnapshotRequest>())) .Returns(new SnapshotResponse()); elastickClientMock.Setup(x => x.SnapshotStatus(It.IsAny<ISnapshotStatusRequest>())) .Returns(snapshotStatusReponseMock.Object); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver(response => done = true, exception => onErrorWasCalled = done = true, () => done = true)); while (!done) Thread.Sleep(10); Assert.AreEqual(true, onErrorWasCalled); }
public void OnCompleted_SnapshotObservableShouldNotify() { var onCompletedWasCalled = false; var done = false; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 1)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot")); sut.Subscribe(new SnapshotObserver(response => done = true, exception => done = true, () => onCompletedWasCalled = done = true)); while (!done) Thread.Sleep(10); Assert.AreEqual(true, onCompletedWasCalled); }
public void ShouldNotNotifyOnNextWhenDisposed() { var disposed = false; var onNextCalledAfterDispose = false; var done = true; var elastickClientMock = ElastickClientMock(SnapshotStatusFixture(1, 1, 2)); var sut = new SnapshotObservable(elastickClientMock.Object, new SnapshotRequest("repository", "snapshot"), TimeSpan.FromMilliseconds(5)); Action<ISnapshotStatusResponse> onNext = response => { done = true; if (disposed) onNextCalledAfterDispose = true; }; using (sut.Subscribe(new SnapshotObserver(onNext, exception => done = true, () => done = true))) { while (!done) Thread.Sleep(10); } disposed = true; Thread.Sleep(100); Assert.AreEqual(false, onNextCalledAfterDispose); }