public void DataSourceWatcher_ErrorOccurs_ErrorEventIsFired() { var exception = new InternalTestFailureException(); var errorEventFired = false; var onStart = new Action <IDataSourceWatcher>(dsw => { }); var onStop = new Action <IDataSourceWatcher>(dsw => { }); var dataSource = MockRepository.GenerateMock <IDataSource>(); var dataSourceWatcher = new MockDataSourceWatcher(onStart, onStop); dataSourceWatcher.Error += (sender, e) => { errorEventFired = true; Assert.AreEqual(exception, e.Exception); }; dataSourceWatcher.Start(); dataSourceWatcher.RaiseErrorEvent(exception); dataSourceWatcher.Stop(); Assert.IsTrue(errorEventFired); }
public void PerformCancelableAction_AggregateExceptionContainingUnexpectedExceptionAndOperationCanceledExceptionIsThrown_ExceptionIsPropogated() { var internalTestFailureException = new InternalTestFailureException(); var operationCanceledException = new OperationCanceledException(); ActionHelper.PerformCancelableAction(() => throw new AggregateException(internalTestFailureException, operationCanceledException)); }
public async Task CatchNotCalledWhenHandledInThenCallback() { var othersWereCalled1 = false; var handlerCalled1 = false; var catchCalled1 = false; var othersWereCalled2 = false; var catchCalled2 = false; var exception = new InternalTestFailureException(); var promise = new SharpPromise.Promise(resolve => resolve()); var prom = promise.Then(() => { }) .Then(() => { }) .Then((Action)(() => throw exception)); var run1 = prom.Then(() => { }, ex => { handlerCalled1 = true; ex.ShouldBe(exception, "Exceptions were not the same."); }) .Then(() => { othersWereCalled1 = true; }) .Catch(ex => { catchCalled1 = true; }); var run2 = prom.Then(() => { othersWereCalled2 = true; }) .Catch(ex => { catchCalled2 = true; }); await SharpPromise.Promise.All(run1, run2); othersWereCalled1.ShouldBeTrue("Subsequent \"Then\" calls were not executed after exception was handled."); handlerCalled1.ShouldBeTrue("Handler was not called after exception."); catchCalled1.ShouldBeFalse("Catch was still called after exception was handled."); othersWereCalled2.ShouldBeFalse(); catchCalled2.ShouldBeTrue(); }
public void Constructor_ExceptionAndDataSourceProvided_PropertiesAreSet() { var exception = new InternalTestFailureException(); var dataSource = MockRepository.GenerateMock <IDataSource>(); var createDataImportErrorEventArgs = new CreateDataImportErrorEventArgs(exception, dataSource); Assert.AreEqual(exception, createDataImportErrorEventArgs.Exception); Assert.AreEqual(dataSource, createDataImportErrorEventArgs.DataSource); }
public async Task ExceptionIsPassedThroughFinally() { var wasCalled = false; var message = "It was passed as expected."; var value = new InternalTestFailureException(message); await SharpPromise.Promise <int> .Reject(value) .Finally(() => { wasCalled = true; }) .Catch(val => val.Message.ShouldBe(message)); wasCalled.ShouldBeTrue(); }
public async Task ExceptionIsPassedThroughFinallyAndHandledInThen() { var wasCalled = false; var wrongThenCalled = false; var value = new InternalTestFailureException("It was passed as expected."); await SharpPromise.Promise <int> .Reject(value) .Finally(() => { wasCalled = true; }) .Then(() => { wrongThenCalled = true; }, val => val.ShouldBe(value)); wasCalled.ShouldBeTrue(); wrongThenCalled.ShouldBeFalse(); }
public async Task ExceptionGetsHandledInThenCallbackFromRejectedTask() { var message = "Task failed, but that's what we wanted."; var ex = new InternalTestFailureException(message); var testTask = new SharpPromise.Promise(Task.FromException(ex)); await testTask.Then(() => { Assert.Fail("Promise resolved, but should not have."); }, e => { e.Message.ShouldBe(message, "Exception messages did not match."); }); }
public async Task ThenReturnsPromiseWithException() { var message = "Promise failed, but that's what we expected"; var ex = new InternalTestFailureException(message); var testPromise = SharpPromise.Promise.Resolve() .Then(() => { return(SharpPromise.Promise.Reject(ex)); }); await testPromise.Then(() => { Assert.Fail("Promise resolved, but should not have."); }) .Catch(e => { e.Message.ShouldBe(message); }); }
public async Task ThenReturnsTaskThatFails() { var message = "Task failed, but that's what we wanted."; var ex = new InternalTestFailureException(message); var testPromise = SharpPromise.Promise.Resolve() .Then(() => { return(Task.FromException(ex)); }); await testPromise.Then(() => { Assert.Fail("Promise resolved, but should not have."); }) .Catch(e => { e.Message.ShouldBe(message); }); }
public void FileWatcher_DataSourceAvailableEventHandlerThrowsException_ErrorEventIsFired() { var errorEventWasFired = false; var exception = new InternalTestFailureException(); var fileDataSourceFactory = MockRepository.GenerateMock <IFileDataSourceFactory>(); var fileWatcher = new MockFileWatcher(fileDataSourceFactory, FileWatcherTests.TestFilesDirectory); fileWatcher.ShouldIgnoreExistingFiles = false; fileDataSourceFactory.Expect(x => x.Create( Arg <string> .Is.Equal(this.FilePath))) .Return(new FileDataSource(dataReader: null, filePath: this.FilePath)) .Repeat.Once(); using (var waitSignal = new ManualResetEventSlim()) { fileWatcher.DataSourceAvailable += (sender, e) => throw exception; fileWatcher.Error += (sender, e) => { errorEventWasFired = e.Exception.Equals(exception); waitSignal.Set(); }; fileWatcher.Start(); File.WriteAllText(this.FilePath, String.Empty); fileWatcher.FindNewFilesPublic(); waitSignal.Wait(TimeSpan.FromSeconds(1)); fileWatcher.Stop(); fileDataSourceFactory.VerifyAllExpectations(); Assert.IsTrue(errorEventWasFired); } }