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); }