示例#1
0
        public void Test_MapWithFake_GivenHasPropFieldNameAttribute_ShouldMapWithExpectedFieldName()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();
            var expectedDatabaseFieldName = GetRandomString();

            wrapper.Stub(wrapper1 => wrapper1.HasAttribute <AutoMapFieldNameAttribute>()).Return(true);
//            if(false)
//            {
            wrapper.Stub(propertyWrapper => propertyWrapper.GetAttribute <AutoMapFieldNameAttribute>()).Return(
                new AutoMapFieldNameAttribute(expectedDatabaseFieldName));
            //}
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(wrapper.GetAttribute <AutoMapFieldNameAttribute>());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var databaseFieldName = propDef.DatabaseFieldName;

            Assert.AreEqual(expectedDatabaseFieldName, databaseFieldName);
        }
示例#2
0
        public void MapProperty_WhenHasKeepValuePrivateAttribute_ShouldSetKeepValuePrivateTrue()
        {
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBOWProps);
            var propertyInfo       = classType.GetProperty("PublicWithKeepValuePrivateAtt");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsTrue(propDef.KeepValuePrivate);
        }
示例#3
0
        public void Test_Map_WhenIsStatic_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBoWithStaticProperty);
            var propertyInfo       = classType.GetProperty("PublicStringProp");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsFalse(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyInfo.ToPropertyWrapper().IsStatic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
示例#4
0
        public void Test_MapWithFake_WhenNotHasReadWriteAttribute_ShouldReturnPropDefWithReadWrite()
        {
            //---------------Set up test pack-------------------
            var wrapper            = GetMockPropWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapReadWriteRuleAttribute>());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var defaultValueString = propDef.DefaultValueString;

            Assert.IsNull(defaultValueString);
        }
示例#5
0
        public void Test_Map_WhenHasIgnoreAttribute_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBOWProps);
            var propertyInfo       = classType.GetProperty("PublicWithIgnoreAtt");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.AreEqual(1, propertyInfo.GetCustomAttributes(true).Length);
            Assert.IsTrue(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
示例#6
0
        public void Test_Map_WhenTypeNotSystem_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBOWProps);
            var propertyInfo       = classType.GetProperty("ClassDef");
            var propTypeName       = propertyInfo.PropertyType.FullName;
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            propTypeName.ShouldNotStartWith("System.");
            Assert.IsFalse(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
            Assert.IsFalse(propertyInfo.PropertyType.CanMapToProp());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
示例#7
0
        public void Test_MapWithFake_WhenDateTimeStringPropRuleAttribute_ShouldReturnPropDefWithDateTimePropRuleWithValues()
        {
            //---------------Set up test pack-------------------
            var          wrapper            = GetMockPropWrapper();
            var          propertyAutoMapper = new PropertyAutoMapper(wrapper);
            const string StartDate          = "Today";
            const string EndDate            = "Tomorrow";

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapDateTimePropRuleAttribute>());
            //---------------Execute Test ----------------------

            SetDateTimeStringPropRuleAttributeWithDefaultConstructor(wrapper, StartDate, EndDate);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(1, propDef.PropRules.Count);
        }
示例#8
0
        public void Test_MapWithFake_WhenStringLengthPropRuleAttribute_ShouldReturnPropDefWithStringLengthPropRuleDefault()
        {
            //---------------Set up test pack-------------------
            var wrapper            = GetMockPropWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapStringLengthPropRuleAttribute>());
            //---------------Execute Test ----------------------
            SetStringLengthPropRuleAttributeWithDefaultConstructor(wrapper);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var propMinValue = (int)propDef.PropRules[0].Parameters["minLength"];
            var propMaxValue = (int)propDef.PropRules[0].Parameters["maxLength"];

            Assert.AreEqual(0, propMinValue);
            Assert.AreEqual(255, propMaxValue);
        }
