public void GetFormatKeyValuePairFromProperties_SimpleSample_GetOnlyPublicMembers() { //Arrange var expectedResult = new FormatKeyValuePair("{Name}", "SAMPLE1"); var expectedResult1 = new FormatKeyValuePair("{Amount}", "1"); // Act var result = service.GetFormatKeyValuePairFromProperties(sample).ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedResult, result[0]); Assert.AreEqual(expectedResult1, result[1]); }
public void GetFormatKeyValuePairFromProperties_HasHasSimple_NotGetChildeProperties_GetParentProperties() { // Arrange var expectedResult = new FormatKeyValuePair("{Name}", "HASHAS1"); var expectedResult1 = new FormatKeyValuePair("{HSS}", hasSample.ToString()); // Act var result = service.GetFormatKeyValuePairFromProperties(hasHasSample, getChildlenProperties: false).ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedResult, result[0]); Assert.AreEqual(expectedResult1, result[1]); }
public void GetFormatKeyValuePairFromProperties_HasSimpleSample_getPropertiesInNoValueTypePropertyIsFalse__GetWithSimpleSampleToString() { // Arrange var expectedResult = new FormatKeyValuePair("{Name}", "HAS1"); var expectedResult1 = new FormatKeyValuePair("{SS}", "SAMPLE1:1"); // Act var result = service.GetFormatKeyValuePairFromProperties(hasSample, getChildlenProperties: false).ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedResult, result[0]); Assert.AreEqual(expectedResult1, result[1]); }
public void GetXmlFormatKeyValuePairFromProperties_HasHasSimple_NotGetChildeProperties_GetParentProperties() { // Arrange var expectedResult = new FormatKeyValuePair("{Name}", "HASHAS1"); var expectedResult1 = new FormatKeyValuePair("{HSS}", hasSample.ToString()); // Act var result = service.GetXmlFormatKeyValuePairFromProperties(hasHasSample, getChildlenProperties: false).ToList(); // Assert Assert.AreEqual(expectedResult.Key, result[0].Attribute("key").Value); Assert.AreEqual(expectedResult.Value, result[0].Attribute("value").Value); Assert.AreEqual(expectedResult1.Key, result[1].Attribute("key").Value); Assert.AreEqual(expectedResult1.Value, result[1].Attribute("value").Value); }
public void GetFormatKeyValuePairFromProperties_HasSimpleSample_GetWithSimpleSampleProperties() { // Arrange var expectedResult = new FormatKeyValuePair("{Name}", "HAS1"); var expectedResult1 = new FormatKeyValuePair("{SS::Name}", "SAMPLE1"); var expectedResult2 = new FormatKeyValuePair("{SS::Amount}", "1"); // Act var result = service.GetFormatKeyValuePairFromProperties(hasSample).ToList(); // Assert Assert.AreEqual(3, result.Count); Assert.AreEqual(expectedResult, result[0]); Assert.AreEqual(expectedResult1, result[1]); Assert.AreEqual(expectedResult2, result[2]); }
public void GetFormatKeyValuePairs_ValueIsEmpty_ValueIsStringEmpty() { // Arrange StringBuilder builder = new StringBuilder(); builder.AppendLine("{Name}<=>"); builder.AppendLine("{Amount}<=>1"); var expectedPair = new FormatKeyValuePair("{Name}", ""); var expectedPair1 = new FormatKeyValuePair("{Amount}", "1"); // Act var result = service.GetFormatKeyValuePairs(builder.ToString()).ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedPair, result[0]); Assert.AreEqual(expectedPair1, result[1]); }
IEnumerable <IFormatKeyValuePair> GetKeyValuePairsFromProperty(PropertyInfo property, object obj, string prefix, bool getChildlenProperties, string splitMark) { if (property.PropertyType.IsCollectionType()) { return(GetFormatKeyValuePairsFromCollectionProperty(obj, property, prefix, getChildlenProperties, splitMark)); } else if (getChildlenProperties == false || property.PropertyType.IsValueTypeOrString()) { var pairs = new FormatKeyValuePair(GetKey(property, prefix), GetValue(property, obj), splitMark); return(new IFormatKeyValuePair[] { pairs }); } else { var classPrefix = prefix + property.Name + "::"; return(GetFormatKeyValuePairFromProperties(property.GetValue(obj), classPrefix, getChildlenProperties, splitMark)); } }
public void GetXmlFormatKeyValuePairFromProperties_HasHasSimpleSample_GetWithHasSimpleSampleProperties() { // Arrange var expectedResult = new FormatKeyValuePair("{Name}", "HASHAS1"); var expectedResult1 = new FormatKeyValuePair("{HSS::Name}", "HAS1"); var expectedResult2 = new FormatKeyValuePair("{HSS::SS::Name}", "SAMPLE1"); var expectedResult3 = new FormatKeyValuePair("{HSS::SS::Amount}", "1"); // Act var result = service.GetXmlFormatKeyValuePairFromProperties(hasHasSample).ToList(); // Assert Assert.AreEqual(4, result.Count); Assert.AreEqual(expectedResult.Key, result[0].Attribute("key").Value); Assert.AreEqual(expectedResult.Value, result[0].Attribute("value").Value); Assert.AreEqual(expectedResult1.Key, result[1].Attribute("key").Value); Assert.AreEqual(expectedResult1.Value, result[1].Attribute("value").Value); Assert.AreEqual(expectedResult2.Key, result[2].Attribute("key").Value); Assert.AreEqual(expectedResult2.Value, result[2].Attribute("value").Value); Assert.AreEqual(expectedResult3.Key, result[3].Attribute("key").Value); Assert.AreEqual(expectedResult3.Value, result[3].Attribute("value").Value); }
IEnumerable <IFormatKeyValuePair> GetFormatKeyValuePairsFromCollectionProperty(object obj, PropertyInfo arrayProperty, string prefix, bool getChildlenProperties, string splitMark) { int count = 0; var result = new List <IFormatKeyValuePair>(); ICollection values = (ICollection)arrayProperty.GetValue(obj); foreach (var value in values) { if (getChildlenProperties == false || value.GetType().IsValueTypeOrString()) { var pairs = new FormatKeyValuePair(string.Format("{{{0}{1}[{2}]}}", prefix, arrayProperty.Name, count++), value.ToString(), splitMark); result.Add(pairs); } else { var classPrefix = prefix + arrayProperty.Name + string.Format("[{0}]", count++) + "::"; result.AddRange(GetFormatKeyValuePairFromProperties(value, classPrefix)); } } return(result); }