public void GetSetValue() { Employee person = new Employee { FirstName = "Franz", LastName = "Huber", Address = new Address { City = "NY" } }; var path1 = PropertyPath.Create <Person, string>(p => p.FirstName); Assert.AreEqual("Franz", path1.GetValue(person)); path1.SetValue(person, "Hans"); Assert.AreEqual("Hans", person.FirstName); var path2 = PropertyPath.Create <Employee, string>(p => p.LastName); Assert.AreEqual("Huber", path2.GetValue(person)); path2.SetValue(person, "Maier"); Assert.AreEqual("Maier", person.LastName); var path3 = PropertyPath.Create <Employee, string>(p => p.Address.City); Assert.AreEqual("NY", path3.GetValue(person)); path3.SetValue(person, "AZ"); Assert.AreEqual("AZ", person.Address.City); person.Address = null; AssertHelper.Throws <NullReferenceException>(() => path3.GetValue(person) ) .Containing("'[Employee].Address'") .Containing("'[Employee].Address.City'"); var path4 = PropertyPath.CreateWithDefaultValue <Employee, string>(p => p.Address.City, "-"); Assert.AreEqual("-", path4.GetValue(person)); // SetValue should be ignored... path4.SetValue(person, "Test"); Assert.AreEqual(null, person.Address); var path5 = PropertyPath.Create <Person, Person>(p => p); Assert.AreEqual(person, path5.GetValue(person)); AssertHelper.Throws <InvalidOperationException>( () => path5.SetValue(person, person) ).Containing("empty"); path5 = PropertyPath.Empty <Person>(); Assert.AreEqual(person, path5.GetValue(person)); AssertHelper.Throws <InvalidOperationException>( () => path5.SetValue(person, person) ).Containing("empty"); }
public void Setup() { Configuration = new VMDescriptorConfiguration(new BehaviorChainConfiguration()); SourceObjectFactory = new VMPropertyBuilder <EmployeeVM, Employee>( PropertyPath.Create((EmployeeVM x) => x.SourcePerson), Configuration ); RootFactory = new VMPropertyBuilder <EmployeeVM, EmployeeVM>( PropertyPath.Empty <EmployeeVM>(), Configuration ); }
public void Concat() { var path1 = PropertyPath.Create <Employee, Address>(p => p.Address); var path2 = PropertyPath.Create <Address, string>(a => a.City); var path3 = PropertyPath.Concat(path1, path2); TestAddressPath(path3); var emptyEmployeePath = PropertyPath.Empty <Employee>(); var emptyStringPath = PropertyPath.Create <string, string>(s => s); var path4 = PropertyPath.Concat(emptyEmployeePath, path3); var path5 = PropertyPath.Concat(path3, emptyStringPath); TestAddressPath(path4); TestAddressPath(path5); }
public IVMPropertyBuilder <TVM> GetPropertyBuilder() { return(new VMPropertyBuilder <TVM, TVM>(PropertyPath.Empty <TVM>(), _configuration)); }