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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
*.suo
[Bb]in/
[Oo]bj/
TestResults/
TestResults/
_ReSharper*
packages/
*.suo
*.user
*.sln.docstates
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
136 changes: 136 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
2 changes: 1 addition & 1 deletion CoderMike.Autofac.EasySettings.1.0.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>Constructing settings classes that get read out of AppSettings on demand</description>
<summary />
<dependencies>
<dependency id="Autofac" version="2.5" />
<dependency id="Autofac" version="3.1.1" />
</dependencies>
</metadata>
</package>
16 changes: 12 additions & 4 deletions CoderMike.Autofac.EasySettings.Tests/App.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<clear/>
<add key="Email:Port" value="2345"/>
<add key="Email:Ssl" value="true"/>
<clear />
<add key="Email:Port" value="2345" />
<add key="Email:Ssl" value="true" />
<add key="Email:Username" value="MyUserName" />
<add key="Akismet:ApiKey" value="SomeKey" />
<add key="Blog:EnableComments" value="true" />
<add key="Blog:EnableHistory" value="true" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Autofac;

using CoderMike.Autofac.EasySettings.Tests.SettingsReading;

using Xunit;

namespace CoderMike.Autofac.EasySettings.Tests.AutofacConfiguration
{
public class DirectProviderSetupFixture
{
private readonly TestSettingsProvider _provider;

public DirectProviderSetupFixture()
{
_provider = new TestSettingsProvider(new Dictionary<string, string>
{
{"First:Value", "things"}
});
}

[Fact]
public void ModuleInstallsSimpleSettingsReaderByDefault()
{
var module = new EasySettingsModule(_provider);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

Assert.NotNull(reader);
Assert.IsType<SimpleSettingsReader>(reader);
}

[Fact]
public void ModuleInstallsSettingsSource()
{
var module = new EasySettingsModule(_provider);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
Assert.NotEmpty(container.ComponentRegistry.Sources.OfType<SettingsSource>());
}

[Fact]
public void ConfigurationValuesLoadedFromSuppliedCollection()
{
var module = new EasySettingsModule(_provider);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

var instance = reader.Read<FirstSettings>();

Assert.Equal("things", instance.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Linq;

using Autofac;

using CoderMike.Autofac.EasySettings.Tests.SettingsReading;

using Xunit;

namespace CoderMike.Autofac.EasySettings.Tests.AutofacConfiguration
{
public class FileSetupFixture
{
[Fact]
public void ModuleInstallsSimpleSettingsReaderByDefault()
{
var module = new EasySettingsModule("MultipleEntries.json");

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

Assert.NotNull(reader);
Assert.IsType<SimpleSettingsReader>(reader);
}

[Fact]
public void ModuleInstallsSettingsSource()
{
var module = new EasySettingsModule("MultipleEntries.json");

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
Assert.NotEmpty(container.ComponentRegistry.Sources.OfType<SettingsSource>());
}

[Fact]
public void ConfigurationValuesLoadedFromSuppliedCollection()
{
var module = new EasySettingsModule("MultipleEntries.json");

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

var instance = reader.Read<FirstSettings>();

Assert.Equal("blah", instance.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Specialized;
using System.Linq;

using Autofac;

using CoderMike.Autofac.EasySettings.Tests.SettingsReading;

using Xunit;

namespace CoderMike.Autofac.EasySettings.Tests.AutofacConfiguration
{
public class NameValueCollectionSetupFixture
{
[Fact]
public void ModuleInstallsSimpleSettingsReaderByDefault()
{
var settings = new NameValueCollection();
var module = new EasySettingsModule(settings);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

Assert.NotNull(reader);
Assert.IsType<SimpleSettingsReader>(reader);
}

[Fact]
public void ModuleInstallsSettingsSource()
{
var settings = new NameValueCollection();
var module = new EasySettingsModule(settings);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
Assert.NotEmpty(container.ComponentRegistry.Sources.OfType<SettingsSource>());
}

[Fact]
public void ConfigurationValuesLoadedFromSuppliedCollection()
{
var settings = new NameValueCollection
{
{ "First:Value", "something"}
};
var module = new EasySettingsModule(settings);

var builder = new ContainerBuilder();
builder.RegisterModule(module);

var container = builder.Build();
var reader = container.Resolve<ISettingsReader>();

var instance = reader.Read<FirstSettings>();

Assert.Equal("something", instance.Value);
}
}
}
Loading