public void Object_Property_Pairs_NonGeneric() { var person = new OtherPerson2(25) { FirstName = "FirstNameValue", LastName = "LastNameValue", MiddleName = "MiddleNameValue", NickName = "NickNameValue", Suffix = "SuffixValue", Title = "TitleValue", NumberOfKids = 3 }; var pairs = _.Object.Property.Pairs(person); Assert.IsTrue(pairs.Any(a => a.Name == "FirstName" && ((string)a.Value) == "FirstNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "LastName" && ((string)a.Value) == "LastNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "MiddleName" && ((string)a.Value) == "MiddleNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "NickName" && ((string)a.Value) == "NickNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "Suffix" && ((string)a.Value) == "SuffixValue")); Assert.IsTrue(pairs.Any(a => a.Name == "Title" && ((string)a.Value) == "TitleValue")); Assert.IsTrue(pairs.Any(a => a.Name == "NumberOfKids" && ((int)a.Value) == 3)); Assert.IsTrue(pairs.Any(a => a.Name == "Age" && ((int)a.Value) == 25)); //testing that there are no more than the expected properties Assert.AreEqual(8, pairs.Count()); }
public void Object_Property_Foreach_NonGeneric_ValueAndName() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); _.Object.Property.Each(person, (value, name) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); }); //then check all expected properties were called var propertiesMissed = new List <string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_NonGeneric_JustValues() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyValues = new List <object> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", 3, 25 }; var allPropertyNames = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); _.Object.Property.Each(person, (value) => { var indexOf = allPropertyValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[indexOf] = true; } }); //then check all expected properties were called var propertiesMissed = new List <string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Could not match values to the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_Generic_ValueAndNameAndSetter() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var strProperties = new HashSet <string>(new[] { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids" }); var intProperties = new HashSet <string>(new[] { "NumberOfKids", "Age" }); var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); int increment = 0; _.Object.Property.Each <string>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = "Some value " + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); }); _.Object.Property.Each <int>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); if (name == "Age") { Assert.IsNull(setter, "Setter should be null for the 'Age' property because it does not have a setter"); } else { // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = 100 + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } }); //then check all expected properties were called var propertiesMissed = new List <string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_Generic_JustValues() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //have to get the property based off of the value, so use two arrays //seperating values by types because the tests are going to iterate over the properties based off of their type var allStrValues = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title" }; var strPropNames = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title" }; //25 added for the age property var intPropNames = new List <string> { "NumberOfKids", "Age" }; var allIntValues = new List <int> { 3, 25 }; var allPropertiesTouched = new Dictionary <string, bool>(); //initialize the dictionary to have all properties as not touched foreach (var prop in strPropNames) { allPropertiesTouched[prop] = false; } foreach (var prop in intPropNames) { allPropertiesTouched[prop] = true; } _.Object.Property.Each <string>(person, (value) => { var indexOf = allStrValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[strPropNames[indexOf]] = true; } }); _.Object.Property.Each <int>(person, (value) => { var indexOf = allIntValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[intPropNames[indexOf]] = true; } }); //get all of the properties that were missed var propertiesMissed = allPropertiesTouched.Where(a => !a.Value).Select(a => a.Key); //if any were miseed print out an error message with the names of the missed properties if (propertiesMissed.Any()) { Assert.Fail("Could not match values to the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_NonGeneric_ValueAndNameAndSetter() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List <string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var strProperties = new HashSet <string>(new[] { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title" }); var intProperties = new HashSet <string>(new[] { "NumberOfKids", "Age" }); var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); int increment = 0; _.Object.Property.Each(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); //if the property is NOT a settable property then the set method will be null if (name == "Age") { Assert.IsNull(setter, "Setter should be null for the 'Age' property because it does not have a setter"); } else { //testing to see if the property setting works if (strProperties.Contains(name)) { // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = "Some value " + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } else if (intProperties.Contains(name)) { //incrementing for the same reason as before, don't want to test with the same value if something is wrong //might give false pass result var newValue = 100 + increment; setter(newValue); increment++; var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } else { //test was possibly updated but forgot to add property to one of the fields //or new hashset needs to be made etc Assert.Fail("Property " + name + " is not included in any of the possible test cases, add property to either set or handle it explicitly "); } } }); //then check all expected properties were called var propertiesMissed = new List <string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Pairs_NonGeneric() { var person = new OtherPerson2(25) { FirstName = "FirstNameValue", LastName = "LastNameValue", MiddleName = "MiddleNameValue", NickName = "NickNameValue", Suffix = "SuffixValue", Title = "TitleValue", NumberOfKids = 3 }; var pairs = _.Object.Property.Pairs(person); Assert.IsTrue(pairs.Any(a => a.Name == "FirstName" && ((string)a.Value) == "FirstNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "LastName" && ((string)a.Value) == "LastNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "MiddleName" && ((string)a.Value) == "MiddleNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "NickName" && ((string)a.Value) == "NickNameValue")); Assert.IsTrue(pairs.Any(a => a.Name == "Suffix" && ((string)a.Value) == "SuffixValue")); Assert.IsTrue(pairs.Any(a => a.Name == "Title" && ((string)a.Value) == "TitleValue")); Assert.IsTrue(pairs.Any(a => a.Name == "NumberOfKids" && ((int)a.Value) == 3)); Assert.IsTrue(pairs.Any(a => a.Name == "Age" && ((int)a.Value) == 25)); //testing that there are no more than the expected properties Assert.AreEqual(8,pairs.Count()); }
public void Object_Property_Foreach_Generic_ValueAndNameAndSetter() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var strProperties = new HashSet<string>(new[] {"FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids"}); var intProperties = new HashSet<string>(new[] { "NumberOfKids", "Age" }); var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); int increment = 0; _.Object.Property.Each<string>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = "Some value " + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); }); _.Object.Property.Each<int>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); if (name == "Age") { Assert.IsNull(setter, "Setter should be null for the 'Age' property because it does not have a setter"); } else { // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = 100 + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } }); //then check all expected properties were called var propertiesMissed = new List<string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_Generic_ValueAndName() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); _.Object.Property.Each<string>(person, (value, name) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = (string)typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.AreEqual(actualValue, value); }); _.Object.Property.Each<int>(person, (value, name) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = (int)typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.AreEqual(actualValue, value); }); //then check all expected properties were called var propertiesMissed = new List<string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_Generic_JustValues() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //have to get the property based off of the value, so use two arrays //seperating values by types because the tests are going to iterate over the properties based off of their type var allStrValues = new List<string> {"FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title"}; var strPropNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title"}; //25 added for the age property var intPropNames = new List<string> { "NumberOfKids", "Age" }; var allIntValues = new List<int> { 3, 25 }; var allPropertiesTouched = new Dictionary<string,bool>(); //initialize the dictionary to have all properties as not touched foreach (var prop in strPropNames) allPropertiesTouched[prop] = false; foreach (var prop in intPropNames) allPropertiesTouched[prop] = true; _.Object.Property.Each<string>(person, (value) => { var indexOf = allStrValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[strPropNames[indexOf]] = true; } }); _.Object.Property.Each<int>(person, (value) => { var indexOf = allIntValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[intPropNames[indexOf]] = true; } }); //get all of the properties that were missed var propertiesMissed = allPropertiesTouched.Where(a => !a.Value).Select(a => a.Key); //if any were miseed print out an error message with the names of the missed properties if (propertiesMissed.Any()) { Assert.Fail("Could not match values to the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_NonGeneric_ValueAndNameAndSetter() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var strProperties = new HashSet<string>(new[] {"FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title"}); var intProperties = new HashSet<string>(new[] { "NumberOfKids", "Age" }); var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); int increment = 0; _.Object.Property.Each(person, (value, name,setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); //if the property is NOT a settable property then the set method will be null if (name == "Age") { Assert.IsNull(setter, "Setter should be null for the 'Age' property because it does not have a setter"); } else { //testing to see if the property setting works if (strProperties.Contains(name)) { // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = "Some value " + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } else if (intProperties.Contains(name)) { //incrementing for the same reason as before, don't want to test with the same value if something is wrong //might give false pass result var newValue = 100 + increment; setter(newValue); increment++; var newActualValue = typeof (OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } else { //test was possibly updated but forgot to add property to one of the fields //or new hashset needs to be made etc Assert.Fail("Property " + name + " is not included in any of the possible test cases, add property to either set or handle it explicitly "); } } }); //then check all expected properties were called var propertiesMissed = new List<string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void Object_Property_Foreach_NonGeneric_JustValues() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyValues = new List<object> {"FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", 3, 25}; var allPropertyNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); _.Object.Property.Each(person, (value) => { var indexOf = allPropertyValues.IndexOf(value); if (indexOf == -1) { Assert.Fail("Could not find property with value " + value); } else { allPropertiesTouched[indexOf] = true; } }); //then check all expected properties were called var propertiesMissed = new List<string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Could not match values to the following properties " + string.Join(", ", propertiesMissed)); } }