Skip to content

Commit

Permalink
Fixed errors in tests and configuration constructor usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
open-collar committed May 17, 2021
1 parent c0acc90 commit 8d7eaef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public Element<TKey, TElement> this[TKey key]
return value;
}

throw new ArgumentOutOfRangeException(nameof(key), key, string.Format(CultureInfo.CurrentCulture, Exceptions.KeyNotFound, nameof(key)));
throw new ArgumentOutOfRangeException(nameof(key), key, string.Format(CultureInfo.CurrentCulture, Exceptions.KeyNotFound, nameof(key), key));
}
}

Expand Down Expand Up @@ -860,7 +860,7 @@ protected TElement AddNew(TKey key)
break;

case ImplementationKind.ConfigurationObject:
var validators = ServiceCollectionExtensions.GetValidators(PropertyDef.ElementImplementation.ImplementationType);
var validators = ServiceCollectionExtensions.GetValidators(PropertyDef.ElementImplementation.Type);
value = (TElement)Activator.CreateInstance(PropertyDef.ElementImplementation.ImplementationType, PropertyDef, ConfigurationRoot, this, PropertyDef.Settings, validators);
break;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenCollar.Extensions.Configuration/PropertyDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public TElement CopyValue<TElement>(IImplementation implementation, TElement val
return (TElement)Activator.CreateInstance(implementation.ImplementationType, parent, this, configurationRoot, value, implementation.Settings);

case ImplementationKind.ConfigurationObject:
var validators = ServiceCollectionExtensions.GetValidators(implementation.ImplementationType);
var validators = ServiceCollectionExtensions.GetValidators(implementation.Type);
var clone = Activator.CreateInstance(implementation.ImplementationType, this, configurationRoot, parent, implementation.Settings, validators);
((ConfigurationObjectBase)clone).Clone((IConfigurationObject)value);
return (TElement)clone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ public void TestConstructors()
Assert.NotNull(x);
Assert.Null(x.PropertyDef());

var validators = System.Array.Empty<IConfigurationObjectValidator<IRootElement>>();

Assert.Throws<TargetInvocationException>(() =>
{
var y = Activator.CreateInstance(x.GetType(), (IPropertyDef)null, (IConfigurationRoot)null, (IConfigurationParent)null, new ConfigurationObjectSettings());
var y = Activator.CreateInstance(x.GetType(), (IPropertyDef)null, (IConfigurationRoot)null, (IConfigurationParent)null, new ConfigurationObjectSettings(), validators);
});

try
{
var y = Activator.CreateInstance(x.GetType(), (IPropertyDef)null, (IConfigurationRoot)null, (IConfigurationParent)null, new ConfigurationObjectSettings());
var y = Activator.CreateInstance(x.GetType(), (IPropertyDef)null, (IConfigurationRoot)null, (IConfigurationParent)null, new ConfigurationObjectSettings(), validators);
}
catch(TargetInvocationException ex)
{
Expand All @@ -132,7 +134,8 @@ public void TestDefaults()

Assert.Equal("DEFAULT_VALUE", fixture.RootElement.CustomValueB);

// The default here is true, but the value in the config is false. In earlier versions the default overrode the config value.
// The default here is true, but the value in the config is false. In earlier versions the default overrode
// the config value.
Assert.False(fixture.RootElement.TestDefaults);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace OpenCollar.Extensions.Configuration.TESTS
{
internal class ConfigurationObjectMock : ConfigurationObjectBase<IRootElement>
{
public ConfigurationObjectMock(IPropertyDef propertyDef, IConfigurationRoot configurationRoot, IConfigurationParent parent, ConfigurationObjectSettings settings) : base(propertyDef, configurationRoot, parent, settings)
public ConfigurationObjectMock(IPropertyDef propertyDef, IConfigurationRoot configurationRoot, IConfigurationParent parent, ConfigurationObjectSettings settings) : base(propertyDef, configurationRoot, parent, settings, System.Array.Empty<IConfigurationObjectValidator<IRootElement>>())
{
}
}
Expand Down

0 comments on commit 8d7eaef

Please sign in to comment.