Skip to content

Commit

Permalink
Merge branch 'GetChocolatey' into stable
Browse files Browse the repository at this point in the history
* GetChocolatey:
  (chocolateyGH-109) GetChocolatey can now get chocolatey
  (chocolateyGH-109) ConfigurationOptions explicit reset
  (chocolateyGH-109)(log) Set file appender if output dir is provided
  (chocolateyGH-109) Container - move initialize to lazy
  • Loading branch information
ferventcoder committed Feb 25, 2015
2 parents 4b0478f + 405644e commit 33939dc
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void Main(string[] args)
Bootstrap.initialize();
Bootstrap.startup();

var container = SimpleInjectorContainer.initialize();
var container = SimpleInjectorContainer.Container;
var config = container.GetInstance<ChocolateyConfiguration>();
var fileSystem = container.GetInstance<IFileSystem>();

Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey.tests.integration/NUnitSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NUnitSetup : tests.NUnitSetup

public override void BeforeEverything()
{
Container = SimpleInjectorContainer.initialize();
Container = SimpleInjectorContainer.Container;
fix_application_parameter_variables(Container);
var config = Container.GetInstance<ChocolateyConfiguration>();
var force = config.Force;
Expand Down
82 changes: 82 additions & 0 deletions src/chocolatey.tests/GetChocolateySpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.tests
{
using log4net;
using Should;

public class GetChocolateySpecs
{
public abstract class GetChocolateySpecsBase : TinySpec
{
public override void Context()
{
}
}

public class when_getting_chocolatey : GetChocolateySpecsBase
{
private GetChocolatey _chocolatey;

public override void Because()
{
_chocolatey = Lets.GetChocolatey();
}

[Fact]
public void should_get_chocolotey()
{
_chocolatey.ShouldNotBeNull();
}

[Fact]
public void should_conigure_log4net()
{
LogManager.GetRepository().Configured.ShouldBeTrue();
}
}

public class when_getting_chocolatey_more_than_once : GetChocolateySpecsBase
{
private GetChocolatey _chocolatey1;
private GetChocolatey _chocolatey2;

public override void Because()
{
_chocolatey1 = Lets.GetChocolatey();
_chocolatey2 = Lets.GetChocolatey();
}

[Fact]
public void should_get_instantiated_chocolotey1()
{
_chocolatey1.ShouldNotBeNull();
}

[Fact]
public void should_get_instantiated_chocolotey2()
{
_chocolatey2.ShouldNotBeNull();
}

[Fact]
public void should_have_distinct_configurations()
{
_chocolatey1.GetConfiguration().ShouldNotEqual(_chocolatey2.GetConfiguration());
}
}
}
}
5 changes: 5 additions & 0 deletions src/chocolatey.tests/chocolatey.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.XmlTransform, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
</Reference>
Expand All @@ -57,6 +61,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GetChocolateySpecs.cs" />
<Compile Include="infrastructure.app\attributes\CommandForAttributeSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyApiKeyCommandSpecs.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyFeatureCommandSpecs.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public abstract class ConfigurationOptionsSpecBase : TinySpec
public override void Context()
{
ConfigurationOptions.initialize_with(new Lazy<IConsole>(() => console.Object));
ConfigurationOptions.reset_options();
console.Setup((c) => c.Error).Returns(writer);
}

Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net40" />
<package id="NuGet.Core" version="2.8.2" targetFramework="net40" />
Expand Down
6 changes: 4 additions & 2 deletions src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ public class GetChocolatey
/// </summary>
public GetChocolatey()
{
Log4NetAppenderConfiguration.configure();
Bootstrap.initialize();
_configuration = new ChocolateyConfiguration();
_container = SimpleInjectorContainer.initialize();
_container = SimpleInjectorContainer.Container;
_fileSystem = _container.GetInstance<IFileSystem>();

set_defaults();
}

private void set_defaults()
{
ConfigurationBuilder.set_up_configuration(null, _configuration, _fileSystem, _container.GetInstance<IXmlService>(), null);
ConfigurationBuilder.set_up_configuration(new List<string>(), _configuration, _fileSystem, _container.GetInstance<IXmlService>(), null);
Config.initialize_with(_configuration);

_configuration.PromptForConfirmation = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static IEnvironment Environment
public static void set_up_configuration(IList<string> args, ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action<string> notifyWarnLoggingAction)
{
set_file_configuration(config, fileSystem, xmlService, notifyWarnLoggingAction);
ConfigurationOptions.reset_options();
set_global_options(args, config);
set_environment_options(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static void initialize_with(Lazy<IConsole> console)
_console = console;
}

public static void reset_options()
{
_optionSet.Clear();
}

private static IConsole Console
{
get { return _console.Value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public sealed class Log4NetAppenderConfiguration
private static bool _alreadyConfiguredFileAppender;

/// <summary>
/// Pulls xmlconfiguration from embedded location and applies it. Then it configures a file appender to the specified output directory.
/// Pulls xmlconfiguration from embedded location and applies it.
/// Then it configures a file appender to the specified output directory if one is provided.
/// </summary>
/// <param name="outputDirectory">The output directory.</param>
public static void configure(string outputDirectory)
public static void configure(string outputDirectory = null)
{
var assembly = Assembly.GetExecutingAssembly();
var resource = ApplicationParameters.Log4NetConfigurationResource;
Expand All @@ -49,7 +50,11 @@ public static void configure(string outputDirectory)
Stream xmlConfigStream = assembly.get_manifest_stream(resource);

XmlConfigurator.Configure(xmlConfigStream);
set_file_appender(outputDirectory);

if (outputDirectory != null)
{
set_file_appender(outputDirectory);
}

_logger.DebugFormat("Configured {0} from assembly {1}", resource, assembly.FullName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace chocolatey.infrastructure.registration
/// </summary>
public static class SimpleInjectorContainer
{
private static readonly Lazy<Container> _container = new Lazy<Container>(() => new Container());
private static readonly Lazy<Container> _container = new Lazy<Container>(initialize);

/// <summary>
/// Gets the container.
Expand All @@ -37,25 +37,21 @@ public static Container Container
/// <summary>
/// Initializes the container
/// </summary>
public static Container initialize()
private static Container initialize()
{
Container.Options.AllowOverridingRegistrations = true;
var originalConstructorResolutionBehavior = Container.Options.ConstructorResolutionBehavior;
Container.Options.ConstructorResolutionBehavior = new SimpleInjectorContainerResolutionBehavior(originalConstructorResolutionBehavior);
var container = new Container();
container.Options.AllowOverridingRegistrations = true;
var originalConstructorResolutionBehavior = container.Options.ConstructorResolutionBehavior;
container.Options.ConstructorResolutionBehavior = new SimpleInjectorContainerResolutionBehavior(originalConstructorResolutionBehavior);

initialize_container(Container);
var binding = new ContainerBinding();
binding.RegisterComponents(container);

#if DEBUG
Container.Verify();
container.Verify();
#endif

return Container;
}

private static void initialize_container(Container container)
{
var binding = new ContainerBinding();
binding.RegisterComponents(container);
return container;
}
}
}

0 comments on commit 33939dc

Please sign in to comment.