Skip to content

Commit

Permalink
(GH-3946) Add ISetupContext to Frosting lifetime
Browse files Browse the repository at this point in the history
* fixes #3946
  • Loading branch information
devlead committed Oct 29, 2022
1 parent bd4ad10 commit a14dc69
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Cake.Frosting.Tests/Fakes/FakeLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class FakeLifetime : FrostingLifetime
public int SetupCount { get; set; }
public int TeardownCount { get; set; }

public override void Setup(ICakeContext context)
public override void Setup(ICakeContext context, ISetupContext info)
{
SetupCount++;
}
Expand Down
26 changes: 9 additions & 17 deletions src/Cake.Frosting/FrostingLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public abstract class FrostingLifetime<TContext> : IFrostingLifetime
/// If setup fails, no tasks will be executed but teardown will be performed.
/// </summary>
/// <param name="context">The context.</param>
public abstract void Setup(TContext context);
/// <param name="info">The setup information.</param>
public abstract void Setup(TContext context, ISetupContext info);

/// <summary>
/// This method is executed after all tasks have been run.
Expand All @@ -38,29 +39,20 @@ public abstract class FrostingLifetime<TContext> : IFrostingLifetime
/// <param name="info">The teardown information.</param>
public abstract void Teardown(TContext context, ITeardownContext info);

/// <inheritdoc/>
void IFrostingSetup.Setup(ICakeContext context)
/// <inheritdoc cref="IFrostingSetup" />
void IFrostingSetup.Setup(ICakeContext context, ISetupContext info)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(info);

Setup((TContext)context);
Setup((TContext)context, info);
}

/// <inheritdoc/>
void IFrostingTeardown.Teardown(ICakeContext context, ITeardownContext info)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (info is null)
{
throw new ArgumentNullException(nameof(info));
}
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(info);

Teardown((TContext)context, info);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Cake.Frosting/FrostingSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public abstract class FrostingSetup<TContext> : IFrostingSetup
/// If setup fails, no tasks will be executed but teardown will be performed.
/// </summary>
/// <param name="context">The context.</param>
public abstract void Setup(TContext context);
/// <param name="info">The setup infortation.</param>
public abstract void Setup(TContext context, ISetupContext info);

void IFrostingSetup.Setup(ICakeContext context)
/// <inheritdoc cref="IFrostingSetup"/>
void IFrostingSetup.Setup(ICakeContext context, ISetupContext info)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(info);

Setup((TContext)context);
Setup((TContext)context, info);
}
}
}
3 changes: 2 additions & 1 deletion src/Cake.Frosting/IFrostingLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface IFrostingSetup
/// If setup fails, no tasks will be executed but teardown will be performed.
/// </summary>
/// <param name="context">The context.</param>
void Setup(ICakeContext context);
/// <param name="info">The setup information.</param>
void Setup(ICakeContext context, ISetupContext info);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Frosting/Internal/FrostingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void ConfigureLifetime()
if (_setup != null)
{
_log.Debug("Registering setup: {0}", _setup.GetType().Name);
_engine.RegisterSetupAction(info => _setup.Setup(_context));
_engine.RegisterSetupAction(info => _setup.Setup(_context, info));
}

if (_teardown != null)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cake.Frosting/build/Lifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public sealed class Lifetime : FrostingLifetime<Context>
{
public override void Setup(Context context)
public override void Setup(Context context, ISetupContext info)
{
context.Information("Setting things up...");
}
Expand Down

0 comments on commit a14dc69

Please sign in to comment.