Skip to content

Commit

Permalink
Added support for typed context.
Browse files Browse the repository at this point in the history
This closes #2008, closes #1772, closes #1594
  • Loading branch information
patriksvensson authored and devlead committed May 25, 2018
1 parent a1a6f06 commit 105eb54
Show file tree
Hide file tree
Showing 52 changed files with 2,799 additions and 1,289 deletions.
2 changes: 2 additions & 0 deletions src/Cake.Common/Tools/DotCover/DotCoverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal sealed class DotCoverContext : ICakeContext

public IToolLocator Tools => _context.Tools;

public ICakeDataResolver Data => _context.Data;

public FilePath FilePath => _runner.FilePath;

public ProcessSettings Settings => _runner.ProcessSettings;
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Common/Tools/OpenCover/OpenCoverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal sealed class OpenCoverContext : ICakeContext

public IToolLocator Tools => _context.Tools;

public ICakeDataResolver Data => _context.Data;

public FilePath FilePath => _runner.FilePath;

public ProcessSettings Settings => _runner.ProcessSettings;
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Common/Tools/SpecFlow/SpecFlowContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal sealed class SpecFlowContext : ICakeContext

public IToolLocator Tools => _context.Tools;

public ICakeDataResolver Data => _context.Data;

public FilePath FilePath => _runner.FilePath;

public ProcessSettings Settings => _runner.ProcessSettings;
Expand Down
4 changes: 3 additions & 1 deletion src/Cake.Core.Tests/Fixtures/CakeContextFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class CakeContextFixture
public IProcessRunner ProcessRunner { get; set; }
public IRegistry Registry { get; set; }
public IToolLocator Tools { get; set; }
public ICakeDataService Data { get; set; }

public CakeContextFixture()
{
Expand All @@ -30,12 +31,13 @@ public CakeContextFixture()
ProcessRunner = Substitute.For<IProcessRunner>();
Registry = Substitute.For<IRegistry>();
Tools = Substitute.For<IToolLocator>();
Data = Substitute.For<ICakeDataService>();
}

public CakeContext CreateContext()
{
return new CakeContext(FileSystem, Environment, Globber,
Log, Arguments, ProcessRunner, Registry, Tools);
Log, Arguments, ProcessRunner, Registry, Tools, Data);
}
}
}
4 changes: 3 additions & 1 deletion src/Cake.Core.Tests/Fixtures/CakeEngineFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class CakeEngineFixture
public IProcessRunner ProcessRunner { get; set; }
public ICakeContext Context { get; set; }
public IExecutionStrategy ExecutionStrategy { get; set; }
public ICakeDataService DataService { get; set; }

public CakeEngineFixture()
{
Expand All @@ -28,6 +29,7 @@ public CakeEngineFixture()
Arguments = Substitute.For<ICakeArguments>();
ProcessRunner = Substitute.For<IProcessRunner>();
ExecutionStrategy = new DefaultExecutionStrategy(Log);
DataService = Substitute.For<ICakeDataService>();

Context = Substitute.For<ICakeContext>();
Context.Arguments.Returns(Arguments);
Expand All @@ -40,7 +42,7 @@ public CakeEngineFixture()

public CakeEngine CreateEngine()
{
return new CakeEngine(Log);
return new CakeEngine(DataService, Log);
}
}
}
108 changes: 0 additions & 108 deletions src/Cake.Core.Tests/Unit/ActionTaskTests.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/Cake.Core.Tests/Unit/CakeContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public void Should_Throw_If_Process_Runner_Is_Null()
AssertEx.IsArgumentNullException(result, "processRunner");
}

[Fact]
public void Should_Throw_If_Registry_Is_Null()
{
// Given
var fixture = new CakeContextFixture();
fixture.Registry = null;

// When
var result = Record.Exception(() => fixture.CreateContext());

// Then
AssertEx.IsArgumentNullException(result, "registry");
}

[Fact]
public void Should_Throw_If_Tools_Are_Null()
{
Expand Down
24 changes: 24 additions & 0 deletions src/Cake.Core.Tests/Unit/CakeEngineActionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;

namespace Cake.Core.Tests.Unit
{
public sealed class CakeEngineActionsTests
{
public sealed class TheConstructor
{
[Fact]
public void Should_Throw_If_Data_Service_Is_Null()
{
// Given, When
var result = Record.Exception(() => new CakeEngineActions(null));

// Then
AssertEx.IsArgumentNullException(result, "data");
}
}
}
}
Loading

0 comments on commit 105eb54

Please sign in to comment.