Esempio n. 1
0
        public void TestThatImportTranslationUpdatesValueOnTranslationWhenTranslationForTranslationInfoDoesExists()
        {
            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>();

            var translationInfoIdentifier = Guid.NewGuid();
            var translationInfoMock       = MockRepository.GenerateMock <ITranslationInfo>();

            translationInfoMock.Stub(m => m.Identifier)
            .Return(translationInfoIdentifier)
            .Repeat.Any();

            var translationIdentifier  = Guid.NewGuid();
            var domainObjectIdentifier = Guid.NewGuid();
            var translationMock        = MockRepository.GenerateMock <ITranslation>();

            translationMock.Stub(m => m.Identifier)
            .Return(translationIdentifier)
            .Repeat.Any();
            translationMock.Stub(m => m.TranslationOfIdentifier)
            .Return(domainObjectIdentifier)
            .Repeat.Any();
            translationMock.Stub(m => m.TranslationInfo)
            .Return(translationInfoMock)
            .Repeat.Any();

            var domainObjectMock = MockRepository.GenerateMock <ITranslatable>();

            domainObjectMock.Stub(m => m.Identifier)
            .Return(domainObjectIdentifier)
            .Repeat.Any();
            domainObjectMock.Stub(m => m.Translations)
            .Return(new List <ITranslation> {
                translationMock
            })
            .Repeat.Any();

            var logicExecutorMock = MockRepository.GenerateMock <ILogicExecutor>();

            logicExecutorMock.Stub(m => m.TranslationModify(Arg <ITranslation> .Is.NotNull))
            .Return(translationIdentifier)
            .Repeat.Any();

            var translationValue = fixture.Create <string>();

            var commandHandler = new MyFoodWasteSystemDataCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            commandHandler.ImportTranslation(domainObjectMock, translationInfoMock, translationValue, logicExecutorMock);

            translationMock.AssertWasCalled(m => m.Value = Arg <string> .Is.Equal(translationValue));
        }
Esempio n. 2
0
        public void TestThatImportTranslationReturnsInsertedTranslationWhenTranslationForTranslationInfoDoesNotExists()
        {
            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>();

            var translationInfoIdentifier = Guid.NewGuid();
            var translationInfoMock       = MockRepository.GenerateMock <ITranslationInfo>();

            translationInfoMock.Stub(m => m.Identifier)
            .Return(translationInfoIdentifier)
            .Repeat.Any();

            var translationIdentifier = Guid.NewGuid();
            var translationValue      = fixture.Create <string>();

            var domainObjectIdentifier = Guid.NewGuid();
            var domainObjectMock       = MockRepository.GenerateMock <ITranslatable>();

            domainObjectMock.Stub(m => m.Identifier)
            .Return(domainObjectIdentifier)
            .Repeat.Any();
            domainObjectMock.Stub(m => m.Translations)
            .Return(new List <ITranslation>(0))
            .Repeat.Any();

            var logicExecutorMock = MockRepository.GenerateMock <ILogicExecutor>();

            logicExecutorMock.Stub(m => m.TranslationAdd(Arg <ITranslation> .Is.NotNull))
            .Return(translationIdentifier)
            .Repeat.Any();

            var commandHandler = new MyFoodWasteSystemDataCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            var translation = commandHandler.ImportTranslation(domainObjectMock, translationInfoMock, translationValue, logicExecutorMock);

            Assert.That(translation, Is.Not.Null);
            Assert.That(translation.Identifier, Is.Not.Null);
            Assert.That(translation.Identifier.HasValue, Is.True);
            // ReSharper disable PossibleInvalidOperationException
            Assert.That(translation.Identifier.Value, Is.EqualTo(translationIdentifier));
            // ReSharper restore PossibleInvalidOperationException
            Assert.That(translation.TranslationOfIdentifier, Is.EqualTo(domainObjectIdentifier));
            Assert.That(translation.TranslationInfo, Is.Not.Null);
            Assert.That(translation.TranslationInfo, Is.EqualTo(translationInfoMock));
            Assert.That(translation.Value, Is.Not.Null);
            Assert.That(translation.Value, Is.Not.Empty);
            Assert.That(translation.Value, Is.EqualTo(translationValue));
        }
Esempio n. 3
0
        public void TestThatImportTranslationCallsTranslationAddOnLogicExecutorWhenTranslationForTranslationInfoDoesNotExists()
        {
            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>();

            var translationInfoIdentifier = Guid.NewGuid();
            var translationInfoMock       = MockRepository.GenerateMock <ITranslationInfo>();

            translationInfoMock.Stub(m => m.Identifier)
            .Return(translationInfoIdentifier)
            .Repeat.Any();

            var domainObjectIdentifier = Guid.NewGuid();
            var domainObjectMock       = MockRepository.GenerateMock <ITranslatable>();

            domainObjectMock.Stub(m => m.Identifier)
            .Return(domainObjectIdentifier)
            .Repeat.Any();
            domainObjectMock.Stub(m => m.Translations)
            .Return(new List <ITranslation>(0))
            .Repeat.Any();

            var translationValue  = fixture.Create <string>();
            var logicExecutorMock = MockRepository.GenerateMock <ILogicExecutor>();

            logicExecutorMock.Stub(m => m.TranslationAdd(Arg <ITranslation> .Is.NotNull))
            .WhenCalled(e =>
            {
                var translation = (ITranslation)e.Arguments.ElementAt(0);
                Assert.That(translation, Is.Not.Null);
                Assert.That(translation.Identifier, Is.Null);
                Assert.That(translation.Identifier.HasValue, Is.False);
                Assert.That(translation.TranslationOfIdentifier, Is.EqualTo(domainObjectIdentifier));
                Assert.That(translation.TranslationInfo, Is.Not.Null);
                Assert.That(translation.TranslationInfo, Is.EqualTo(translationInfoMock));
                Assert.That(translation.Value, Is.Not.Null);
                Assert.That(translation.Value, Is.Not.Empty);
                Assert.That(translation.Value, Is.EqualTo(translationValue));
            })
            .Return(Guid.NewGuid())
            .Repeat.Any();

            var commandHandler = new MyFoodWasteSystemDataCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            commandHandler.ImportTranslation(domainObjectMock, translationInfoMock, translationValue, logicExecutorMock);

            logicExecutorMock.AssertWasCalled(m => m.TranslationAdd(Arg <ITranslation> .Is.NotNull));
        }
Esempio n. 4
0
        public void TestThatImportTranslationThrowsArgumentNullExceptionWhentranslationValueIsInvalid(string invalidValue)
        {
            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 commandHandler = new MyFoodWasteSystemDataCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            var exception = Assert.Throws <ArgumentNullException>(() => commandHandler.ImportTranslation(MockRepository.GenerateMock <ITranslatable>(), MockRepository.GenerateMock <ITranslationInfo>(), invalidValue, MockRepository.GenerateMock <ILogicExecutor>()));

            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("translationValue"));
            Assert.That(exception.InnerException, Is.Null);
        }
Esempio n. 5
0
        public void TestThatImportTranslationThrowsArgumentNullExceptionWhenDomainObjectIsNull()
        {
            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>();

            var commandHandler = new MyFoodWasteSystemDataCommandHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, specificationMock, commonValidationsMock, exceptionBuilderMock);

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

            var exception = Assert.Throws <ArgumentNullException>(() => commandHandler.ImportTranslation(null, MockRepository.GenerateMock <ITranslationInfo>(), fixture.Create <string>(), MockRepository.GenerateMock <ILogicExecutor>()));

            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("domainObject"));
            Assert.That(exception.InnerException, Is.Null);
        }