示例#9
0
        public void Test_MapWithFake_GivenNotHasPropFieldNameAttribute_ShouldMapWithPropertyName()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();

            wrapper.Stub(wrapper1 => wrapper1.HasAttribute <AutoMapFieldNameAttribute>()).Return(false);
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapFieldNameAttribute>());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var databaseFieldName = propDef.DatabaseFieldName;

            Assert.AreEqual(propDef.PropertyName, databaseFieldName);
        }
示例#10
0
        public void Test_MapWithFake_WhenNotHasDefaultAttribute_ShouldReturnPropDefWithDefaultNull()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();

            SetHasDefaultAttribute(wrapper, false, GetRandomString());
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsFalse(wrapper.HasDefaultAttribute);
            Assert.IsNull(wrapper.GetAttribute <AutoMapDefaultAttribute>());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var defaultValueString = propDef.DefaultValueString;

            Assert.IsNull(defaultValueString);
        }
示例#11
0
        public void Test_MapWithFake_WhenStringPatternMatchPropRuleAttribute_ShouldReturnPropDefWithStringPatternMatchPropRuleWithValue()
        {
            //---------------Set up test pack-------------------
            var          wrapper            = GetMockPropWrapper();
            var          propertyAutoMapper = new PropertyAutoMapper(wrapper);
            const string emailPatternMatch  = @"\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapStringPatternMatchPropRuleAttribute>());
            //---------------Execute Test ----------------------
            SetStringPatternMatchPropRuleAttributeWithDefaultConstructor(wrapper, emailPatternMatch);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(1, propDef.PropRules.Count);
            var actualPattern = (string)propDef.PropRules[0].Parameters["patternMatch"];

            StringAssert.AreEqualIgnoringCase(emailPatternMatch, actualPattern);
        }
示例#12
0
        public void Test_PrivateProp_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBoWithPrivateProps);
            var propertyInfo       = classType.GetProperty("PrivateStringProp", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper    = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsFalse(propertyWrapper.IsPublic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
示例#13
0
        public void Test_MapWithFake_WhenHasReadWriteAttribute_ShouldReturnPropDefWithAttribute()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();
            var expectedReadWriteRule = RandomValueGenerator.GetRandomEnum <PropReadWriteRule>();

            SetReadWriteAttribute(wrapper, expectedReadWriteRule);
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(wrapper.GetAttribute <AutoMapReadWriteRuleAttribute>());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var actualReadWriteRule = propDef.ReadWriteRule;

            Assert.IsNotNull(actualReadWriteRule);
            Assert.AreEqual(expectedReadWriteRule, actualReadWriteRule);
        }
示例#14
0
        public void Test_Map_WhenHasNoAutoIncrementingAttribute_ShouldNotMakePropertyAutoIncrementing()
        {
            //---------------Set up test pack-------------------
            var          classType          = typeof(FakeBOWithAutoIncrementingProp);
            const string propName           = "NonAutoIncrementingProp";
            var          propertyInfo       = classType.GetProperty(propName);
            var          propertyWrapper    = propertyInfo.ToPropertyWrapper();
            var          propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasAutoIncrementingAttribute);
            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.IsFalse(propDef.AutoIncrementing);
        }
示例#15
0
        public void Test_MapWithFake_WhenNotHasDisplayNameAttribute_ShouldReturnPropDefWithDefaultDisplayName()
        {
            //---------------Set up test pack-------------------
            var wrapper             = GetMockPropWrapper();
            var expectedDisplayName = GetRandomString();

            SetHasDisplayNameAttribute(wrapper, false, expectedDisplayName);
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsFalse(wrapper.HasDisplayNameAttribute);
            Assert.IsNull(wrapper.GetAttribute <AutoMapDisplayNameAttribute>());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var actualDisplayName = propDef.DisplayName;

            Assert.AreNotEqual(expectedDisplayName, actualDisplayName);
        }
