示例#1
0
        public IEnumerable <ExtensibleEnumInfo <T> > GetValueInfos <T> (ExtensibleEnumDefinition <T> definition) where T : ExtensibleEnum <T>
        {
            ArgumentUtility.CheckNotNull("definition", definition);

            var types = _typeDiscoveryService.GetTypes(null, false).Cast <Type>();

            return(GetValueInfosForTypes(definition, types));
        }
示例#2
0
        public void SetUp()
        {
            _fakeColorDefinition  = new ExtensibleEnumDefinition <Color> (MockRepository.GenerateStub <IExtensibleEnumValueDiscoveryService> ());
            _fakePlanetDefinition = new ExtensibleEnumDefinition <Planet> (MockRepository.GenerateStub <IExtensibleEnumValueDiscoveryService> ());

            _typeDiscoveryServiceStub = MockRepository.GenerateStub <ITypeDiscoveryService> ();
            _service = new TestableExtensibleEnumValueDiscoveryService(_typeDiscoveryServiceStub);
        }
        private ExtensibleEnumDefinition <T> CreateDefinition <T> (IEnumerable <ExtensibleEnumInfo <T> > infos)
            where T : ExtensibleEnum <T>
        {
            var valueDiscoveryServiceStub = MockRepository.GenerateStub <IExtensibleEnumValueDiscoveryService>();
            var definition = new ExtensibleEnumDefinition <T> (valueDiscoveryServiceStub);

            valueDiscoveryServiceStub.Stub(stub => stub.GetValueInfos(Arg <ExtensibleEnumDefinition <T> > .Is.Anything)).Return(infos);
            return(definition);
        }
示例#4
0
        public void GetValueInfos_PassesDefinition_ToExtensionMethod()
        {
            _typeDiscoveryServiceStub.Stub(stub => stub.GetTypes(null, false)).Return(new[] { typeof(ColorExtensions) });

            var definition = new ExtensibleEnumDefinition <Color> (_service);

            _service.GetValueInfos(definition).ToArray();

            Assert.That(ColorExtensions.LastCallArgument, Is.SameAs(definition));
        }
示例#5
0
        public IEnumerable <ExtensibleEnumInfo <T> > GetValueInfosForTypes <T> (
            ExtensibleEnumDefinition <T> definition,
            IEnumerable <Type> typeCandidates)
            where T : ExtensibleEnum <T>
        {
            ArgumentUtility.CheckNotNull("definition", definition);
            ArgumentUtility.CheckNotNull("typeCandidates", typeCandidates);

            return(from type in GetStaticTypes(typeCandidates)
                   // optimization: only static types can have extension methods
                   from valueInfo in GetValueInfosForType(definition, type)
                   select valueInfo);
        }
        public void GetValueInfos_PassesExtensibleEnumDefinitionInstance_ToExtensibleEnumValueDiscoveryService()
        {
            var valueDiscoveryServiceMock = MockRepository.GenerateMock <IExtensibleEnumValueDiscoveryService>();
            var infos = GetInfos(_red);

            valueDiscoveryServiceMock.Stub(mock => mock.GetValueInfos(Arg <ExtensibleEnumDefinition <Color> > .Is.Anything)).Return(infos);

            var extensibleEnumDefinition = new ExtensibleEnumDefinition <Color> (valueDiscoveryServiceMock);

            extensibleEnumDefinition.GetValueInfos();

            valueDiscoveryServiceMock.AssertWasCalled(mock => mock.GetValueInfos(extensibleEnumDefinition));
        }
示例#7
0
        public IEnumerable <ExtensibleEnumInfo <T> > GetValueInfosForType <T> (ExtensibleEnumDefinition <T> definition, Type typeDeclaringMethods)
            where T : ExtensibleEnum <T>
        {
            ArgumentUtility.CheckNotNull("definition", definition);
            ArgumentUtility.CheckNotNull("typeDeclaringMethods", typeDeclaringMethods);

            var methods          = typeDeclaringMethods.GetMethods(BindingFlags.Static | BindingFlags.Public);
            var extensionMethods = GetValueExtensionMethods(typeof(T), methods);

            return(from mi in extensionMethods
                   let value = (T)mi.Invoke(null, new object[] { definition })
                               let positionAttribute = AttributeUtility.GetCustomAttribute <ExtensibleEnumPositionAttribute> (mi, true)
                                                       let positionalKey = positionAttribute != null ? positionAttribute.PositionalKey : 0.0
                                                                           select new ExtensibleEnumInfo <T> (value, mi, positionalKey));
        }
        public void GetValueInfos_CachesValues()
        {
            var valueDiscoveryServiceMock = MockRepository.GenerateMock <IExtensibleEnumValueDiscoveryService>();

            valueDiscoveryServiceMock
            .Expect(mock => mock.GetValueInfos(Arg <ExtensibleEnumDefinition <Color> > .Is.Anything))
            .Return(GetInfos(_red))
            .Repeat.Once();
            valueDiscoveryServiceMock.Replay();

            var extensibleEnumDefinition = new ExtensibleEnumDefinition <Color> (valueDiscoveryServiceMock);
            var values1 = extensibleEnumDefinition.GetValueInfos();
            var values2 = extensibleEnumDefinition.GetValueInfos();

            valueDiscoveryServiceMock.VerifyAllExpectations();
            Assert.That(values1, Is.SameAs(values2));
        }
 public static Color LightBlue(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color("LightBlue"));
 }
