From fca1fa9933a13d3e66179c4811b62ae32ffa731c Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Thu, 2 Mar 2023 14:26:52 +0000 Subject: [PATCH] update processing library + test --- src/Arma.Demo.Core/Processing/Intent.cs | 8 ++ src/Arma.Demo.Core/Processing/Package.cs | 3 + src/Arma.Demo.Core/Processing/Process.cs | 2 +- .../Processing/ProcessingExtensions.cs | 12 +++ src/Arma.Demo.Core/Processing/Resource.cs | 6 ++ tests/processing-test/PackageGenerator.cs | 10 +- tests/processing-test/ProcessGenerator.cs | 99 ++++++++++++------- tests/processing-test/ProcessingEngine.cs | 47 +++++++++ tests/processing-test/Program.cs | 21 +--- 9 files changed, 150 insertions(+), 58 deletions(-) create mode 100644 src/Arma.Demo.Core/Processing/Intent.cs create mode 100644 src/Arma.Demo.Core/Processing/ProcessingExtensions.cs create mode 100644 src/Arma.Demo.Core/Processing/Resource.cs create mode 100644 tests/processing-test/ProcessingEngine.cs diff --git a/src/Arma.Demo.Core/Processing/Intent.cs b/src/Arma.Demo.Core/Processing/Intent.cs new file mode 100644 index 0000000..d129122 --- /dev/null +++ b/src/Arma.Demo.Core/Processing/Intent.cs @@ -0,0 +1,8 @@ +namespace Arma.Demo.Core.Processing; +public enum Intent +{ + Approve, + Acquire, + Transfer, + Destroy +} \ No newline at end of file diff --git a/src/Arma.Demo.Core/Processing/Package.cs b/src/Arma.Demo.Core/Processing/Package.cs index 45b5349..a366ed8 100644 --- a/src/Arma.Demo.Core/Processing/Package.cs +++ b/src/Arma.Demo.Core/Processing/Package.cs @@ -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 Resources { get; set; } } \ No newline at end of file diff --git a/src/Arma.Demo.Core/Processing/Process.cs b/src/Arma.Demo.Core/Processing/Process.cs index ae90eea..d92afdf 100644 --- a/src/Arma.Demo.Core/Processing/Process.cs +++ b/src/Arma.Demo.Core/Processing/Process.cs @@ -2,6 +2,6 @@ namespace Arma.Demo.Core.Processing; public class Process { public string Name { get; set; } - + public List Tasks { get; set; } } \ No newline at end of file diff --git a/src/Arma.Demo.Core/Processing/ProcessingExtensions.cs b/src/Arma.Demo.Core/Processing/ProcessingExtensions.cs new file mode 100644 index 0000000..fae3de0 --- /dev/null +++ b/src/Arma.Demo.Core/Processing/ProcessingExtensions.cs @@ -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") + }; +} \ No newline at end of file diff --git a/src/Arma.Demo.Core/Processing/Resource.cs b/src/Arma.Demo.Core/Processing/Resource.cs new file mode 100644 index 0000000..115dcda --- /dev/null +++ b/src/Arma.Demo.Core/Processing/Resource.cs @@ -0,0 +1,6 @@ +namespace Arma.Demo.Core.Processing; +public class Resource +{ + public Guid Key => Guid.NewGuid(); + public string Name { get; set; } +} \ No newline at end of file diff --git a/tests/processing-test/PackageGenerator.cs b/tests/processing-test/PackageGenerator.cs index 5337e45..b6be9f8 100644 --- a/tests/processing-test/PackageGenerator.cs +++ b/tests/processing-test/PackageGenerator.cs @@ -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" } + } + }; } \ No newline at end of file diff --git a/tests/processing-test/ProcessGenerator.cs b/tests/processing-test/ProcessGenerator.cs index 0affb0e..3ea5915 100644 --- a/tests/processing-test/ProcessGenerator.cs +++ b/tests/processing-test/ProcessGenerator.cs @@ -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 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 + } + }; } \ No newline at end of file diff --git a/tests/processing-test/ProcessingEngine.cs b/tests/processing-test/ProcessingEngine.cs new file mode 100644 index 0000000..5a143bd --- /dev/null +++ b/tests/processing-test/ProcessingEngine.cs @@ -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" + ) + }; +} \ No newline at end of file diff --git a/tests/processing-test/Program.cs b/tests/processing-test/Program.cs index bccbba0..daeb3dd 100644 --- a/tests/processing-test/Program.cs +++ b/tests/processing-test/Program.cs @@ -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"); \ No newline at end of file +await new ProcessingEngine( + PackageGenerator.ApprovalPackage() +).Execute(); \ No newline at end of file