Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.suo
[Bb]in/
[Oo]bj/
TestResults/
TestResults/
_ReSharper.CoderMike.Autofac.EasySettings/
CoderMike.Autofac.EasySettings.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F8E8B9A5-B69F-4754-85F7-19192DA90712}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CoderMike.Autofac.EasySettings.Tests</RootNamespace>
<AssemblyName>CoderMike.Autofac.EasySettings.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.5.2.830, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.2.5.2.830\lib\NET40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Configuration">
<HintPath>..\packages\Autofac.2.5.2.830\lib\NET40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="EasySettingsModuleFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scenarios.cs" />
<Compile Include="SettingsSourceFixture.cs" />
<Compile Include="SimpleSettingsReaderFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoderMike.Autofac.EasySettings\CoderMike.Autofac.EasySettings.csproj">
<Project>{DB3BD92D-8EEF-4FE5-AA18-2FD52303DC18}</Project>
<Name>CoderMike.Autofac.EasySettings</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F8E8B9A5-B69F-4754-85F7-19192DA90712}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CoderMike.Autofac.EasySettings.Tests</RootNamespace>
<AssemblyName>CoderMike.Autofac.EasySettings.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.5.2.830, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.2.5.2.830\lib\NET40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Configuration">
<HintPath>..\packages\Autofac.2.5.2.830\lib\NET40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="EasySettingsModuleFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scenarios.cs" />
<Compile Include="SettingsSourceFixture.cs" />
<Compile Include="SimpleSettingsInjectorFixture.cs" />
<Compile Include="SimpleSettingsReaderFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoderMike.Autofac.EasySettings\CoderMike.Autofac.EasySettings.csproj">
<Project>{DB3BD92D-8EEF-4FE5-AA18-2FD52303DC18}</Project>
<Name>CoderMike.Autofac.EasySettings</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
25 changes: 22 additions & 3 deletions CoderMike.Autofac.EasySettings.Tests/Scenarios.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Specialized;
using System.Text;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -31,6 +32,23 @@ public void TestMethod1()
Assert.AreEqual("SomeKey", component.AkismetSettings.ApiKey);
Assert.IsTrue(component.BlogSettings.EnableComments);
Assert.IsTrue(component.BlogSettings.EnableHistory);
}

[TestMethod]
public void MultipleSettingsReaders()
{
var builder = new ContainerBuilder();
builder.RegisterModule(new EasySettingsModule(ConfigurationManager.AppSettings));
//extra settings provider
var secretItems = new NameValueCollection {{"Blog:SuperSecretItem", "SuperSecretValue"}};
builder.RegisterInstance(new SimpleSettingsReader(secretItems)).As<ISettingsReader>();

builder.RegisterType<FakeComponent>();

var container = builder.Build();
var component = container.Resolve<FakeComponent>();

Assert.AreEqual("SuperSecretValue", component.BlogSettings.SuperSecretItem);
}

class FakeComponent
Expand Down Expand Up @@ -61,8 +79,9 @@ class AkismetSettings

class BlogSettings
{
public bool EnableComments { get; private set; }
public bool EnableHistory { get; private set; }
public bool EnableComments { get; private set; }
public bool EnableHistory { get; private set; }
public string SuperSecretItem { get; private set; }
}
}
}
53 changes: 36 additions & 17 deletions CoderMike.Autofac.EasySettings.Tests/SettingsSourceFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Specialized;
using System.Text;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,18 +14,23 @@ public class SettingsSourceFixture
[TestMethod]
public void SettingsSourceAllowsResolvingOfSettingClasses()
{
var builder = new ContainerBuilder();
var reader = new FakeReader();
builder.RegisterInstance(reader).As<ISettingsReader>();
var builder = new ContainerBuilder();
var reader = new FakeReader();
var injector = new FakeInjector();
builder.RegisterInstance(reader).As<ISettingsReader>();
builder.RegisterInstance(injector).As<ISettingsInjector>();
builder.RegisterSource(new SettingsSource());

var container = builder.Build();
var fakeSettings = new FakeSettings();
reader.Settings = fakeSettings;
var fakeSettings = new NameValueCollection();
reader.Collection = fakeSettings;

var resolvedSettings = container.Resolve<FakeSettings>();
Assert.AreSame(fakeSettings, resolvedSettings);
Assert.IsTrue(reader.WasCalled);

Assert.IsNotNull(resolvedSettings);
Assert.IsTrue(injector.WasCalled);
Assert.IsNotNull(injector.Settings, "Settings sources were not passed to injector");
Assert.IsTrue(injector.Settings.Contains(reader));
}

class FakeSettings
Expand All @@ -34,15 +40,28 @@ class FakeSettings


class FakeReader : ISettingsReader
{
public object Settings { get; set; }
{
public NameValueCollection Collection { get; set; }
public bool WasCalled { get; set; }

public object Read(Type settingsType)
{
WasCalled = true;
return Settings;
}
}

public NameValueCollection Read()
{
WasCalled = true;
return Collection;
}
}

private class FakeInjector : ISettingsInjector
{
public bool WasCalled { get; set; }
public IEnumerable<ISettingsReader> Settings { get; set; }

public void Inject(object o, IEnumerable<ISettingsReader> settings)
{
WasCalled = true;
Settings = settings;
}

}
}
}
Loading