public async Task RemoveAsync_ShouldCallInner_WhenEntityIsGiven(bool handlerReturnValue) { // Arrange var entity = new FakeEntity <int> { Id = 5 }; InvalidOperationException actualException = null; _mockInner .Setup(i => i.RemoveAsync(entity)) .Returns(TaskHelpers.CompletedTask); var subject = new AsyncCommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act await subject.RemoveAsync(entity).ConfigureAwait(false); // Assert actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void GetCountAsync_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse() { // Arrange var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.GetCountAsync()) .ThrowsAsync(expectedException); var subject = new AsyncQueryServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(false); }); // Act Func <Task> action = async() => await subject.GetCountAsync().ConfigureAwait(false); // Assert action.Should().Throw <InvalidOperationException>(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public void Commit_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse() { // Arrange var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.Commit()) .Throws(expectedException); var subject = new UnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(false); }); // Act Action action = () => subject.Commit(); // Assert action.Should().Throw <InvalidOperationException>(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public void GetCount_ShouldCallInner_AndReturnResult(bool handlerReturnValue) { // Arrange const long expectedResult = 123; InvalidOperationException actualException = null; _mockInner .Setup(i => i.GetCount()) .Returns(expectedResult); var subject = new RepositoryExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act var actualResult = subject.GetCount(); // Assert actualResult.Should().Be(expectedResult); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void FromValue_Wraps_Data_Conversion_Exception() { // arrange InvalidOperationException exceptionThrown = null; // act try { this.CreateConverter() .FromValue(new string('k', EntityIdentifier.MaxLength + 1)); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown .Should() .NotBeNull(); exceptionThrown .InnerException .Should() .BeOfType <ArgumentException>(); }
public async Task TryRemoveAsync_ShouldCallInner_AndReturnResult_WhenEntityIsGiven(bool handlerReturnValue) { // Arrange var entity = new FakeEntity <int> { Id = 5 }; var expectedResult = true; InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryRemoveAsync(entity)) .ReturnsAsync(expectedResult); var subject = new AsyncCommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act var actualResult = await subject.TryRemoveAsync(entity).ConfigureAwait(false); // Assert actualResult.Should().Be(expectedResult); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void ToValue_Wraps_Data_Conversion_Exception() { // arrange InvalidOperationException exceptionThrown = null; // act try { this.CreateConverter() .ToValue("definitely not a GUID", typeof(Guid)); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown .Should() .NotBeNull(); exceptionThrown .InnerException .Should() .BeOfType <FormatException>(); }
public void Add_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse() { // Arrange var entity = new FakeEntity <int> { Id = 5 }; var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.Add(entity)) .Throws(expectedException); var subject = new CommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(false); }); // Act Action action = () => subject.Add(entity); // Assert action.Should().Throw <InvalidOperationException>(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
private void ThrowsInvalidOperationExceptionWhenIdChanges( Action <FakeEntity, string> setId, Func <SafeMetadataProvider <FakeEntity>, Func <FakeEntity, EntityIdentifier> > getMethod) { // arrange SafeMetadataProvider <FakeEntity> safeMetadataProvider = this.CreateSafeMetadataProvider(); var entity = new FakeEntity() { SourceSystemEntityId = Guid.NewGuid().ToString("d"), DestinationSystemEntityId = Guid.NewGuid().ToString("d"), Label = Guid.NewGuid().ToString("d") }; Func <FakeEntity, EntityIdentifier> method = getMethod(safeMetadataProvider); InvalidOperationException exceptionThrown = null; // act method(entity); setId(entity, Guid.NewGuid().ToString("d")); try { method(entity); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown.Should().NotBeNull(); }
public void TryRemove_ShouldNotCatchException_WhenEntityIsGiven_AndInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue) { // Arrange var entity = new FakeEntity <int> { Id = 5 }; InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryRemove(entity)) .Throws(new Exception()); var subject = new CommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act Action action = () => subject.TryRemove(entity); // Assert action.Should().Throw <Exception>(); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void TryRemove_ShouldCallInner_AndReturnResult_WhenIdIsGiven(bool handlerReturnValue) { // Arrange const int id = 5; var expectedResult = true; InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryRemove(id)) .Returns(expectedResult); var subject = new CommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act var actualResult = subject.TryRemove(id); // Assert actualResult.Should().Be(expectedResult); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void TryRemove_ShouldInvokeHandler_AndReturnResult_WhenEntityIsGiven_AndInnerThrowsException_AndHandlerReturnsTrue() { // Arrange var entity = new FakeEntity <int> { Id = 5 }; var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryRemove(entity)) .Throws(expectedException); var subject = new CommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(true); }); // Act var actualResult = subject.TryRemove(entity); // Assert actualResult.Should().BeFalse(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public void Cenario_sem_sucesso(RepositorioFuncionarios repositorio, Funcionario funcionario, InvalidOperationException excecaoEsperada) { "Dado um repositorio" .Given(() => repositorio = _container.Create <RepositorioFuncionarios>()); "E um funcionário com NIF repetido" .And(() => funcionario = Funcionario.CriaVazio(new TipoFuncionario())); "E alguns mocks" .And(() => _container.GetMock <IVerificadorNif>() .Setup(v => v.NifDuplicado(It.IsAny <string>(), It.IsAny <int>())) .Returns(true)); "Quando gravamos o funcionário" .When(() => { try { repositorio.Grava(funcionario); } catch (InvalidOperationException ex) { excecaoEsperada = ex; } }); "Então obtemos uma exceção " .Then(() => excecaoEsperada.Should().NotBeNull()); "e serviço verificação é usado" .And(() => _container.GetMock <IVerificadorNif>().VerifyAll()); }
public async Task GetCountAsync_ShouldCallInner_AndReturnResult(bool handlerReturnValue) { // Arrange const long expectedResult = 123; InvalidOperationException actualException = null; _mockInner .Setup(i => i.GetCountAsync()) .ReturnsAsync(expectedResult); var subject = new AsyncQueryServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act var actualResult = await subject.GetCountAsync().ConfigureAwait(false); // Assert actualResult.Should().Be(expectedResult); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void GetCount_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse() { // Arrange var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.GetCount()) .Throws(expectedException); var subject = new RepositoryExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(false); }); // Act Action action = () => subject.GetCount(); // Assert action.Should().Throw <InvalidOperationException>(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public async Task TryUpdateAsync_ShouldInvokeHandler_AndReturnResult_WhenInnerThrowsException_AndHandlerReturnsTrue() { // Arrange var entity = new FakeEntity <int> { Id = 5 }; var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryUpdateAsync(entity)) .ThrowsAsync(expectedException); var subject = new AsyncCommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(true); }); // Act var actualResult = await subject.TryUpdateAsync(entity).ConfigureAwait(false); // Assert actualResult.Should().BeFalse(); actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public void TryUpdateAsync_ShouldNotCatchException_WhenInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue) { // Arrange var entity = new FakeEntity <int> { Id = 5 }; InvalidOperationException actualException = null; _mockInner .Setup(i => i.TryUpdateAsync(entity)) .ThrowsAsync(new Exception()); var subject = new AsyncCommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act Func <Task> action = async() => await subject.TryUpdateAsync(entity).ConfigureAwait(false); // Assert action.Should().Throw <Exception>(); actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void CreateScope_AlreadyExists() { // arrange string instanceId = Guid.NewGuid().ToString(); OrchestrationScope.CreateScope(instanceId, GetServiceProvider()); // act InvalidOperationException ex = Capture <InvalidOperationException>( () => OrchestrationScope.CreateScope(instanceId, GetServiceProvider())); // assert ex.Should().NotBeNull(); }
public void it_should_throw_when_not_initialized_and_trying_to_find_input_conveter() { InvalidOperationException exception = null; try { new DefaultConverterProvider().FindBestInputConverter(typeof(string), _request.Object); } catch (InvalidOperationException error) { exception = error; } exception.Should().NotBeNull(); }
public void it_should_throw_when_invalid_constructor_arguments_are_passed() { InvalidOperationException exception = null; try { ((UrsaConfigurationSection)ConfigurationManager.GetSection(UrsaConfigurationSection.ConfigurationSectionGroupName)) .GetProvider <IConverterProvider>(typeof(DefaultConverterProvider), typeof(object)); } catch (InvalidOperationException error) { exception = error; } exception.Should().NotBeNull(); }
public void FromValue_Throws_InvalidOperationException_If_Value_Type_Not_Supported() { // arrange InvalidOperationException exceptionThrown = null; // act try { this.CreateConverter() .FromValue(3.141592684d); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown.Should().NotBeNull(); }
public void ToValue_Throws_InvalidOperationException_If_Value_Type_Not_Supported() { // arrange InvalidOperationException exceptionThrown = null; // act try { this.CreateConverter() .ToValue("2.718d", typeof(double)); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown.Should().NotBeNull(); }
public async Task FileSystem_VerifyFileSystemResetOnLock() { using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem1 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var lockMessage = Guid.NewGuid().ToString(); await InitCommand.RunAsync(settings, fileSystem1, log); // Verify that files work normally var testFile = fileSystem1.Get("test.json"); await testFile.GetJsonOrNull(log, CancellationToken.None); var testFile2 = fileSystem1.Get("test2.json"); fileSystem1.Files.Count.Should().BeGreaterThan(1); // Lock the feed to reset it var lockObj1 = await SourceUtility.VerifyInitAndLock(settings, fileSystem1, lockMessage, log, CancellationToken.None); lockObj1.IsLocked.Should().BeTrue(); // 1 file should be found since it loads the index fileSystem1.Files.Count.Should().Be(1); InvalidOperationException failureEx = null; try { // Verify the old file no longer works await testFile.GetJsonOrNull(log, CancellationToken.None); await testFile2.GetJsonOrNull(log, CancellationToken.None); } catch (InvalidOperationException ex) { failureEx = ex; } failureEx.Should().NotBeNull(); } }
public void Commit_ShouldCallInner(bool handlerReturnValue) { // Arrange InvalidOperationException actualException = null; _mockInner.Setup(i => i.Commit()); var subject = new UnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act subject.Commit(); // Assert actualException.Should().BeNull(); _mockInner.VerifyAll(); }
public void ReceiveOrSendImmediately_GivenPreparationIsNotImmediate_JustThrowsTheException() { // Arrange preparationInlet.Setup(p => p.SendImmediately(It.IsAny <string>())).Throws <InvalidOperationException>(); // Act InvalidOperationException exception = null; try { valve.ReceiveOrSendImmediately("Not gonna make it..."); } catch (InvalidOperationException e) { exception = e; } // Assert preparationInlet.Verify(p => p.SendImmediately(It.IsAny <string>()), Times.Once); resultOutlet.Verify(r => r.ReceiveImmediately(), Times.Never); exception.Should().NotBeNull(); }
public async Task CommitAsync_ShouldCallInner(bool handlerReturnValue) { // Arrange InvalidOperationException actualException = null; _mockInner .Setup(i => i.CommitAsync()) .Returns(TaskHelpers.CompletedTask); var subject = new AsyncUnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act await subject.CommitAsync().ConfigureAwait(false); // Assert actualException.Should().BeNull(); _mockInner.VerifyAll(); }
private void ThrowsInvalidOperationException <TReturn>( FakeEntity entity, Func <SafeMetadataProvider <FakeEntity>, Func <FakeEntity, TReturn> > getMethod) { // arrange SafeMetadataProvider <FakeEntity> safeMetadataProvider = this.CreateSafeMetadataProvider(); InvalidOperationException exceptionThrown = null; // act try { getMethod(safeMetadataProvider)(entity); } catch (InvalidOperationException exception) { exceptionThrown = exception; } // assert exceptionThrown.Should().NotBeNull(); }
public async Task CommitAsync_ShouldInvokeHandler_WhenInnerThrowsException_AndHandlerReturnsTrue() { // Arrange var expectedException = new InvalidOperationException(); InvalidOperationException actualException = null; _mockInner .Setup(i => i.CommitAsync()) .ThrowsAsync(expectedException); var subject = new AsyncUnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(true); }); // Act await subject.CommitAsync().ConfigureAwait(false); // Assert actualException.Should().BeSameAs(expectedException); _mockInner.VerifyAll(); }
public void ReceiveOrSendImmediately_GivenReceivingAResultIsNotImmediate_FlushesTheMessageToBeSentAndThrowsTheException() { // Arrange resultOutlet.Setup(r => r.ReceiveImmediately()).Throws <InvalidOperationException>(); // Act InvalidOperationException exception = null; try { valve.ReceiveOrSendImmediately("Not gonna make it..."); } catch (InvalidOperationException e) { exception = e; } // Assert preparationInlet.Verify(p => p.SendImmediately(It.IsAny <string>()), Times.Once); resultOutlet.Verify(r => r.ReceiveImmediately(), Times.Once); flushOutlet.Verify(f => f.ReceiveImmediately(), Times.Once); exception.Should().NotBeNull(); }
public void Remove_ShouldCallInner_WhenEntityIsGiven(bool handlerReturnValue) { // Arrange var entity = new FakeEntity <int> { Id = 5 }; InvalidOperationException actualException = null; _mockInner.Setup(i => i.Remove(entity)); var subject = new CommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex => { actualException = ex; return(handlerReturnValue); }); // Act subject.Remove(entity); // Assert actualException.Should().BeNull(); _mockInner.VerifyAll(); }