public SecurableClassInfo GetMetadata(Type type, MetadataCache cache) { ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("type", type, typeof(ISecurableObject)); if (type.IsValueType) { throw new ArgumentException("Value types are not supported.", "type"); } ArgumentUtility.CheckNotNull("cache", cache); SecurableClassInfo info = cache.GetSecurableClassInfo(type); if (info == null) { info = new SecurableClassInfo(); info.Name = TypeUtility.GetPartialAssemblyQualifiedName(type); PermanentGuidAttribute guidAttribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(type, typeof(PermanentGuidAttribute), true); if (guidAttribute != null) { info.ID = guidAttribute.Value.ToString(); } info.Properties.AddRange(GetProperties(type, cache)); info.AccessTypes.AddRange(_accessTypeReflector.GetAccessTypesFromType(type, cache)); cache.AddSecurableClassInfo(type, info); if (typeof(ISecurableObject).IsAssignableFrom(type.BaseType)) { info.BaseClass = GetMetadata(type.BaseType, cache); info.BaseClass.DerivedClasses.Add(info); } } return(info); }
public void GetMetadata() { List <EnumValueInfo> fileAccessTypes = new List <EnumValueInfo> (); fileAccessTypes.Add(AccessTypes.Read); fileAccessTypes.Add(AccessTypes.Write); fileAccessTypes.Add(AccessTypes.Journalize); List <EnumValueInfo> paperFileAccessTypes = new List <EnumValueInfo> (); paperFileAccessTypes.Add(AccessTypes.Read); paperFileAccessTypes.Add(AccessTypes.Write); paperFileAccessTypes.Add(AccessTypes.Journalize); paperFileAccessTypes.Add(AccessTypes.Archive); Expect.Call(_statePropertyReflectorMock.GetMetadata(typeof(PaperFile).GetProperty("Confidentiality"), _cache)).Return(_confidentialityProperty); Expect.Call(_statePropertyReflectorMock.GetMetadata(typeof(PaperFile).GetProperty("State"), _cache)).Return(_stateProperty); Expect.Call(_statePropertyReflectorMock.GetMetadata(typeof(File).GetProperty("Confidentiality"), _cache)).Return(_confidentialityProperty); Expect.Call(_accessTypeReflectorMock.GetAccessTypesFromType(typeof(File), _cache)).Return(fileAccessTypes); Expect.Call(_accessTypeReflectorMock.GetAccessTypesFromType(typeof(PaperFile), _cache)).Return(paperFileAccessTypes); _mocks.ReplayAll(); SecurableClassInfo info = _classReflector.GetMetadata(typeof(PaperFile), _cache); _mocks.VerifyAll(); Assert.That(info, Is.Not.Null); Assert.That(info.Name, Is.EqualTo("Remotion.Security.UnitTests.TestDomain.PaperFile, Remotion.Security.UnitTests.TestDomain")); Assert.That(info.ID, Is.EqualTo("00000000-0000-0000-0002-000000000000")); Assert.That(info.DerivedClasses.Count, Is.EqualTo(0)); Assert.That(info.BaseClass, Is.Not.Null); Assert.That(info.BaseClass.Name, Is.EqualTo("Remotion.Security.UnitTests.TestDomain.File, Remotion.Security.UnitTests.TestDomain")); Assert.That(info.BaseClass.DerivedClasses.Count, Is.EqualTo(1)); Assert.That(info.BaseClass.DerivedClasses, Has.Member(info)); Assert.That(info.Properties.Count, Is.EqualTo(2)); Assert.That(info.Properties, Has.Member(_confidentialityProperty)); Assert.That(info.Properties, Has.Member(_stateProperty)); Assert.That(info.AccessTypes.Count, Is.EqualTo(4)); foreach (EnumValueInfo accessType in paperFileAccessTypes) { Assert.That(info.AccessTypes, Has.Member(accessType)); } }