示例#16
0
        public void Test_MapWithFake_WhenStringPatternMatchPropRuleAttribute_WhenMessageSet_ShouldReturnPropDefWithStringPatternMatchPropRuleWithMessage()
        {
            //---------------Set up test pack-------------------
            var          wrapper              = GetMockPropWrapper();
            var          propertyAutoMapper   = new PropertyAutoMapper(wrapper);
            const string fourDigitStringRegex = @"^\d{4}$";
            var          expectedMessage      = GetRandomString();

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapStringPatternMatchPropRuleAttribute>());
            //---------------Execute Test ----------------------
            SetStringPatternMatchPropRuleAttributeWithDefaultConstructor(wrapper, fourDigitStringRegex, expectedMessage);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(1, propDef.PropRules.Count);
            var actualMessage = (string)propDef.PropRules[0].Parameters["patternMatchMessage"];

            StringAssert.AreEqualIgnoringCase(expectedMessage, actualMessage);
        }
示例#17
0
        public void Test_MapProperty_WhenPublicProp_ShouldSetPropNameAndType(string propName, Type propType, string typeName)
        {
            //---------------Set up test pack-------------------
            var expectedPropName   = propName;
            var classType          = typeof(FakeBOWProps);
            var propertyInfo       = classType.GetProperty(expectedPropName);
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.AreEqual(expectedPropName, propertyInfo.Name);
            Assert.AreEqual(propType, propertyInfo.PropertyType);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(expectedPropName, propDef.PropertyName);
            Assert.AreEqual(typeName, propDef.PropertyTypeName);
            Assert.AreEqual(PropReadWriteRule.ReadWrite, propDef.ReadWriteRule);
        }
示例#18
0
        public void Test_MapWithFake_WhenShortPropRuleAttribute_ShouldReturnPropDefWithShortMinMaxRuleWithValues()
        {
            //---------------Set up test pack-------------------
            var         wrapper            = GetMockPropWrapper();
            var         propertyAutoMapper = new PropertyAutoMapper(wrapper);
            const short minValue           = 9;
            const short maxValue           = 89;

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapShortPropRuleAttribute>());
            //---------------Execute Test ----------------------
            SetShortPropRuleAttributeWithDefaultConstructor(wrapper, minValue, maxValue);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var propMinValue = (short)propDef.PropRules[0].Parameters["min"];
            var propMaxValue = (short)propDef.PropRules[0].Parameters["max"];

            Assert.AreEqual(minValue, propMinValue);
            Assert.AreEqual(maxValue, propMaxValue);
        }
示例#19
0
        public void Test_Map_WhenDefaultAttribute_ShouldReturnPropDefWithDefaultSet()
        {
            //---------------Set up test pack-------------------
            var          classType          = typeof(FakeBOWithDefaultProp);
            const string propName           = "DefaultProp";
            var          propertyInfo       = classType.GetProperty(propName);
            var          propertyWrapper    = propertyInfo.ToPropertyWrapper();
            var          propertyAutoMapper = new PropertyAutoMapper(propertyWrapper);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsTrue(propertyWrapper.HasDefaultAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(propName, propDef.PropertyName);
            Assert.NotNull(propDef.DefaultValueString);
        }
示例#20
0
        public void Test_Map_WhenNoCompulsoryAttribute_ShouldReturnMakePropDefCompulsoryFalse()
        {
            //---------------Set up test pack-------------------
            var          classType          = typeof(FakeBOWithCompulsoryProp);
            const string propName           = "NonCompulsoryProp";
            var          propertyInfo       = classType.GetProperty(propName);
            var          propertyWrapper    = propertyInfo.ToPropertyWrapper();
            var          propertyAutoMapper = new PropertyAutoMapper(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasCompulsoryAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.IsFalse(propDef.Compulsory);
        }
示例#21
0
        public void Test_Map_WhenImplementedProp_ShouldReturnPropDef()
        {
            //When Prop is implemented as part of an interface it should still be mapped
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBOImplementingInterface);
            var propertyInfo       = classType.GetProperty("ImplementedProp");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper    = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            Assert.IsFalse(propertyWrapper.IsInherited);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual("ImplementedProp", propDef.PropertyName);
        }
示例#22
0
        public void Test_MapWithFake_WhenNoShortPropRuleAttribute_ShouldReturnPropDefWithShortMinMaxRuleDefault()
        {
            //---------------Set up test pack-------------------
            var wrapper            = GetMockPropWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);

            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute <AutoMapShortPropRuleAttribute>());
            //---------------Execute Test ----------------------
            SetShortPropRuleAttributeWithDefaultConstructor(wrapper);
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var propRule = propDef.PropRules[0];

            Assert.IsInstanceOf <PropRuleShort>(propRule);
            var defaultMinValue = (short)propRule.Parameters["min"];
            var defaultMaxValue = (short)propRule.Parameters["max"];

            Assert.AreEqual(short.MinValue, defaultMinValue);
            Assert.AreEqual(short.MaxValue, defaultMaxValue);
        }
