public void ConvertingViaBaseDtoSucceeds()
        {
            // Arrange
            const string name        = "arbitrary-name";
            const string description = "optional-description";
            const string size        = "40";

            var StringPropertyWithAnnotationAnnotationValue      = "arbitrary-string";
            var LongPropertyWithAnnotationAnnotationValue        = 42L;
            var StringPropertyWithAnnotationAnnotationType1Value = "arbitrary-string-1";
            var LongPropertyWithAnnotationAnnotationType1Value   = 1L;
            var StringPropertyWithAnnotationAnnotationType2Value = "arbitrary-string-2";
            var LongPropertyWithAnnotationAnnotationType2Value   = 2L;

            var dictionaryParameters = new DictionaryParameters()
            {
                { STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION, StringPropertyWithAnnotationAnnotationValue }
                ,
                { LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION, LongPropertyWithAnnotationAnnotationValue }
                ,
                { STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION_TYPE1, StringPropertyWithAnnotationAnnotationType1Value }
                ,
                { LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION_TYPE1, LongPropertyWithAnnotationAnnotationType1Value }
                ,
                { STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION_TYPE2, StringPropertyWithAnnotationAnnotationType2Value }
                ,
                { LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION_TYPE2, LongPropertyWithAnnotationAnnotationType2Value }
                ,
                { "arbitrary-other-key", "arbitrary-value" }
            };

            // Act
            var result = EnvironmentVariableConverter.Convert <ClassWithEnvironmentVariableAttributesAsTBase>(dictionaryParameters, null);

            // Assert

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);

            foreach (var dto in result)
            {
                Assert.IsTrue(dto.IsValid(), dto.GetType().FullName);
            }

            Assert.IsTrue(result[0] is ClassWithEnvironmentVariableAttributesAsDerivedType1 || result[1] is ClassWithEnvironmentVariableAttributesAsDerivedType1);
            Assert.IsTrue(result[0] is ClassWithEnvironmentVariableAttributesAsDerivedType2 || result[1] is ClassWithEnvironmentVariableAttributesAsDerivedType2);

            var type1 = result[0] is ClassWithEnvironmentVariableAttributesAsDerivedType1 ? result[0] : result[1];

            Assert.IsNotNull(type1);
            var type2 = result[0] is ClassWithEnvironmentVariableAttributesAsDerivedType2 ? result[0] : result[1];

            Assert.IsNotNull(type2);

            Assert.AreEqual(StringPropertyWithAnnotationAnnotationType1Value, type1.StringPropertyWithAnnotation);
            Assert.AreEqual(LongPropertyWithAnnotationAnnotationType1Value, type1.LongPropertyWithAnnotation);

            Assert.AreEqual(StringPropertyWithAnnotationAnnotationType2Value, type2.StringPropertyWithAnnotation);
            Assert.AreEqual(LongPropertyWithAnnotationAnnotationType2Value, type2.LongPropertyWithAnnotation);
        }
        public void ConvertToDictionaryParametersSucceeds()
        {
            // Arrange
            var sut = new ClassWithEnvironmentVariableAttributes()
            {
                StringPropertyWithAnnotation    = "arbitrary-StringPropertyWithAnnotation",
                LongPropertyWithAnnotation      = 42L,
                StringPropertyWithoutAnnotation = "arbitrary-StringPropertyWithoutAnnotation",
                LongPropertyWithoutAnnotation   = 8L
            };

            // Act
            var result = EnvironmentVariableConverter.Convert(sut);

            // Assert
            Assert.IsNotNull(result);
            if (!result.IsValid())
            {
                var validationResults = result.GetValidationResults();
                foreach (var validationResult in validationResults)
                {
                    System.Diagnostics.Debug.WriteLine(validationResult.ErrorMessage);
                }
            }
            Assert.IsTrue(result.IsValid());

            Assert.AreEqual(2, result.Keys.Count);

            Assert.IsTrue(result.ContainsKey(STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION));
            Assert.AreEqual("arbitrary-StringPropertyWithAnnotation", result[STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION]);
            Assert.IsTrue(result.ContainsKey(LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION));
            Assert.AreEqual(42L, result[LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION]);
        }
        public void ConvertFromDictionaryParametersSucceeds()
        {
            // Arrange
            var extraEnvironmentVariableName = "biz.dfch.CS.Commons.EnvironmentVariable.ThatIsNotDefinedInTheTargetDataTransferObjectAndWillBeIgnoredOnConversion";

            var parameters = new DictionaryParameters
            {
                { STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION, "arbitrary-string-value" }
                ,
                { LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION, 42L }
                ,
                { extraEnvironmentVariableName, "some-other-arbitrary-string-value" }
            };

            // Act
            var result = EnvironmentVariableConverter.Convert <ClassWithEnvironmentVariableAttributes>(parameters);

            // Assert
            Assert.IsNotNull(result);
            if (!result.IsValid())
            {
                var validationResults = result.GetValidationResults();
                foreach (var validationResult in validationResults)
                {
                    System.Diagnostics.Debug.WriteLine(validationResult.ErrorMessage);
                }
            }
            Assert.IsTrue(result.IsValid());

            Assert.AreEqual("arbitrary-string-value", result.StringPropertyWithAnnotation);
            Assert.AreEqual(42L, result.LongPropertyWithAnnotation);
            Assert.IsNull(result.StringPropertyWithoutAnnotation);
            Assert.AreEqual(0, result.LongPropertyWithoutAnnotation);
        }
        public void ConvertEnvironmentVariableBaseDtoWithNullEnvironmentVariableBaseDtoThrowsContractFailure2()
        {
            // Arrange
            var dictionaryParameters = default(DictionaryParameters);
            var sut = new EnvironmentVariableConverter();

            // Act
            // ReSharper disable once ExpressionIsAlwaysNull
            var result = EnvironmentVariableConverter.Convert <ClassWithEnvironmentVariableAttributes>(dictionaryParameters);

            // Assert
            // N/A
        }
        public void ConvertEnvironmentVariableBaseDtoWithNullEnvironmentVariableBaseDtoThrowsContractFailure()
        {
            // Arrange
            var environmentVariableBaseDto = default(EnvironmentVariableBaseDto);
            var sut = new EnvironmentVariableConverter();

            // Act
            // ReSharper disable once ExpressionIsAlwaysNull
            var result = EnvironmentVariableConverter.Convert(environmentVariableBaseDto);

            // Assert
            // N/A
        }
        public void ConverterTestWithStringTypesCanBeConvertedAndSucceeds()
        {
            var sut = new DictionaryParameters()
            {
                { EnvironmentVariableClass.BAG_NAME_INT, "42" }
                ,
                { EnvironmentVariableClass.BAG_NAME_LONG, (int.MaxValue + 1L).ToString() }
                ,
                { EnvironmentVariableClass.BAG_NAME_DOUBLE, 4.2d.ToString() }
            };

            var result = EnvironmentVariableConverter.Convert <EnvironmentVariableClass>(sut);

            Assert.IsTrue(result.IsValid());
        }
        public void ConverterTestWithMatchingTypesSucceeds()
        {
            var sut = new DictionaryParameters()
            {
                { EnvironmentVariableClass.BAG_NAME_INT, 42 }
                ,
                { EnvironmentVariableClass.BAG_NAME_LONG, int.MaxValue + 1L }
                ,
                { EnvironmentVariableClass.BAG_NAME_DOUBLE, 4.2d }
            };

            var result = EnvironmentVariableConverter.Convert <EnvironmentVariableClass>(sut);

            Assert.IsTrue(result.IsValid());
        }
        public void ConvertingEnvironmentVariableBaseDtoToDictionaryParametersSucceeds()
        {
            var sut = new MyEnvironmentVariableBaseDto()
            {
                StringProperty = MyEnvironmentVariableBaseDto.NAME_PROPERTY_VALUE
                ,
                LongProperty = MyEnvironmentVariableBaseDto.VALUE_PROPERTY_VALUE
            };

            Assert.IsTrue(sut.IsValid());

            var parameters = EnvironmentVariableConverter.Convert(sut);

            Assert.IsNotNull(parameters);
            Assert.AreEqual(2, parameters.Count);
            Assert.IsTrue(parameters.ContainsKey(MyEnvironmentVariableBaseDto.NAME_PROPERTY_NAME));
            Assert.AreEqual(MyEnvironmentVariableBaseDto.NAME_PROPERTY_VALUE, parameters[MyEnvironmentVariableBaseDto.NAME_PROPERTY_NAME]);
            Assert.IsTrue(parameters.ContainsKey(MyEnvironmentVariableBaseDto.VALUE_PROPERTY_NAME));
            Assert.AreEqual(MyEnvironmentVariableBaseDto.VALUE_PROPERTY_VALUE, parameters[MyEnvironmentVariableBaseDto.VALUE_PROPERTY_NAME]);
        }
        public void ConvertFromDictionaryParametersWithTypeConversionSucceeds()
        {
            // Arrange
            var parameters = new DictionaryParameters
            {
                { STRING_PROPERTY_WITH_ANNOTATION_ANNOTATION, "arbitrary-string-value" }
                ,
                { LONG_PROPERTY_WITH_ANNOTATION_ANNOTATION, 42L.ToString() }
            };

            // Act
            var result = EnvironmentVariableConverter.Convert <ClassWithEnvironmentVariableAttributes>(parameters);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsValid());

            Assert.AreEqual("arbitrary-string-value", result.StringPropertyWithAnnotation);
            Assert.AreEqual(42L, result.LongPropertyWithAnnotation);
        }