Skip to content

Commit

Permalink
Added CleanupCode and testing to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Theauxm committed Jul 10, 2024
1 parent 5919fce commit 7fd2bde
Show file tree
Hide file tree
Showing 39 changed files with 543 additions and 360 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"CSharpier": {
"version": "0.26.7",
"commands": [
"dotnet-csharpier"
]
}
}
}
53 changes: 53 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "ChainSharp: Run CI/CD Test Suite"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- "main"
push:
branches:
- "main"

# Allow manual runs
workflow_dispatch: ~

env:
DOTNET_VERSION: '8.0.204' # The .NET SDK version to use

jobs:
cleanupcode:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install tools
run: dotnet tool restore --configfile ./nuget.config

- name: Cleanup Code
run: dotnet dotnet-csharpier --check .

test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Build Project
run: dotnet build --configuration Release /clp:ErrorsOnly

- name: Run Tests
run: dotnet test --configuration Release --no-restore /clp:ErrorsOnly
17 changes: 8 additions & 9 deletions ChainSharp.Tests/Examples/Brewery/Cider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

namespace ChainSharp.Tests.Examples.Brewery;

public class Cider(
IPrepare prepare,
IFerment ferment,
IBrew brew,
IBottle bottle) : Workflow<Ingredients, List<GlassBottle>>, ICider
public class Cider(IPrepare prepare, IFerment ferment, IBrew brew, IBottle bottle)
: Workflow<Ingredients, List<GlassBottle>>,
ICider
{
protected override async Task<Either<Exception, List<GlassBottle>>> RunInternal(Ingredients input)
=> this
.Chain<IPrepare, Ingredients, BrewingJug>(prepare, input, out var jug)
protected override async Task<Either<Exception, List<GlassBottle>>> RunInternal(
Ingredients input
) =>
this.Chain<IPrepare, Ingredients, BrewingJug>(prepare, input, out var jug)
.Chain<IFerment, BrewingJug>(ferment, jug)
.Chain<IBrew, BrewingJug>(brew, jug)
.Chain<IBottle, BrewingJug, List<GlassBottle>>(bottle, jug, out var bottles)
.Resolve(bottles);
}
}
4 changes: 1 addition & 3 deletions ChainSharp.Tests/Examples/Brewery/ICider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace ChainSharp.Tests.Examples.Brewery;

public interface ICider : IWorkflow<Ingredients, List<GlassBottle>>
{
}
public interface ICider : IWorkflow<Ingredients, List<GlassBottle>> { }
11 changes: 5 additions & 6 deletions ChainSharp.Tests/Examples/Brewery/Steps/Bottle/Bottle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ public class Bottle(IFerment ferment) : Step<BrewingJug, List<GlassBottle>>, IBo
public override async Task<List<GlassBottle>> Run(BrewingJug input)
{
if (!input.IsBrewed)
throw new WorkflowException("We don't want to bottle un-brewed beer! What are we, trying to make poison?");
throw new WorkflowException(
"We don't want to bottle un-brewed beer! What are we, trying to make poison?"
);

// 16 oz bottles
var bottlesNeeded = input.Gallons / 8;

var filledBottles = new List<GlassBottle>();
for (var i = 0; i < bottlesNeeded; i++)
{
filledBottles.Add(new GlassBottle()
{
HasCider = true
});
filledBottles.Add(new GlassBottle() { HasCider = true });
}

return filledBottles;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace ChainSharp.Tests.Examples.Brewery.Steps.Bottle;
public class GlassBottle
{
public bool HasCider { get; set; }
}
}
4 changes: 1 addition & 3 deletions ChainSharp.Tests/Examples/Brewery/Steps/Bottle/IBottle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Bottle;

public interface IBottle : IStep<BrewingJug, List<GlassBottle>>
{
}
public interface IBottle : IStep<BrewingJug, List<GlassBottle>> { }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Bottle;

public class StealCinnamonAndRunAway: Step<BrewingJug, List<GlassBottle>>
public class StealCinnamonAndRunAway : Step<BrewingJug, List<GlassBottle>>
{
public override async Task<List<GlassBottle>> Run(BrewingJug input)
{
Expand All @@ -14,10 +14,10 @@ public override async Task<List<GlassBottle>> Run(BrewingJug input)
input.HasCinnamonSticks = false;
var emptyBottles = new List<GlassBottle>()
{
new() {},
new() {},
new() {},
new() { },
new() { },
new() { },
};
return emptyBottles;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Bottle;

public class TripTryingToSteal: Step<BrewingJug, List<GlassBottle>>
public class TripTryingToSteal : Step<BrewingJug, List<GlassBottle>>
{
public override async Task<List<GlassBottle>> Run(BrewingJug input)
{
// We try to steal the cinnamon, but we trip and fall and GO LEFT
throw new WorkflowException("You done messed up now, son.");
}
}
}
4 changes: 2 additions & 2 deletions ChainSharp.Tests/Examples/Brewery/Steps/Brew/Brew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public override async Task<Unit> Run(BrewingJug input)
{
if (!input.IsFermented)
throw new WorkflowException("We cannot brew our Cider before it is fermented!");

// Pretend that we waited 2 days...
input.IsBrewed = true;

return Unit.Default;
}
}
}
4 changes: 1 addition & 3 deletions ChainSharp.Tests/Examples/Brewery/Steps/Brew/IBrew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Brew;

