/// <summary> /// Replaces the resource. /// </summary> /// <param name="resource">The resource to reset.</param> /// <returns></returns> object IUpdatable.ResetResource(object resource) { IUpdatable update = this; // Create a new resource of the same type // but only make a local copy as we're only using it to set the default fields // Get the metadata IClassMetadata metadata = session.SessionFactory.GetClassMetadata(resource.GetType().ToString()); object tempCopy = metadata.Instantiate(null, EntityMode.Poco); for (int i = 0; i < metadata.PropertyNames.Length; i++) { var propertyType = metadata.PropertyTypes[i]; var propName = metadata.PropertyNames[i]; if (!propertyType.IsEntityType) { object value = metadata.GetPropertyValue(tempCopy, propName, EntityMode.Poco); update.SetValue(resource, propName, value); } } //Return the new resource return(resource); }
public void TestSetValue() { // Create a new customer const string userName = "******"; object newUser = update.CreateResource("Users", typeof(User).FullName); // Update a key update.SetValue(newUser, "Id", 1000); // Update a non-key update.SetValue(newUser, "Name", userName); // Test the values User user = (User)newUser; Assert.AreEqual(user.Id, 1000); Assert.AreEqual(user.Name, userName); // Clear it so we're not in an unsafe state update.ClearChanges(); }