Skip to content

Commit

Permalink
Merge branch 'feature/station-rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
mavickers committed Aug 23, 2022
2 parents 056dda3 + c039a7c commit f783ad2
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 261 deletions.
18 changes: 18 additions & 0 deletions Cargo.Tests/Integration/Common/ContentModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ public class ContentModel2
{
public int IntVal { get; set; } = 0;
}

public interface IContentModel3
{
string String1 { get; set; }
string String2 { get; set; }
string String3 { get; set; }
int Int1 { get; set; }
}

public class ContentModel3 : IContentModel3
{
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string String4 { get; set; }
public int Int1 { get; set; }
public int Int2 { get; set; }
}
}
22 changes: 9 additions & 13 deletions Cargo.Tests/Integration/Finalize.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using LightPath.Cargo.Tests.Integration.Common;
using System.Linq;
using System.Runtime.Remoting;
using LightPath.Cargo.Tests.Integration.Common;
using LightPath.Cargo.Tests.Unit;
using Xunit;
using static LightPath.Cargo.Tests.Integration.Stations.Finalize;

namespace LightPath.Cargo.Tests.Integration
{
Expand All @@ -31,7 +27,7 @@ public void Scenario1()
Assert.False(bus.Package.IsErrored);
Assert.False(bus.Package.IsAborted);
Assert.Equal(29, content.IntVal);
Assert.Equal(3, bus.Package.Results.Count(r => r.WasSkipped));
Assert.Equal(0, bus.Package.Results.Count(r => r.IsAborting));
}

/// <summary>
Expand All @@ -54,9 +50,8 @@ public void Scenario2()

Assert.False(bus.Package.IsErrored);
Assert.True(bus.Package.IsAborted);
Assert.Equal(21, content.IntVal);
Assert.Equal(0, bus.Package.Results.Count(r => r.WasSkipped));
Assert.Equal(1, bus.Package.Results.Count(r => r.WasAborted));
Assert.Equal(1, content.IntVal);
Assert.Equal(1, bus.Package.Results.Count(r => r.IsAborting));
}

/// <summary>
Expand All @@ -79,8 +74,8 @@ public void Scenario3()
bus.Go(content);

Assert.True(bus.Package.IsErrored);
Assert.False(bus.Package.IsAborted);
Assert.Equal(29, content.IntVal);
Assert.True(bus.Package.IsAborted);
Assert.Equal(9, content.IntVal);

bus.WithNoAbortOnError().Go(content);

Expand All @@ -105,8 +100,9 @@ public void Scenario4()
bus.Go(content);

Assert.True(bus.Package.IsErrored);
Assert.False(bus.Package.IsAborted);
Assert.True(bus.Package.Results.Last().Exception is System.NotImplementedException);
Assert.True(bus.Package.IsAborted);
Assert.True(bus.Package.Results.Last().Exception is System.Reflection.TargetInvocationException);
Assert.True(bus.Package.Results.Last().Exception.InnerException is System.NotImplementedException);
}
}
}
28 changes: 15 additions & 13 deletions Cargo.Tests/Integration/Repeating.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LightPath.Cargo.Tests.Integration.Common;
using System.Linq;
using LightPath.Cargo.Tests.Integration.Common;
using Xunit;
using static LightPath.Cargo.Tests.Integration.Stations.Repeating;