public interface IBrew : IStep<BrewingJug, Unit>
{
}
public interface IBrew : IStep<BrewingJug, Unit> { }
4 changes: 2 additions & 2 deletions ChainSharp.Tests/Examples/Brewery/Steps/Ferment/Ferment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<Either<WorkflowException, Unit>> AddCinnamonSticks(BrewingJug

return Unit.Default;
}

public async Task<Either<WorkflowException, Unit>> AddYeast(BrewingJug jug)
{
if (jug.Ingredients.Yeast <= 0)
Expand All @@ -41,4 +41,4 @@ public async Task<Either<WorkflowException, Unit>> AddYeast(BrewingJug jug)

return Unit.Default;
}
}
}
4 changes: 1 addition & 3 deletions ChainSharp.Tests/Examples/Brewery/Steps/Ferment/IFerment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Ferment;

public interface IFerment : IStep<BrewingJug, Unit>
{
}
public interface IFerment : IStep<BrewingJug, Unit> { }
12 changes: 6 additions & 6 deletions ChainSharp.Tests/Examples/Brewery/Steps/Prepare/BrewingJug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ namespace ChainSharp.Tests.Examples.Brewery.Steps.Prepare;
public class BrewingJug : IBrewingJug
{
public required int Gallons { get; set; }

public int Yeast { get; set; }

public bool HasCinnamonSticks { get; set; }

public bool IsFermented { get; set; }

public bool IsBrewed { get; set; }

public Ingredients Ingredients { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public interface IBrewingJug
bool IsFermented { get; set; }
bool IsBrewed { get; set; }
Ingredients Ingredients { get; set; }
}
}
4 changes: 1 addition & 3 deletions ChainSharp.Tests/Examples/Brewery/Steps/Prepare/IPrepare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Prepare;

public interface IPrepare : IStep<Ingredients, BrewingJug>
{
}
public interface IPrepare : IStep<Ingredients, BrewingJug> { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ namespace ChainSharp.Tests.Examples.Brewery.Steps.Prepare;
public class Ingredients
{
public required int Apples { get; set; }

public required int BrownSugar { get; set; }

public required int Cinnamon { get; set; }

public required int Yeast { get; set; }
}
}
4 changes: 2 additions & 2 deletions ChainSharp.Tests/Examples/Brewery/Steps/Prepare/Meditate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace ChainSharp.Tests.Examples.Brewery.Steps.Prepare;

internal class Meditate: Step<Unit, Unit>
internal class Meditate : Step<Unit, Unit>
{
public override async Task<Unit> Run(Unit input)
{
// You silently consider what you should brew
return unit;
}
}
}
16 changes: 8 additions & 8 deletions ChainSharp.Tests/Examples/Brewery/Steps/Prepare/Prepare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public override async Task<BrewingJug> Run(Ingredients input)

if (gallonAppleJuice.IsLeft)
throw gallonAppleJuice.Swap().ValueUnsafe();

return new BrewingJug()
{
Gallons = gallonAppleJuice.ValueUnsafe(),
Ingredients = input
};

return new BrewingJug() { Gallons = gallonAppleJuice.ValueUnsafe(), Ingredients = input };
}

private async Task<Either<WorkflowException, int>> Boil(int gallonWater, int numApples, int ozBrownSugar)
private async Task<Either<WorkflowException, int>> Boil(
int gallonWater,
int numApples,
int ozBrownSugar
)
{
return gallonWater + (numApples / 8) + (ozBrownSugar / 128);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public override async Task<IBrewingJug> Run(Ingredients input)

if (gallonAppleJuice.IsLeft)
throw gallonAppleJuice.Swap().ValueUnsafe();

return new BrewingJug()
{
Gallons = gallonAppleJuice.ValueUnsafe(),
Ingredients = input
};

return new BrewingJug() { Gallons = gallonAppleJuice.ValueUnsafe(), Ingredients = input };
}

private async Task<Either<WorkflowException, int>> Boil(int gallonWater, int numApples, int ozBrownSugar)
private async Task<Either<WorkflowException, int>> Boil(
int gallonWater,
int numApples,
int ozBrownSugar
)
{
return gallonWater + (numApples / 8) + (ozBrownSugar / 128);
}
}
}
11 changes: 3 additions & 8 deletions ChainSharp.Tests/TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

namespace ChainSharp.Tests;


[SetUpFixture]
public class TestFixture
{
[OneTimeSetUp]
public async Task RunBeforeAnyTests()
{
}
public async Task RunBeforeAnyTests() { }

[OneTimeTearDown]
public async Task RunAfterAnyTests()
{
}
}
public async Task RunAfterAnyTests() { }
}
2 changes: 1 addition & 1 deletion ChainSharp.Tests/TestSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public virtual async Task TestSetUp()

[TearDown]
public async Task TestTearDown() { }
}
}
Loading

0 comments on commit 7fd2bde

Please sign in to comment.