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)); }
public void TestThatConstructorInitializeTranslationModifyCommandHandler() { 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>(); var translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(translationModifyCommandHandler, Is.Not.Null); }
public void TestThatExecuteCallsIsNotNullForTranslationOnCommonValidations() { var fixture = new Fixture(); var commonValidationsMock = MockRepository.GenerateMock <ICommonValidations>(); var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>(); var translationMock = DomainObjectMockBuilder.BuildTranslationMock(Guid.NewGuid()); var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>(); systemDataRepositoryMock.Stub(m => m.Get <ITranslation>(Arg <Guid> .Is.Anything)) .Return(translationMock) .Repeat.Any(); systemDataRepositoryMock.Stub(m => m.Update(Arg <ITranslation> .Is.Anything)) .Return(DomainObjectMockBuilder.BuildTranslationMock(Guid.NewGuid())) .Repeat.Any(); var specificationMock = MockRepository.GenerateMock <ISpecification>(); specificationMock.Stub(m => m.IsSatisfiedBy(Arg <Func <bool> > .Is.NotNull, Arg <Exception> .Is.Anything)) .WhenCalled(e => { var func = (Func <bool>)e.Arguments.ElementAt(0); func.Invoke(); }) .Return(specificationMock) .Repeat.Any(); var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>(); foodWasteObjectMapperMock.Stub(m => m.Map <IIdentifiable, ServiceReceiptResponse>(Arg <IIdentifiable> .Is.Anything, Arg <CultureInfo> .Is.Anything)) .Return(fixture.Create <ServiceReceiptResponse>()) .Repeat.Any(); var translationModifyCommand = fixture.Build <TranslationModifyCommand>() .With(m => m.TranslationIdentifier, Guid.NewGuid()) .With(m => m.TranslationValue, fixture.Create <string>()) .Create(); var translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(translationModifyCommandHandler, Is.Not.Null); translationModifyCommandHandler.Execute(translationModifyCommand); commonValidationsMock.AssertWasCalled(m => m.IsNotNull(Arg <ITranslation> .Is.Equal(translationMock))); }
public void TestThatExecuteReturnsServiceReceiptFromMapOnFoodWasteObjectMapper() { var fixture = new Fixture(); var commonValidationsMock = MockRepository.GenerateMock <ICommonValidations>(); var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>(); var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>(); systemDataRepositoryMock.Stub(m => m.Get <ITranslation>(Arg <Guid> .Is.Anything)) .Return(DomainObjectMockBuilder.BuildTranslationMock(Guid.NewGuid())) .Repeat.Any(); systemDataRepositoryMock.Stub(m => m.Update(Arg <ITranslation> .Is.Anything)) .Return(DomainObjectMockBuilder.BuildTranslationMock(Guid.NewGuid())) .Repeat.Any(); var specificationMock = MockRepository.GenerateMock <ISpecification>(); specificationMock.Stub(m => m.IsSatisfiedBy(Arg <Func <bool> > .Is.NotNull, Arg <Exception> .Is.Anything)) .Return(specificationMock) .Repeat.Any(); var serviceReceipt = fixture.Build <ServiceReceiptResponse>() .With(m => m.Identifier, Guid.NewGuid()) .With(m => m.EventDate, DateTime.Now) .Create(); var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>(); foodWasteObjectMapperMock.Stub(m => m.Map <IIdentifiable, ServiceReceiptResponse>(Arg <IIdentifiable> .Is.Anything, Arg <CultureInfo> .Is.Anything)) .Return(serviceReceipt) .Repeat.Any(); var translationModifyCommand = fixture.Build <TranslationModifyCommand>() .With(m => m.TranslationIdentifier, Guid.NewGuid()) .With(m => m.TranslationValue, fixture.Create <string>()) .Create(); var translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(translationModifyCommandHandler, Is.Not.Null); var result = translationModifyCommandHandler.Execute(translationModifyCommand); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(serviceReceipt)); }
public void TestThatExecuteThrowsArgumentNullExceptionIfTranslationModifyCommandIsNull() { 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>(); var translationModifyCommandHandler = new TranslationModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock); Assert.That(translationModifyCommandHandler, Is.Not.Null); var exception = Assert.Throws <ArgumentNullException>(() => translationModifyCommandHandler.Execute(null)); Assert.That(exception, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Null); Assert.That(exception.ParamName, Is.Not.Empty); Assert.That(exception.ParamName, Is.EqualTo("command")); Assert.That(exception.InnerException, Is.Null); }
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)); }