public void GetAbstractRoles() { Dictionary <Enum, EnumValueInfo> domainAbstractRoles = new Dictionary <Enum, EnumValueInfo> (); domainAbstractRoles.Add(DomainAbstractRoles.Clerk, AbstractRoles.Clerk); domainAbstractRoles.Add(DomainAbstractRoles.Secretary, AbstractRoles.Secretary); Dictionary <Enum, EnumValueInfo> specialAbstractRoles = new Dictionary <Enum, EnumValueInfo> (); specialAbstractRoles.Add(SpecialAbstractRoles.Administrator, AbstractRoles.Administrator); Expect.Call(_enumeratedTypeReflectorMock.GetValues(typeof(DomainAbstractRoles), _cache)).Return(domainAbstractRoles); Expect.Call(_enumeratedTypeReflectorMock.GetValues(typeof(SpecialAbstractRoles), _cache)).Return(specialAbstractRoles); _mocks.ReplayAll(); List <EnumValueInfo> values = _abstractRoleReflector.GetAbstractRoles(typeof(File).Assembly, _cache); _mocks.VerifyAll(); Assert.That(values, Is.Not.Null); Assert.That(values.Count, Is.EqualTo(3)); Assert.That(values, Has.Member(AbstractRoles.Clerk)); Assert.That(values, Has.Member(AbstractRoles.Secretary)); Assert.That(values, Has.Member(AbstractRoles.Administrator)); }
public List <EnumValueInfo> GetAccessTypesFromAssembly(Assembly assembly, MetadataCache cache) { ArgumentUtility.CheckNotNull("assembly", assembly); ArgumentUtility.CheckNotNull("cache", cache); List <EnumValueInfo> accessTypes = new List <EnumValueInfo> (); foreach (var type in AssemblyTypeCache.GetTypes(assembly)) { if (type.IsEnum && Attribute.IsDefined(type, typeof(AccessTypeAttribute), false)) { Dictionary <Enum, EnumValueInfo> values = _enumerationReflector.GetValues(type, cache); foreach (KeyValuePair <Enum, EnumValueInfo> entry in values) { if (!cache.ContainsAccessType(entry.Key)) { cache.AddAccessType(entry.Key, entry.Value); } accessTypes.Add(entry.Value); } } } return(accessTypes); }
public void GetMetadata() { Dictionary <Enum, EnumValueInfo> values = new Dictionary <Enum, EnumValueInfo> (); values.Add(Confidentiality.Normal, PropertyStates.ConfidentialityNormal); values.Add(Confidentiality.Confidential, PropertyStates.ConfidentialityConfidential); values.Add(Confidentiality.Private, PropertyStates.ConfidentialityPrivate); Expect.Call(_enumeratedTypeReflectorMock.GetValues(typeof(Confidentiality), _cache)).Return(values); _mocks.ReplayAll(); StatePropertyInfo info = _statePropertyReflector.GetMetadata(typeof(PaperFile).GetProperty("Confidentiality"), _cache); _mocks.VerifyAll(); Assert.That(info, Is.Not.Null); Assert.That(info.Name, Is.EqualTo("Confidentiality")); Assert.That(info.ID, Is.EqualTo("00000000-0000-0000-0001-000000000001")); Assert.That(info.Values, Is.Not.Null); Assert.That(info.Values.Count, Is.EqualTo(3)); Assert.That(info.Values, Has.Member(PropertyStates.ConfidentialityNormal)); Assert.That(info.Values, Has.Member(PropertyStates.ConfidentialityPrivate)); Assert.That(info.Values, Has.Member(PropertyStates.ConfidentialityConfidential)); }
public StatePropertyInfo GetMetadata(PropertyInfo property, MetadataCache cache) { ArgumentUtility.CheckNotNull("property", property); if (!property.PropertyType.IsEnum) { throw new ArgumentException( string.Format("The type of the property '{0}' in type '{1}' is not an enumerated type.", property.Name, property.DeclaringType.FullName), "property"); } if (!Attribute.IsDefined(property.PropertyType, typeof(SecurityStateAttribute), false)) { throw new ArgumentException(string.Format("The type of the property '{0}' in type '{1}' does not have the {2} applied.", property.Name, property.DeclaringType.FullName, typeof(SecurityStateAttribute).FullName), "property"); } ArgumentUtility.CheckNotNull("cache", cache); StatePropertyInfo info = cache.GetStatePropertyInfo(property); if (info == null) { info = new StatePropertyInfo(); info.Name = property.Name; PermanentGuidAttribute attribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(property, typeof(PermanentGuidAttribute), true); if (attribute != null) { info.ID = attribute.Value.ToString(); } info.Values = new List <EnumValueInfo> (_enumerationReflector.GetValues(property.PropertyType, cache).Values); cache.AddStatePropertyInfo(property, info); } return(info); }