public void TestThatConstructorInitializeTranslatableBase()
        {
            var translatable = new MyTranslatable();

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.False);
            Assert.That(translatable.Translation, Is.Null);
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Empty);
        }
        public void TestThatTranslationAddThrowsArgumentNullExceptionWhenTranslationIsNull()
        {
            var translatable = new MyTranslatable();

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

            var exception = Assert.Throws <ArgumentNullException>(() => translatable.TranslationAdd(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("translation"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatTranslateSetsTranslationToNullWhenIdentifierOnTranslatableBaseIsNull()
        {
            var translatable = new MyTranslatable();

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Null);
            Assert.That(translatable.Identifier.HasValue, Is.False);

            translatable.Initialize(Guid.NewGuid());
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);

            translatable.Translate(CultureInfo.CurrentUICulture);
            Assert.That(translatable.Translation, Is.Null);
        }
        public void TestThatTranslateSetsTranslationToNullWhenTranslationCollectionIsNull()
        {
            var translatable = new MyTranslatable
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.True);

            translatable.SetToNull();
            Assert.That(translatable.Translations, Is.Null);

            translatable.Translate(CultureInfo.CurrentUICulture);
            Assert.That(translatable.Translation, Is.Null);
        }
        public void TestThatTranslateSetsTranslationToNullWhenTranslationCollectionDoesNotContainIdentifierFromTranslatableBase()
        {
            var translatable = new MyTranslatable
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.True);

            translatable.Initialize(Guid.NewGuid());
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);

            translatable.Translate(CultureInfo.CurrentUICulture);
            Assert.That(translatable.Translation, Is.Null);
        }
        public void TestThatTranslationAddAddsTranslation()
        {
            var identifier   = Guid.NewGuid();
            var translatable = new MyTranslatable
            {
                Identifier = identifier
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Empty);

            var translationMock = DomainObjectMockBuilder.BuildTranslationMock(identifier);

            translatable.TranslationAdd(translationMock);
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);
            Assert.That(translatable.Translations.Contains(translationMock), Is.True);
        }
        public void TestThatTranslateCallsOnTranslation()
        {
            var translatable = new MyTranslatable
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.True);

            // ReSharper disable PossibleInvalidOperationException
            translatable.Initialize(translatable.Identifier.Value);
            // ReSharper restore PossibleInvalidOperationException
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);

            Assert.That(translatable.OnTranslateWasCalled, Is.False);
            translatable.Translate(translatable.Translations.First().TranslationInfo.CultureInfo);
            Assert.That(translatable.OnTranslateWasCalled, Is.True);
        }
        public void TestThatTranslateSetsTranslationWhenTranslationCollectionDoesNotContainsCultureTranslation(string notTranslatedCultureName)
        {
            var notTranslatedCulture = new CultureInfo(notTranslatedCultureName);

            var translatable = new MyTranslatable
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.True);

            // ReSharper disable PossibleInvalidOperationException
            translatable.Initialize(translatable.Identifier.Value);
            // ReSharper restore PossibleInvalidOperationException
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);

            translatable.Translate(notTranslatedCulture);
            Assert.That(translatable.Translation, Is.Not.Null);
        }
        public void TestThatTranslateSetsTranslationWhenTranslationCollectionContainsCultureTranslation()
        {
            var translatable = new MyTranslatable
            {
                Identifier = Guid.NewGuid()
            };

            Assert.That(translatable, Is.Not.Null);
            Assert.That(translatable.Identifier, Is.Not.Null);
            Assert.That(translatable.Identifier.HasValue, Is.True);

            // ReSharper disable PossibleInvalidOperationException
            translatable.Initialize(translatable.Identifier.Value);
            // ReSharper restore PossibleInvalidOperationException
            Assert.That(translatable.Translations, Is.Not.Null);
            Assert.That(translatable.Translations, Is.Not.Empty);

            foreach (var translation in translatable.Translations)
            {
                translatable.Translate(translation.TranslationInfo.CultureInfo);
                Assert.That(translatable.Translation, Is.Not.Null);
                Assert.That(translatable.Translation, Is.EqualTo(translation));
            }
        }