示例#10
0
 public static Color Red(this ExtensibleEnumDefinition <Color> definition)
 {
     LastCallArgument = definition;
     return(new Color("Red"));
 }
示例#11
0
 public static Color Green(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color("Green"));
 }
示例#12
0
 public static EnumWithDifferentCtors DeclaringTypeAndName(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors)
 {
     return(new EnumWithDifferentCtors(typeof(EnumWithDifferentCtorsExtensions), "ValueName"));
 }
示例#13
0
 public static TestEnum ValueWithEnAndEnUS(ExtensibleEnumDefinition <TestEnum> definition)
 {
     throw new NotImplementedException();
 }
示例#14
0
 public static TestEnum ValueWithDuplicateMultiLingualNameAttributes(ExtensibleEnumDefinition <TestEnum> definition)
 {
     throw new NotImplementedException();
 }
 public static Planet Eris(this ExtensibleEnumDefinition <Planet> definition)
 {
     return(new Planet(MethodBase.GetCurrentMethod()));
 }
 public static ExtensibleEnumWithFilter Value2(this ExtensibleEnumDefinition <ExtensibleEnumWithFilter> definition)
 {
     return(new ExtensibleEnumWithFilter("Value2"));
 }
示例#17
0
 public static TestEnum ValueWithMultiLingualNameAttributeForInvariantCulture(ExtensibleEnumDefinition <TestEnum> definition)
 {
     throw new NotImplementedException();
 }
 public static Color DarkBlue(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color("DarkColor", "DarkBlue"));
 }
示例#19
0
 public static Color LightRed(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color("LightColor", "LightRed"));
 }
 public static ExtensibleEnumWithResources ValueWithoutResource(this ExtensibleEnumDefinition <ExtensibleEnumWithResources> definition)
 {
     return(new ExtensibleEnumWithResources(MethodBase.GetCurrentMethod()));
 }
示例#21
0
 public static EnumWithDifferentCtors CurrentMethod(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors)
 {
     return(new EnumWithDifferentCtors(MethodBase.GetCurrentMethod()));
 }
示例#22
0
 public static EnumWithDifferentCtors NameAndNullDeclarationSpace(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors)
 {
     return(new EnumWithDifferentCtors((string)null, "ValueName"));
 }
 public static Color MixedRed(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color("MixedColor", "MixedRed"));
 }
示例#24
0
 public static EnumWithDifferentCtors IDOnly(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors)
 {
     return(new EnumWithDifferentCtors("ValueName"));
 }
示例#25
0
 public static TestEnum ValueWithoutInvariantCulture(ExtensibleEnumDefinition <TestEnum> definition)
 {
     throw new NotImplementedException();
 }
 public static MetallicColor RedMetallic(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new MetallicColor("MetallicColor", "RedMetallic"));
 }
 public static ExtensibleEnumWithDuplicateAttribute Value3(this ExtensibleEnumDefinition <ExtensibleEnumWithDuplicateAttribute> definition)
 {
     return(new ExtensibleEnumWithDuplicateAttribute("Value3"));
 }
示例#28
0
 public static TestExtensibleEnum Value2(this ExtensibleEnumDefinition <TestExtensibleEnum> definition)
 {
     return(new TestExtensibleEnum(MethodBase.GetCurrentMethod()));
 }
 public static Color Blue(this ExtensibleEnumDefinition <Color> definition)
 {
     return(new Color(MethodBase.GetCurrentMethod()));
 }
示例#30
0
 public static EnumWithDifferentCtors NameAndEmptyDeclarationSpace(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors)
 {
     return(new EnumWithDifferentCtors("", "ValueName"));
 }