-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.IO; | ||
using System.Management.Automation; | ||
|
||
namespace PEURandom; | ||
|
||
[Cmdlet(VerbsLifecycle.Assert, "PEUAge")] | ||
[OutputType(typeof(Person))] | ||
public class AssertPEUAgeCmdlet : PSCmdlet | ||
{ | ||
[Parameter(Position = 0, ValueFromPipeline = true)] | ||
public IPerson Person; | ||
|
||
[Parameter()] | ||
public int Age = 18; | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
const int daysInAYear = 365; | ||
var ageSpan = DateTime.Now - Person.BirthDate; | ||
int personAge = (int)Math.Floor(ageSpan.TotalDays / daysInAYear); | ||
if (personAge < Age) { | ||
throw new InvalidDataException($"{Person.Name} is under the age of {Age}"); | ||
} | ||
|
||
WriteObject(Person); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
namespace PEURandom; | ||
using System; | ||
using System.Management.Automation; | ||
using System.Management.Automation; | ||
using LoremNET; | ||
|
||
record Person(string Name, DateTime BirthDate); | ||
namespace PEURandom; | ||
|
||
[Cmdlet(VerbsCommon.Get, "PEUAge")] | ||
[OutputType(typeof(Person))] | ||
public class GetPEURandomSentenceCmdlet : PSCmdlet | ||
public class GetPEUAgeCmdlet : PSCmdlet | ||
{ | ||
[Parameter(ValueFromPipeline = true)] | ||
[Parameter(Position = 0, ValueFromPipeline = true, Mandatory = true)] | ||
public string Name; | ||
|
||
protected override void ProcessRecord() | ||
{ | ||
DateTime birthDate = Lorem.DateTime(); | ||
|
||
WriteObject( | ||
new Person(Name, birthDate) | ||
GetPerson() | ||
); | ||
} | ||
|
||
Person GetPerson() { | ||
return new Person( | ||
Name, | ||
Lorem.DateTime() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace PEURandom; | ||
|
||
public interface IPerson { | ||
string Name { get; } | ||
DateTime BirthDate { get; } | ||
} | ||
|
||
record Person(string Name, DateTime BirthDate) : IPerson; |
Empty file.