public void TestThatExecuteCallsIsNotNullForForeignKeyOnCommonValidations()
        {
            var fixture = new Fixture();
            var commonValidationsMock = MockRepository.GenerateMock <ICommonValidations>();
            var exceptionBuilderMock  = MockRepository.GenerateMock <IExceptionBuilder>();

            var foodGroupMock = DomainObjectMockBuilder.BuildFoodGroupMock();
            // ReSharper disable PossibleInvalidOperationException
            var foreignKeyMock = DomainObjectMockBuilder.BuildForeignKeyMock(foodGroupMock.Identifier.Value, foodGroupMock.GetType());
            // ReSharper restore PossibleInvalidOperationException
            var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepositoryMock.Stub(m => m.Get <IForeignKey>(Arg <Guid> .Is.Anything))
            .Return(foreignKeyMock)
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.Update(Arg <IForeignKey> .Is.Anything))
            // ReSharper disable PossibleInvalidOperationException
            .Return(DomainObjectMockBuilder.BuildForeignKeyMock(foodGroupMock.Identifier.Value, foodGroupMock.GetType()))
            // ReSharper restore PossibleInvalidOperationException
            .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 foreignKeyModifyCommandHandler = new ForeignKeyModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            var foreignKeyModifyCommand = fixture.Build <ForeignKeyModifyCommand>()
                                          .With(m => m.ForeignKeyIdentifier, Guid.NewGuid())
                                          .With(m => m.ForeignKeyValue, fixture.Create <string>())
                                          .Create();

            foreignKeyModifyCommandHandler.Execute(foreignKeyModifyCommand);

            commonValidationsMock.AssertWasCalled(m => m.IsNotNull(Arg <IForeignKey> .Is.Equal(foreignKeyMock)));
        }
        public void TestThatExecuteThrowsArgumentNullExceptionIfForeignKeyModifyCommandIsNull()
        {
            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 foreignKeyModifyCommandHandler = new ForeignKeyModifyCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            var exception = Assert.Throws <ArgumentNullException>(() => foreignKeyModifyCommandHandler.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);
        }