Exemplo n.º 1
0
        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(TranslationModifyCommandHandler).Name));
            })
            .Return(fixture.Create <Exception>())
            .Repeat.Any();

            var translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

            Assert.That(translationModifyCommandHandler, Is.Not.Null);

            var exception = fixture.Create <Exception>();

            Assert.Throws <Exception>(() => translationModifyCommandHandler.HandleException(fixture.Create <TranslationModifyCommand>(), exception));

            exceptionBuilderMock.AssertWasCalled(m => m.Build(Arg <Exception> .Is.Equal(exception), Arg <MethodBase> .Is.NotNull));
        }
Exemplo n.º 2
0
        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 translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

            Assert.That(translationModifyCommandHandler, Is.Not.Null);

            var exception = Assert.Throws <Exception>(() => translationModifyCommandHandler.HandleException(fixture.Create <TranslationModifyCommand>(), fixture.Create <Exception>()));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception, Is.EqualTo(exceptionToThrow));
        }