Expand All @@ -14,9 +15,9 @@ public void Scenario1()
{
var content = new ContentModel2();
var bus = Bus.New<ContentModel2>()
.WithStation<Stations.Repeating.Station1>()
.WithStation<Stations.Repeating.Station2>()
.WithStation<Stations.Repeating.Station3>();
.WithStation<Station1>()
.WithStation<Station2>()
.WithStation<Station3>();

bus.Go(content);

Expand All @@ -33,14 +34,15 @@ public void Scenario2()
{
var content = new ContentModel2();
var bus = Bus.New<ContentModel2>()
.WithStation<Stations.Repeating.Station1>()
.WithStation<Stations.Repeating.Station4>()
.WithStation<Stations.Repeating.Station3>();
.WithStation<Station1>()
.WithStation<Station4>()
.WithStation<Station3>();

bus.Go(content);

Assert.False(bus.Package.IsAborted);
Assert.True(bus.Package.IsAborted);
Assert.True(bus.Package.IsErrored);
Assert.True(bus.Package.Results.Last().Exception is System.OverflowException);
Assert.Equal(101, content.IntVal);
}

Expand All @@ -54,11 +56,11 @@ public void Scenario3()
{
var content = new ContentModel2();
var bus = Bus.New<ContentModel2>()
.WithStation<Stations.Repeating.Station1>()
.WithStation<Stations.Repeating.Station2>()
.WithStation<Stations.Repeating.Station1>()
.WithStation<Stations.Repeating.Station2>()
.WithStation<Stations.Repeating.Station3>();
.WithStation<Station1>()
.WithStation<Station2>()
.WithStation<Station1>()
.WithStation<Station2>()
.WithStation<Station3>();

bus.Go(content);

Expand Down
43 changes: 40 additions & 3 deletions Cargo.Tests/Integration/Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public void Scenario1()
{
var content = new ContentModel1();
var bus = Bus.New<ContentModel1>()
.WithStation<Simple.Station1>()
.WithStation<Simple.Station2>()
.WithStation<Simple.Station3>();
.WithStation<Station1>()
.WithStation<Station2>()
.WithStation<Station3>();

bus.Go(content);

Expand All @@ -35,5 +35,42 @@ public void Scenario1()
Assert.False(bus.Package.IsAborted);
Assert.False(bus.Package.IsErrored);
}

/// <summary>
/// Scenario2 repeats Scenario1 but uses an interface for the bus
/// package type and implementations of the interface as station
/// package types.
/// </summary>
[Fact]
public void Scenario2()
{
var content = new ContentModel3();
var bus = Bus.New<IContentModel3>()
.WithStation<Station4>()
.WithStation<Station5>()
.WithStation<Station6>()
.WithStation<Station7>();

Assert.Throws<System.Reflection.TargetException>(() => bus.Go(content));
}

/// <summary>
/// Scenario2 repeats Scenario1 but uses an interface for the bus
/// package type and implementations of the interface as station
/// package types.
/// </summary>
[Fact]
public void Scenario3()
{
var content = new ContentModel3();
var bus = Bus.New<ContentModel3>()
.WithStation<Station4>()
.WithStation<Station5>()
.WithStation<Station6>()
.WithStation<Station7>();

// maybe someday we can mix interfaces/implementation in the stations
Assert.Throws<System.Reflection.TargetException>(() => bus.Go(content));
}
}
}
45 changes: 0 additions & 45 deletions Cargo.Tests/Integration/Skipping.cs

This file was deleted.

24 changes: 15 additions & 9 deletions Cargo.Tests/Integration/Stations/Finalize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,55 @@ public class Finalize
{
public class Station1 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal = 1;

return Station.Action.Next();
}
}

public class Station2 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Skip();
return Station.Action.Next();
}
}

public class Station3 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Abort();
return Station.Action.Abort();
}
}

public class Station4 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal += 4;

return Station.Action.Next();
}
}

public class Station5 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
throw new Exception("Testing");
}
}

public class FinalStation : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal += 20;

return Station.Action.Next();
}
}

Expand All @@ -59,7 +65,7 @@ public override void Process()
/// </summary>
public class FinalStationCrasher : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
throw new NotImplementedException();
}
Expand Down
16 changes: 10 additions & 6 deletions Cargo.Tests/Integration/Stations/Repeating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,41 @@ public class Repeating
{
public class Station1 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal = 1;

return Station.Action.Next();
}
}

public class Station2 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal += 2;

if (Contents.IntVal <= 100) Repeat();
return Contents.IntVal <= 100 ? Station.Action.Repeat() : Station.Action.Next();
}
}

public class Station3 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal += 3;

return Station.Action.Next();
}
}

public class Station4 : Station<ContentModel2>
{
public override void Process()
public override Station.Action Process()
{
Contents.IntVal += 1;

if (Contents.IntVal <= 1000) Repeat();
return Contents.IntVal <= 1000 ? Station.Action.Repeat() : Station.Action.Next();
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions Cargo.Tests/Integration/Stations/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,35 @@ public int AddThree(int val)

public class Station1 : Station<ContentModel1>
{
public override void Process()
public override Station.Action Process()
{
Contents.Int1 += 1;

return Station.Action.Next();
}
}

public class Station2 : Station<ContentModel1>
{
public override void Process()
public override Station.Action Process()
{
Contents.Int1 += 2;

return Station.Action.Next();
}
}

public class Station3 : Station<ContentModel1>
{
public override void Process()
public override Station.Action Process()
{
var service = GetService<Interface1>();

if (service == null) throw new Exception("Could not locate service");

Contents.Int1 = service.AddThree(Contents.Int1);

return Station.Action.Next();
}
}

Expand Down
Loading

0 comments on commit f783ad2

Please sign in to comment.