public void TestThatHandleExceptionCallsBuildOnExceptionBuilder() { var fixture = new Fixture(); var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>(); var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>(); var specificationMock = MockRepository.GenerateMock <ISpecification>(); var commonValidationsMock = MockRepository.GenerateMock <ICommonValidations>(); var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>(); exceptionBuilderMock.Stub(m => m.Build(Arg <Exception> .Is.Anything, Arg <MethodBase> .Is.NotNull)) .WhenCalled(e => { var methodBase = (MethodBase)e.Arguments.ElementAt(1); Assert.That(methodBase, Is.Not.Null); Assert.That(methodBase.ReflectedType.Name, Is.EqualTo(typeof(ForeignKeyAddCommandHandler).Name)); }) .Return(fixture.Create <Exception>()) .Repeat.Any(); var foreignKeyAddCommandHandler = new ForeignKeyAddCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(foreignKeyAddCommandHandler, Is.Not.Null); var exception = fixture.Create <Exception>(); Assert.Throws <Exception>(() => foreignKeyAddCommandHandler.HandleException(fixture.Create <ForeignKeyAddCommand>(), exception)); exceptionBuilderMock.AssertWasCalled(m => m.Build(Arg <Exception> .Is.Equal(exception), Arg <MethodBase> .Is.NotNull)); }
public void TestThatHandleExceptionThrowsCreatedExceptionFromExceptionBuilder() { var fixture = new Fixture(); var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>(); var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>(); var specificationMock = MockRepository.GenerateMock <ISpecification>(); var commonValidationsMock = MockRepository.GenerateMock <ICommonValidations>(); var exceptionToThrow = fixture.Create <Exception>(); var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>(); exceptionBuilderMock.Stub(m => m.Build(Arg <Exception> .Is.Anything, Arg <MethodBase> .Is.Anything)) .Return(exceptionToThrow) .Repeat.Any(); var foreignKeyAddCommandHandler = new ForeignKeyAddCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(foreignKeyAddCommandHandler, Is.Not.Null); var exception = Assert.Throws <Exception>(() => foreignKeyAddCommandHandler.HandleException(fixture.Create <ForeignKeyAddCommand>(), fixture.Create <Exception>())); Assert.That(exception, Is.Not.Null); Assert.That(exception, Is.EqualTo(exceptionToThrow)); }