示例#23
0
        public void Test_Map_WhenOverriddenProp_ShouldReturnNull()
        {
            //When Prop inherits from another class (i.e. overrides previous
            //declaration the prop will be mapped as part of the base class
            // and should not be mapped as part of this class.
            //---------------Set up test pack-------------------
            var classType          = typeof(FakeBOSubClassWithOverridenProps);
            var propertyInfo       = classType.GetProperty("OverriddenProp");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper    = propertyInfo.ToPropertyWrapper();

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            Assert.IsTrue(propertyWrapper.IsOverridden);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();

            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
        public void Test_MapWithFake_GivenHasPropFieldNameAttribute_ShouldMapWithExpectedFieldName()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();
            var expectedDatabaseFieldName = GetRandomString();
            wrapper.Stub(wrapper1 => wrapper1.HasAttribute<AutoMapFieldNameAttribute>()).Return(true);
//            if(false)
//            {
            wrapper.Stub(propertyWrapper => propertyWrapper.GetAttribute<AutoMapFieldNameAttribute>()).Return(
                    new AutoMapFieldNameAttribute(expectedDatabaseFieldName));
            //}
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(wrapper.GetAttribute<AutoMapFieldNameAttribute>());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            var databaseFieldName = propDef.DatabaseFieldName;
            Assert.AreEqual(expectedDatabaseFieldName,  databaseFieldName);
        }
        public void Test_MapWithFake_WhenDateTimeStringPropRuleAttribute_ShouldReturnPropDefWithDateTimePropRuleWithValues()
        {
            //---------------Set up test pack-------------------
            var wrapper = GetMockPropWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(wrapper);
            const string StartDate = "Today";
            const string EndDate = "Tomorrow";
            //---------------Assert Precondition----------------
            Assert.IsNull(wrapper.GetAttribute<AutoMapDateTimePropRuleAttribute>());
            //---------------Execute Test ----------------------

            SetDateTimeStringPropRuleAttributeWithDefaultConstructor(wrapper, StartDate, EndDate);
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(1,propDef.PropRules.Count);
        }
 public void Test_MapWithFake_WhenShortPropRuleAttribute_ShouldReturnPropDefWithShortMinMaxRuleWithValues()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     const short minValue = 9;
     const short maxValue = 89;
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapShortPropRuleAttribute>());
     //---------------Execute Test ----------------------
     SetShortPropRuleAttributeWithDefaultConstructor(wrapper,minValue,maxValue);
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var propMinValue = (short) propDef.PropRules[0].Parameters["min"];
     var propMaxValue = (short) propDef.PropRules[0].Parameters["max"];
     Assert.AreEqual(minValue, propMinValue);
     Assert.AreEqual(maxValue, propMaxValue);
 }
 public void Test_MapWithFake_WhenNotHasReadWriteAttribute_ShouldReturnPropDefWithReadWrite()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapReadWriteRuleAttribute>());
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var defaultValueString = propDef.DefaultValueString;
     Assert.IsNull(defaultValueString);
 }
 public void Test_Map_WhenHasNoAutoIncrementingAttribute_ShouldNotMakePropertyAutoIncrementing()
 {
     //---------------Set up test pack-------------------
     var classType = typeof(FakeBOWithAutoIncrementingProp);
     const string propName = "NonAutoIncrementingProp";
     var propertyInfo = classType.GetProperty(propName);
     var propertyWrapper = propertyInfo.ToPropertyWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(propertyInfo);
     Assert.IsFalse(propertyWrapper.HasAutoIncrementingAttribute);
     Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
     Assert.IsTrue(propertyWrapper.IsPublic);
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     Assert.IsFalse(propDef.AutoIncrementing);
 }
        public void Test_Map_WhenHasDisplayNameAttribute_ShouldReturnPropDefWithDisplayNameSet()
        {
            //---------------Set up test pack-------------------
            var classType = typeof(FakeBOWitDisplayNameProp);
            const string propName = "DisplayNameProp";
            var propertyInfo = classType.GetProperty(propName);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(propertyWrapper);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsTrue(propertyWrapper.HasDisplayNameAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual(propName, propDef.PropertyName);
            Assert.NotNull(propDef.DisplayName);
            Assert.AreEqual("MyDisplayName", propDef.DisplayName);
        }
 public void Test_Map_WhenIsStatic_ShouldReturnNull()
 {
     //---------------Set up test pack-------------------
     var classType = typeof(FakeBoWithStaticProperty);
     var propertyInfo = classType.GetProperty("PublicStringProp");
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsFalse(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
     Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
     Assert.IsTrue(propertyInfo.ToPropertyWrapper().IsStatic);
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNull(propDef);
 }
 public void Test_MapWithFake_WhenStringPatternMatchPropRuleAttribute_WhenMessageSet_ShouldReturnPropDefWithStringPatternMatchPropRuleWithMessage()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     const string fourDigitStringRegex = @"^\d{4}$";
     var expectedMessage = GetRandomString();
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapStringPatternMatchPropRuleAttribute>());
     //---------------Execute Test ----------------------
     SetStringPatternMatchPropRuleAttributeWithDefaultConstructor(wrapper, fourDigitStringRegex, expectedMessage);
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     Assert.AreEqual(1,propDef.PropRules.Count);
     var actualMessage = (string)propDef.PropRules[0].Parameters["patternMatchMessage"];
     StringAssert.AreEqualIgnoringCase(expectedMessage, actualMessage);
 }
 public void Test_MapWithFake_GivenNotHasPropFieldNameAttribute_ShouldMapWithPropertyName()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     wrapper.Stub(wrapper1 => wrapper1.HasAttribute<AutoMapFieldNameAttribute>()).Return(false);
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapFieldNameAttribute>());
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var databaseFieldName = propDef.DatabaseFieldName;
     Assert.AreEqual(propDef.PropertyName, databaseFieldName);
 }
 public void Test_MapWithFake_WhenHasDisplayNameAttribute_ShouldReturnPropDefWithDisplayName()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var expectedDisplayName = GetRandomString();
     SetHasDisplayNameAttribute(wrapper, true, expectedDisplayName);
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsTrue(wrapper.HasDisplayNameAttribute);
     //            Assert.IsTrue(wrapper.);
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var actualDisplayName = propDef.DisplayName;
     Assert.IsNotNull(actualDisplayName);
     Assert.AreEqual(expectedDisplayName, actualDisplayName);
 }
 public void MapProperty_WhenHasKeepValuePrivateAttribute_ShouldSetKeepValuePrivateTrue()
 {
     //---------------Set up test pack-------------------
     var classType = typeof(FakeBOWProps);
     var propertyInfo = classType.GetProperty("PublicWithKeepValuePrivateAtt");
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsTrue(propDef.KeepValuePrivate);
 }
        public void Test_Map_WhenNoCompulsoryAttribute_ShouldReturnMakePropDefCompulsoryFalse()
        {
            //---------------Set up test pack-------------------
            var classType = typeof(FakeBOWithCompulsoryProp);
            const string propName = "NonCompulsoryProp";
            var propertyInfo = classType.GetProperty(propName);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasCompulsoryAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.IsFalse(propDef.Compulsory);
        }
 public void Test_PropWithNonIgnoreAttribute_ShouldReturnPropDef()
 {
     //---------------Set up test pack-------------------
     var classType = typeof(FakeBOWProps);
     var propertyInfo = classType.GetProperty("PublicPropWithAtt");
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(propertyInfo);
     Assert.AreEqual(1, propertyInfo.GetCustomAttributes(true).Length);
     Assert.IsFalse(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
     Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     Assert.AreEqual("PublicPropWithAtt", propDef.PropertyName);
 }
 public void Test_MapWithFake_WhenHasReadWriteAttribute_ShouldReturnPropDefWithAttribute()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var expectedReadWriteRule = RandomValueGenerator.GetRandomEnum<PropReadWriteRule>();
     SetReadWriteAttribute(wrapper, expectedReadWriteRule);
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(wrapper.GetAttribute<AutoMapReadWriteRuleAttribute>());
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var actualReadWriteRule = propDef.ReadWriteRule;
     Assert.IsNotNull(actualReadWriteRule);
     Assert.AreEqual(expectedReadWriteRule, actualReadWriteRule);
 }
        public void Test_PrivateProp_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var classType = typeof(FakeBoWithPrivateProps);
            var propertyInfo = classType.GetProperty("PrivateStringProp", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsFalse(propertyWrapper.IsPublic);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
 public void Test_MapWithFake_WhenNoShortPropRuleAttribute_ShouldReturnPropDefWithShortMinMaxRuleDefault()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapShortPropRuleAttribute>());
     //---------------Execute Test ----------------------
     SetShortPropRuleAttributeWithDefaultConstructor(wrapper);
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var propRule = propDef.PropRules[0];
     Assert.IsInstanceOf<PropRuleShort>(propRule);
     var defaultMinValue = (short) propRule.Parameters["min"];
     var defaultMaxValue = (short) propRule.Parameters["max"];
     Assert.AreEqual(short.MinValue,defaultMinValue);
     Assert.AreEqual(short.MaxValue, defaultMaxValue);
 }        
        public void Test_Map_WhenOverriddenProp_ShouldReturnNull()
        {
            //When Prop inherits from another class (i.e. overrides previous
            //declaration the prop will be mapped as part of the base class
            // and should not be mapped as part of this class.
            //---------------Set up test pack-------------------
            var classType = typeof(FakeBOSubClassWithOverridenProps);
            var propertyInfo = classType.GetProperty("OverriddenProp");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            Assert.IsTrue(propertyWrapper.IsOverridden);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNull(propDef);
        }
 public void Test_MapWithFake_WhenStringLengthPropRuleAttribute_ShouldReturnPropDefWithStringLengthPropRuleWithValues()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     var minLength = 10;
     var maxLength = 100;
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapStringLengthPropRuleAttribute>());
     //---------------Execute Test ----------------------
 
     SetStringLengthPropRuleAttributeWithDefaultConstructor(wrapper,minLength,maxLength);
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var propMinValue = (int)propDef.PropRules[0].Parameters["minLength"];
     var propMaxValue = (int)propDef.PropRules[0].Parameters["maxLength"];
     Assert.AreEqual(minLength, propMinValue);
     Assert.AreEqual(maxLength, propMaxValue);
 }      
        public void Test_Map_WhenImplementedProp_ShouldReturnPropDef()
        {
            //When Prop is implemented as part of an interface it should still be mapped
            //---------------Set up test pack-------------------
            var classType = typeof(FakeBOImplementingInterface);
            var propertyInfo = classType.GetProperty("ImplementedProp");
            var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
            var propertyWrapper = propertyInfo.ToPropertyWrapper();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo);
            Assert.IsFalse(propertyWrapper.HasIgnoreAttribute);

            Assert.IsTrue(propertyInfo.PropertyType.CanMapToProp());
            Assert.IsTrue(propertyWrapper.IsPublic);
            Assert.IsFalse(propertyWrapper.IsInherited);
            //---------------Execute Test ----------------------
            var propDef = propertyAutoMapper.MapProperty();
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef);
            Assert.AreEqual("ImplementedProp", propDef.PropertyName);
        }
 public void Test_MapWithFake_WhenStringPatternMatchPropRuleAttribute_ShouldReturnPropDefWithStringPatternMatchPropRuleWithValue()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     const string emailPatternMatch = @"\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
     //---------------Assert Precondition----------------
     Assert.IsNull(wrapper.GetAttribute<AutoMapStringPatternMatchPropRuleAttribute>());
     //---------------Execute Test ----------------------
     SetStringPatternMatchPropRuleAttributeWithDefaultConstructor(wrapper, emailPatternMatch);
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     Assert.AreEqual(1,propDef.PropRules.Count);
     var actualPattern = (string)propDef.PropRules[0].Parameters["patternMatch"];
     StringAssert.AreEqualIgnoringCase(emailPatternMatch, actualPattern);
 }
 public void Test_MapWithFake_WhenNotHasDefaultAttribute_ShouldReturnPropDefWithDefaultNull()
 {
     //---------------Set up test pack-------------------
     var wrapper = GetMockPropWrapper();
     SetHasDefaultAttribute(wrapper, false, GetRandomString());
     var propertyAutoMapper = new PropertyAutoMapper(wrapper);
     //---------------Assert Precondition----------------
     Assert.IsFalse(wrapper.HasDefaultAttribute);
     Assert.IsNull(wrapper.GetAttribute<AutoMapDefaultAttribute>());
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     var defaultValueString = propDef.DefaultValueString;
     Assert.IsNull(defaultValueString);
 }
 public void Test_MapProperty_WhenPublicProp_ShouldSetPropNameAndType(string propName, Type propType, string typeName)
 {
     //---------------Set up test pack-------------------
     var expectedPropName = propName;
     var classType = typeof (FakeBOWProps);
     var propertyInfo = classType.GetProperty(expectedPropName);
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(propertyInfo);
     Assert.AreEqual(expectedPropName, propertyInfo.Name);
     Assert.AreEqual(propType, propertyInfo.PropertyType);
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef);
     Assert.AreEqual(expectedPropName, propDef.PropertyName);
     Assert.AreEqual(typeName, propDef.PropertyTypeName);
     Assert.AreEqual(PropReadWriteRule.ReadWrite, propDef.ReadWriteRule);
 }
 public void Test_Map_WhenTypeNotSystem_ShouldReturnNull()
 {
     //---------------Set up test pack-------------------
     var classType = typeof(FakeBOWProps);
     var propertyInfo = classType.GetProperty("ClassDef");
     var propTypeName = propertyInfo.PropertyType.FullName;
     var propertyAutoMapper = new PropertyAutoMapper(propertyInfo);
     //---------------Assert Precondition----------------
     propTypeName.ShouldNotStartWith("System.");
     Assert.IsFalse(propertyInfo.ToPropertyWrapper().HasIgnoreAttribute);
     Assert.IsFalse(propertyInfo.PropertyType.CanMapToProp());
     //---------------Execute Test ----------------------
     var propDef = propertyAutoMapper.MapProperty();
     //---------------Test Result -----------------------
     Assert.IsNull(propDef);
 }