public void InheritedAttributes_ParentEntityAttributeValues_IncludesChildEntityAttributeValues() { var rockContext = new RockContext(); var eventItemService = new EventItemService(rockContext); // Verify the values of the test Attribute for Event A and Event B. // These Attributes are defined per-Calendar and so are directly linked to the EventItemCalendar entity, // but they should also appear as inherited attributes of the EventItem. var eventA = eventItemService.Get(EventAGuid.AsGuid()); eventA.LoadAttributes(); Assert.IsTrue(eventA.AttributeValues[InternalCalendarAttribute1Key].Value == "Event A Internal"); Assert.IsTrue(eventA.AttributeValues[PublicCalendarAttribute1Key].Value == "Event A Public"); var eventB = eventItemService.Get(EventBGuid.AsGuid()); eventB.LoadAttributes(); Assert.IsTrue(eventB.AttributeValues[PublicCalendarAttribute1Key].Value == "Event B Public"); Assert.IsTrue(eventB.AttributeValues[InternalCalendarAttribute1Key].Value == null, $"Unexpected Attribute Value: {InternalCalendarAttribute1Key}."); }
public void InheritedAttributes_SetAttributeOnParentEntity_SetsValueForChildEntity() { var rockContext = new RockContext(); var eventItemService = new EventItemService(rockContext); var eventCalendarService = new EventCalendarItemService(rockContext); // Setting the value of an inherited Attribute should persist the value for the child entity. var eventA = eventItemService.Get(EventAGuid.AsGuid()); eventA.LoadAttributes(rockContext); eventA.SetAttributeValue(InternalCalendarAttribute1Key, "xyzzy"); // TODO: SaveAttributeValues does not correctly save inherited values. // It wrongly attributes them to the entity on which they are set rather than the inherited entity. eventA.SaveAttributeValues(rockContext); var calendarItemInternal = eventCalendarService.Get(EventACalendarInternalGuid.AsGuid()); var calendarItemPublic = eventCalendarService.Get(EventACalendarPublicGuid.AsGuid()); calendarItemInternal.LoadAttributes(); Assert.IsTrue(calendarItemInternal.AttributeValues[InternalCalendarAttribute1Key].Value == "xyzzy"); calendarItemPublic.LoadAttributes(); Assert.IsTrue(calendarItemPublic.AttributeValues[InternalCalendarAttribute1Key].Value == "xyzzy"); }