Skip to content

Commit

Permalink
Lab3 Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
T-JGrote committed Jun 15, 2023
1 parent c57fe4e commit 258106f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
28 changes: 28 additions & 0 deletions src/Lab.3.Bouncer/AssertPEUAgeCmdlet.cs
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);
}
}
21 changes: 12 additions & 9 deletions src/Lab.3.Bouncer/GetPEUAgeCmdlet.cs
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()
);
}
}
10 changes: 10 additions & 0 deletions src/Lab.3.Bouncer/Person.cs
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.

0 comments on commit 258106f

Please sign in to comment.