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)); }
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); }
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)); }
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)); }
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")); }
public static Color Red(this ExtensibleEnumDefinition <Color> definition) { LastCallArgument = definition; return(new Color("Red")); }
public static Color Green(this ExtensibleEnumDefinition <Color> definition) { return(new Color("Green")); }
public static EnumWithDifferentCtors DeclaringTypeAndName(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors) { return(new EnumWithDifferentCtors(typeof(EnumWithDifferentCtorsExtensions), "ValueName")); }
public static TestEnum ValueWithEnAndEnUS(ExtensibleEnumDefinition <TestEnum> definition) { throw new NotImplementedException(); }
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")); }
public static TestEnum ValueWithMultiLingualNameAttributeForInvariantCulture(ExtensibleEnumDefinition <TestEnum> definition) { throw new NotImplementedException(); }
public static Color DarkBlue(this ExtensibleEnumDefinition <Color> definition) { return(new Color("DarkColor", "DarkBlue")); }
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())); }
public static EnumWithDifferentCtors CurrentMethod(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors) { return(new EnumWithDifferentCtors(MethodBase.GetCurrentMethod())); }
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")); }
public static EnumWithDifferentCtors IDOnly(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors) { return(new EnumWithDifferentCtors("ValueName")); }
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")); }
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())); }
public static EnumWithDifferentCtors NameAndEmptyDeclarationSpace(this ExtensibleEnumDefinition <EnumWithDifferentCtors> enumWithDifferentCtors) { return(new EnumWithDifferentCtors("", "ValueName")); }