public EnumHelper(Type enumType, IEnumDescriptor enumDescriptor) { EnumType = enumType; EnumDescriptor = enumDescriptor; EnumValues = new Dictionary <ValueType, string>(); InitializeDictionary(); }
public static void Initialize(TestContext testContext) { Mock <IEnumDescriptor> enumDescriptorMock = new Mock <IEnumDescriptor>(); enumDescriptorMock.Setup(instance => instance.DataType).Returns(typeof(int)); enumDescriptorMock.Setup(instance => instance.Enumerations).Returns(new List <string>() { "e1,1" }); enumDescriptor = enumDescriptorMock.Object; enumHelper = new EnumHelper(typeof(TesztEnum), enumDescriptor); }
public IEnumHelper AddEnumType(IEnumDescriptor enumDescriptor) { if (enumDescriptor == null) { throw new ArgumentNullException(); } if (!EnumDictionary.ContainsKey(enumDescriptor.EnumName)) { Type enumType = _enumGenerator.CreateEnumType(enumDescriptor); EnumDictionary.Add(enumDescriptor.EnumName, new EnumHelper(enumType, enumDescriptor)); } return(EnumDictionary[enumDescriptor.EnumName]); }
public Type CreateEnumType(IEnumDescriptor enumDescriptor) { EnumBuilder enumBuilder = moduleBuilder.DefineEnum(enumDescriptor.EnumName, TypeAttributes.Public, enumDescriptor.DataType); if (enumDescriptor.IsFlag) { enumBuilder.SetCustomAttribute(customAttributeBuilder); } foreach (var rawEnumValue in enumDescriptor.Enumerations) { Tuple <string, ValueType> enumValue = EnumValueResolver.ResolveEnumValue(enumDescriptor.DataType, rawEnumValue); enumBuilder.DefineLiteral(enumValue.Item1, enumValue.Item2); } return(enumBuilder.CreateType()); }
public static void Initialize(TestContext testContext) { Mock <IEnumDescriptor> enumDescriptorMock = new Mock <IEnumDescriptor>(); enumDescriptorMock.Setup(instance => instance.DataType).Returns(typeof(int)); enumDescriptorMock.Setup(instance => instance.Enumerations).Returns(new List <string>() { "e1,1" }); enumDescriptorMock.Setup(instance => instance.EnumName).Returns("TesztEnum"); enumDescriptor = enumDescriptorMock.Object; Mock <IEnumTypeGenerator> enumTypeGeneratorMock = new Mock <IEnumTypeGenerator>(); enumTypeGeneratorMock.Setup(instance => instance.CreateEnumType(It.IsAny <IEnumDescriptor>())).Returns(typeof(TesztEnum)); enumGenerator = enumTypeGeneratorMock.Object; enumManager = new EnumManager(enumGenerator); }
public static void Initialize(TestContext testContext) { Mock <IEnumDescriptor> enumDescriptorMock = new Mock <IEnumDescriptor>(); enumDescriptorMock.Setup(instance => instance.DataType).Returns(typeof(int)); enumDescriptorMock.Setup(instance => instance.Enumerations).Returns(new List <string>() { "e1,1" }); enumDescriptorMock.Setup(instance => instance.EnumName).Returns("TesztEnum"); enumDescriptorMock.Setup(instance => instance.IsFlag).Returns(true); enumDescriptor = enumDescriptorMock.Object; Mock <IEnumValueResolver> enumValueResolverMock = new Mock <IEnumValueResolver>(); enumValueResolverMock.Setup(instance => instance.ResolveEnumValue(It.IsAny <Type>(), It.IsAny <string>())).Returns(new Tuple <string, ValueType>("e1", 1)); enumValueResolver = enumValueResolverMock.Object; enumGenerator = new EnumTypeGenerator(enumValueResolver); }