Skip to content

Commit

Permalink
Merge pull request #23 from JaimeStill/service
Browse files Browse the repository at this point in the history
update processing library + test
  • Loading branch information
JaimeStill authored Mar 2, 2023
2 parents ead905a + fca1fa9 commit 37e068c
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 58 deletions.
8 changes: 8 additions & 0 deletions src/Arma.Demo.Core/Processing/Intent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Arma.Demo.Core.Processing;
public enum Intent
{
Approve,
Acquire,
Transfer,
Destroy
}
3 changes: 3 additions & 0 deletions src/Arma.Demo.Core/Processing/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ public class Package
{
public static Guid Key => Guid.NewGuid();
public string Name { get; set; }
public Intent Intent { get; set; }

public List<Resource> Resources { get; set; }
}
2 changes: 1 addition & 1 deletion src/Arma.Demo.Core/Processing/Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Arma.Demo.Core.Processing;
public class Process
{
public string Name { get; set; }

public List<ProcessTask> Tasks { get; set; }
}
12 changes: 12 additions & 0 deletions src/Arma.Demo.Core/Processing/ProcessingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Arma.Demo.Core.Processing;
public static class ProcessingExtensions
{
public static string ToActionString(this Intent intent) => intent switch
{
Intent.Acquire => "Acquisition",
Intent.Approve => "Approval",
Intent.Destroy => "Destruction",
Intent.Transfer => "Transfer",
_ => throw new ArgumentOutOfRangeException("An unexpected intent was provided")
};
}
6 changes: 6 additions & 0 deletions src/Arma.Demo.Core/Processing/Resource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Arma.Demo.Core.Processing;
public class Resource
{
public Guid Key => Guid.NewGuid();
public string Name { get; set; }
}
10 changes: 9 additions & 1 deletion tests/processing-test/PackageGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ namespace Processor;
public static class PackageGenerator
{
public static Package ApprovalPackage() =>
new() { Name = "Demo Approval" };
new() {
Name = "Demo Approval",
Intent = Intent.Approve,
Resources = new()
{
new() { Name = "Training Plan" },
new() { Name = "Servers" }
}
};
}
99 changes: 61 additions & 38 deletions tests/processing-test/ProcessGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,66 @@ public static Process ApprovalProcess() =>
new()
{
Name = "Demo Approval Process",
Tasks = new()
{
new()
{
Name = "Security Review",
Section = "Cybersecurity",
Step = 1,
Duration = 800
},
new()
{
Name = "Legal Review",
Section = "Legal",
Step = 2,
Duration = 1100
},
new()
{
Name = "Informal Review",
Section = "Operational Review Board",
Step = 3,
Duration = 500
},
new()
{
Name = "Formal Review",
Section = "Command Review Board",
Step = 4,
Duration = 1800
},
new()
{
Name = "Final Approval",
Section = "Headquarters Commander",
Step = 5,
Duration = 1000
}
}
Tasks = GenerateTasks()
};

public static Process AcquisitionProcess() =>
new()
{
Name = "Demo Acquisition Process",
Tasks = GenerateTasks()
};

public static Process TransferProcess() =>
new()
{
Name = "Demo Transfer Process",
Tasks = GenerateTasks()
};

public static Process DestructionProcess() =>
new()
{
Name = "Demo Destruction Process",
Tasks = GenerateTasks()
};

static List<ProcessTask> GenerateTasks() => new()
{
new()
{
Name = "Security Review",
Section = "Cybersecurity",
Step = 1,
Duration = 800
},
new()
{
Name = "Legal Review",
Section = "Legal",
Step = 2,
Duration = 1100
},
new()
{
Name = "Informal Review",
Section = "Operational Review Board",
Step = 3,
Duration = 500
},
new()
{
Name = "Formal Review",
Section = "Command Review Board",
Step = 4,
Duration = 1800
},
new()
{
Name = "Final Approval",
Section = "Headquarters Commander",
Step = 5,
Duration = 1000
}
};
}
47 changes: 47 additions & 0 deletions tests/processing-test/ProcessingEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Arma.Demo.Core.Processing;

namespace Processor;
public class ProcessingEngine
{
public Package Package { get; private set; }
public Process Process { get; private set; }

public ProcessingEngine(Package package)
{
Package = package;
Process = GenerateProcess(package);
}

public async Task Execute()
{
Console.WriteLine($"Submitting package {Package.Name} for {Package.Intent.ToActionString()}");
Console.WriteLine("Package Items:");

foreach (Resource resource in Package.Resources)
Console.WriteLine(resource.Name);

await Task.Delay(800);

Console.WriteLine($"Package {Package.Name} assigned process {Process.Name}");

foreach (ProcessTask task in Process.Tasks)
{
Console.WriteLine($"Current step: {task.Name}");
await Task.Delay(task.Duration);
Console.WriteLine($"Package {Package.Name} was approved by {task.Section}");
}

Console.WriteLine($"Package {Package.Name} was successfully approved");
}

static Process GenerateProcess(Package package) => package.Intent switch
{
Intent.Approve => ProcessGenerator.ApprovalProcess(),
Intent.Acquire => ProcessGenerator.AcquisitionProcess(),
Intent.Transfer => ProcessGenerator.TransferProcess(),
Intent.Destroy => ProcessGenerator.DestructionProcess(),
_ => throw new ArgumentOutOfRangeException(
"An unexpected intent was provided and no associated process could be found"
)
};
}
21 changes: 3 additions & 18 deletions tests/processing-test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
using Arma.Demo.Core.Processing;
using Processor;

Package package = PackageGenerator.ApprovalPackage();

Console.WriteLine($"Submitting package {package.Name} for approval");

await Task.Delay(1200);

Process process = ProcessGenerator.ApprovalProcess();

Console.WriteLine($"Package {package.Name} assigned process {process.Name}");

foreach (ProcessTask task in process.Tasks)
{
Console.WriteLine($"Current step: {task.Name}");
await Task.Delay(task.Duration);
Console.WriteLine($"Package {package.Name} was approved by {task.Section}");
}

Console.WriteLine($"Package {package.Name} was successfully approved");
await new ProcessingEngine(
PackageGenerator.ApprovalPackage()
).Execute();

0 comments on commit 37e068c

Please sign in to comment.