public void WhenNullAttributes_ThenUsesConstructorWithNameValueCollectionParameter() { LambdaExpression expression = RegistrationExpressionBuilder.BuildExpression(typeToBuild, null); var newExpression = ((NewExpression)expression.Body); Assert.AreEqual(1, newExpression.Constructor.GetParameters().Count()); Assert.AreEqual(typeof(NameValueCollection), newExpression.Constructor.GetParameters()[0].ParameterType); }
/// <summary> /// Retrieves the <see cref="TypeRegistration"/> container configuration model for custom exception handling data. /// </summary> /// <param name="namePrefix">The child prefix to use when reference child elements</param> /// <returns>The type registration for the custom exception handler</returns> public override IEnumerable <TypeRegistration> GetRegistrations(string namePrefix) { yield return(new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, Attributes), typeof(IExceptionHandler)) { Name = BuildName(namePrefix), Lifetime = TypeRegistrationLifetime.Transient }); }
public void WhenNullAttributes_ThenCreatesEmptyNameValueCollectionForConstructorParameter() { LambdaExpression expression = RegistrationExpressionBuilder.BuildExpression(typeToBuild, null); var newExpression = ((NewExpression)expression.Body); var collection = ((ConstantExpression)newExpression.Arguments[0]).Value as NameValueCollection; Assert.IsNotNull(collection); Assert.AreEqual(0, collection.Count); }
/// <summary> /// Returns the <see cref="TypeRegistration"/> entry for this data section. /// </summary> /// <returns>The type registration for this data section</returns> public override IEnumerable <TypeRegistration> GetRegistrations() { yield return (new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, Attributes), typeof(ILogFormatter)) { Name = this.Name, Lifetime = TypeRegistrationLifetime.Transient }); }
/// <summary> /// Get the set of <see cref="TypeRegistration"/> objects needed to /// register the matching rule represented by this config element and its associated objects. /// </summary> /// <param name="nameSuffix">A suffix for the names in the generated type registration objects.</param> /// <returns>The set of <see cref="TypeRegistration"/> objects.</returns> public override IEnumerable <TypeRegistration> GetRegistrations(string nameSuffix) { yield return (new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, this.Attributes), typeof(IMatchingRule)) { Name = this.Name + nameSuffix, Lifetime = TypeRegistrationLifetime.Transient }); }
/// <summary> /// Creates a <see cref="TypeRegistration"/> instance describing the provider represented by /// this configuration object. /// </summary> /// <returns>A <see cref="TypeRegistration"/> instance describing a provider.</returns> public override IEnumerable <TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { yield return (new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(Type, Attributes), typeof(ISymmetricCryptoProvider)) { Name = Name, Lifetime = TypeRegistrationLifetime.Transient }); }
public void WhenNonNullAttributes_ThenAttributesCollectionIsProvidedAsParameterValue() { NameValueCollection inputCollection = new NameValueCollection() { { "checkone", "one" }, { "checktwo", "two" } }; LambdaExpression expression = RegistrationExpressionBuilder.BuildExpression(typeToBuild, inputCollection); var newExpression = ((NewExpression)expression.Body); var collection = ((ConstantExpression)newExpression.Arguments[0]).Value as NameValueCollection; Assert.AreSame(inputCollection, collection); }
/// <summary> /// /// </summary> /// <returns></returns> public override IEnumerable <TypeRegistration> GetRegistrations() { if (!typeof(IBackingStore).IsAssignableFrom(this.Type)) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Caching.Properties.Resources.ExceptionTypeForCustomBackingStoreMustDeriveFrom, Name, this.Type.FullName)); } yield return(new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, Attributes), typeof(IBackingStore)) { Name = this.Name }); }
/// <summary> /// Get the set of <see cref="TypeRegistration"/> objects needed to /// register the call handler represented by this config element and its associated objects. /// </summary> /// <param name="nameSuffix">A suffix for the names in the generated type registration objects.</param> /// <returns>The set of <see cref="TypeRegistration"/> objects.</returns> public override IEnumerable <TypeRegistration> GetRegistrations(string nameSuffix) { yield return (new TypeRegistration( Expression.Lambda( Expression.MemberInit( RegistrationExpressionBuilder.BuildNewExpression(this.Type, this.Attributes), Expression.Bind( this.Type.GetProperty("Order", BindingFlags.Public | BindingFlags.Instance), Expression.Constant(this.Order)))), typeof(ICallHandler)) { Name = this.Name + nameSuffix }); }
/// <summary> /// /// </summary> /// <returns></returns> public override IEnumerable <TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { //missing type is handled by configuration system. if (!typeof(ISecurityCacheProvider).IsAssignableFrom(this.Type)) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionTypeForCustomCacheProviderMustDeriveFrom, Name, this.Type.FullName)); } yield return(new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, Attributes), typeof(ISecurityCacheProvider)) { Name = this.Name, Lifetime = TypeRegistrationLifetime.Transient }); }
/// <summary> /// Get the set of <see cref="TypeRegistration"/> object needed to /// register the CacheManager represented by this config element. /// </summary> /// <returns>The sequence of <see cref="TypeRegistration"/> objects.</returns> public override IEnumerable <TypeRegistration> GetRegistrations(IConfigurationSource configurationSource) { if (!typeof(ICacheManager).IsAssignableFrom(this.Type)) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Caching.Properties.Resources.ExceptionTypeForCustomCacheManagerMustDeriveFrom, Name, this.Type.FullName)); } TypeRegistration customCacheManagerRegistration = new TypeRegistration( RegistrationExpressionBuilder.BuildExpression(this.Type, Attributes), typeof(ICacheManager)) { Name = this.Name, IsPublicName = true }; return(new TypeRegistration[] { customCacheManagerRegistration }); }
public void WhenTheExpressionIsBuilt_ThenExpressionBuilderThrowsArgumentException() { LambdaExpression expression = RegistrationExpressionBuilder.BuildExpression(typeToBuild, null); }
public void WhenNullAttributes_ThenProvidesNewLambdaExpression() { LambdaExpression expression = RegistrationExpressionBuilder.BuildExpression(typeToBuild, null); Assert.AreEqual(ExpressionType.New, expression.Body.NodeType); }