public void One2Many() { var c2A = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2A").Build(); var c2B = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2B").Build(); var c2C = new C2Builder(this.DatabaseSession).WithC2AllorsString("c2C").Build(); var c1a = new C1Builder(this.DatabaseSession) .WithC1AllorsString("c1A") .WithC1C2One2Many(c2A) .Build(); var c1b = new C1Builder(this.DatabaseSession) .WithC1AllorsString("c1B") .WithC1C2One2Many(c2B) .WithC1C2One2Many(c2C) .Build(); this.DatabaseSession.Derive(true); var path = new Path(C1s.Meta.C1C2One2Manies, C2s.Meta.C2AllorsString); var aclMock = new Mock<IAccessControlList>(); aclMock.Setup(acl => acl.CanRead(It.IsAny<PropertyType>())).Returns(true); var acls = new AccessControlListCache(null, (allorsObject, user) => aclMock.Object); var result = (ISet<object>)path.Get(c1a, acls); Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains("c2A")); result = (ISet<object>)path.Get(c1b, acls); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains("c2B")); Assert.IsTrue(result.Contains("c2C")); }
public static void SetPath(this ModelMetadata modelMetadata, Path value) { modelMetadata.AdditionalValues[PathKey] = value; }
public CsvExportPath(Path path) { this.Path = path; this.Header = path.End.PropertyType.DisplayName; }
public static bool TryParse(Composite composite, string pathString, out Path path) { var propertyType = Resolve(composite, pathString); path = propertyType == null ? null : new Path(propertyType); return path != null; }
protected override CachedDataAnnotationsModelMetadata CreateMetadataPrototype(IEnumerable<Attribute> attributeEnumerations, Type containerType, Type modelType, string propertyName) { var attributes = new List<Attribute>(attributeEnumerations); Composite composite; if (containerType != null && this.compositeByModelType.TryGetValue(containerType, out composite)) { Path path; if (composite != null) { Dictionary<string, Path> pathByPropertyName; if (!this.pathByPropertyNameByModelType.TryGetValue(containerType, out pathByPropertyName)) { pathByPropertyName = new Dictionary<string, Path>(); this.pathByPropertyNameByModelType[containerType] = pathByPropertyName; } var pathString = propertyName; if (!pathByPropertyName.TryGetValue(pathString, out path)) { var pathAttribute = (PathAttribute)attributes.FirstOrDefault(x => x is PathAttribute); if (pathAttribute != null && pathAttribute.PropertyIds.Length > 0) { path = new Path(composite.MetaPopulation, pathAttribute.PropertyIds); } else { Path.TryParse(composite, pathString, out path); } pathByPropertyName[pathString] = path; if (path != null) { var roleType = path.End.PropertyType as RoleType; if (roleType != null) { if (!attributes.Any(x => x is DisplayAttribute)) { var displayAttribute = roleType.DisplayAttribute; if (displayAttribute != null) { attributes.Add(displayAttribute); } } if (!attributes.Any(x => x is DataTypeAttribute)) { var dataTypeAttribute = roleType.DataTypeAttribute; if (dataTypeAttribute != null) { attributes.Add(dataTypeAttribute); } } } } } } } return base.CreateMetadataPrototype(attributes, containerType, modelType, propertyName); }