public void GetProxyType_TypeAttributeWithStaticConstructor_ReturnsProxyWithClassAttribute() { var proxyDefinition = new ProxyDefinition(typeof(IMethodWithNoParameters)); proxyDefinition.AddCustomAttributes(typeof(ClassWithCustomAttributeWithStaticConstructor).GetCustomAttributesData().ToArray()); var proxyBuilder = new ProxyBuilder(); var proxyType = proxyBuilder.GetProxyType(proxyDefinition); Assert.True(proxyType.IsDefined(typeof(CustomAttributeWithStaticConstructor), true)); }
public void GetProxyType_TypeAttributeWithConstructorArgument_ReturnsProxyWithClassAttribute() { var proxyDefinition = new ProxyDefinition(typeof(IMethodWithNoParameters)); proxyDefinition.AddCustomAttributes(typeof(ClassWithCustomAttributeWithConstructorArgument).GetCustomAttributesData().ToArray()); var proxyBuilder = new ProxyBuilder(); var proxyType = proxyBuilder.GetProxyType(proxyDefinition); var attribute = proxyType.GetCustomAttribute <CustomAttributeWithConstructorArgument>(); Assert.Equal(42, attribute.Value); }
private static ProxyDefinition CreateProxyDefinition(Type serviceType) { var proxyDefinition = new ProxyDefinition(serviceType, () => container.GetInstance(serviceType)); if (container.CanGetInstance(serviceType, string.Empty)) { ServiceRegistration serviceRegistration = container.AvailableServices.FirstOrDefault(sr => sr.ServiceType == serviceType); if (serviceRegistration != null && serviceRegistration.ImplementingType != null) { proxyDefinition.AddCustomAttributes( serviceRegistration.ImplementingType.GetCustomAttributesData().ToArray()); } } return(proxyDefinition); }