-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
e426efa
commit 8309bef
Showing
14 changed files
with
236 additions
and
11 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
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
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,11 @@ | ||
<Project> | ||
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build --> | ||
<PropertyGroup> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)Genealogy.snk</AssemblyOriginatorKeyFile> | ||
<PublicKey> | ||
00240000048000009400000006020000002400005253413100040000010001001919901f5df15129968f4c9323fe7d78773579b041f0cefd2f39d406133417c48e6c790381da7d59a51eb3b8b8844fddb6b480a1ab2a630d3f998b6f44c67d67ee94f0c7a7372d071fd47e602ed30be383ba07fce60f0a075935ae637ceca75e9179431eaed5bd3b14d7b50d8f3587902f07b5a78f7ab705370f937dc542bcbc | ||
</PublicKey> | ||
<PublicKeyToken>d55723e43f351317</PublicKeyToken> | ||
</PropertyGroup> | ||
</Project> |
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 @@ | ||
<Project> | ||
<!-- found in https://www.meziantou.net/declaring-internalsvisibleto-in-the-csproj.htm --> | ||
<Target Name="AddInternalsVisibleTo" BeforeTargets="BeforeCompile"> | ||
<!-- Add default suffix if there is no InternalsVisibleTo or InternalsVisibleToSuffix defined --> | ||
<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) == 0 AND @(InternalsVisibleTo->Count()) == 0"> | ||
<InternalsVisibleToSuffix Include=".Tests, PublicKey=$(PublicKey)" /> | ||
</ItemGroup> | ||
|
||
<!-- Handle InternalsVisibleTo --> | ||
<!-- <InternalsVisibleTo Include="CustomTest1" /> [assembly: InternalsVisibleTo("CustomTest1")] --> | ||
<!-- <InternalsVisibleTo Include="CustomTest2, PublicKey=abc" /> [assembly: InternalsVisibleTo("CustomTest2, PublicKey=abc")] --> | ||
<!-- <InternalsVisibleTo Include="$(AssemblyName).Custom" /> [assembly: InternalsVisibleTo("ClassLibrary1.Custom")] --> | ||
<ItemGroup Condition="'@(InternalsVisibleTo->Count())' > 0"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>%(InternalsVisibleTo.Identity)</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
|
||
<!-- Handle InternalsVisibleToSuffix --> | ||
<!-- <InternalsVisibleToSuffix Include=".Tests" /> [assembly: InternalsVisibleTo("ClassLibrary1.Tests")] --> | ||
<!-- <InternalsVisibleToSuffix Include=".FunctionalTests" /> [assembly: InternalsVisibleTo("ClassLibrary1.FunctionalTests")] --> | ||
<ItemGroup Condition="@(InternalsVisibleToSuffix->Count()) > 0"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> | ||
<_Parameter1>$(AssemblyName)%(InternalsVisibleToSuffix.Identity)</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
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,47 @@ | ||
using Genealogy; | ||
|
||
using static System.Runtime.InteropServices.JavaScript.JSType; | ||
|
||
namespace Genealogy.Tests; | ||
|
||
public class DateTest | ||
{ | ||
public static readonly TheoryData<string> ValidGedcomDates = | ||
[ | ||
"6 MAY 2001", | ||
"1977", | ||
"BET 1982 AND 1984", | ||
"EST 1752", | ||
"ABT JAN 1781", | ||
"AFT JAN 1781", | ||
"BEF JAN 1781", | ||
"FROM 1670 TO 1800", | ||
"FROM 1670 TO JULIAN 1800", | ||
"FROM JULIAN 1670 TO 1800", | ||
]; | ||
|
||
[Theory, MemberData(nameof(ValidGedcomDates))] | ||
public void ParseTest(string date) | ||
{ | ||
// Arrange | ||
// Act | ||
IDate result = Date.Parse(date); | ||
// Assert | ||
Assert.Equal(date, result.ToGedcom()); | ||
} | ||
|
||
public static readonly TheoryData<string> InvalidGedcomDates = | ||
[ | ||
null, | ||
string.Empty, | ||
"123", | ||
]; | ||
|
||
[Theory, MemberData(nameof(InvalidGedcomDates))] | ||
public void ParseThrowsGenealogyException(string date) | ||
{ | ||
// Arrange | ||
// Act & Assert | ||
Assert.Throws<GenealogyException>(() => Date.Parse(date)); | ||
} | ||
} |
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" /> | ||
<PackageReference Include="coverlet.msbuild" /> | ||
<PackageReference Include="GitHubActionsTestLogger" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Genealogy\Genealogy.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
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,25 @@ | ||
using Genealogy.DateImplementation; | ||
|
||
namespace Genealogy | ||
{ | ||
public class Date | ||
{ | ||
/// <summary> | ||
/// Parses the specified formal date string representing a GEDCOM date of any kind. | ||
/// </summary> | ||
/// <param name="date">The formal date string to parse.</param> | ||
/// <returns>A new instance defining interface <see cref="IDate"/></returns> | ||
/// <exception cref="GenealogyException"> | ||
/// Throw if the formal date string is null or empty. | ||
/// </exception> | ||
public static IDate Parse(string date) | ||
{ | ||
if (string.IsNullOrEmpty(date)) | ||
{ | ||
throw new GenealogyException("Invalid Date"); | ||
} | ||
|
||
return new SimpleDate(date); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Genealogy.DateImplementation | ||
{ | ||
internal class SimpleDate : IDate | ||
{ | ||
private string _date; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SimpleDate"/> class. | ||
/// </summary> | ||
/// <param name="date">The formal date string that describes a simple GEDCOM date.</param> | ||
internal SimpleDate(string date) | ||
{ | ||
ParseDate(date); | ||
} | ||
|
||
public string ToGedcom() | ||
{ | ||
return _date; | ||
} | ||
|
||
private void ParseDate(string date) | ||
{ | ||
// There is a minimum length of 4 characters | ||
if (date.Length < 4) | ||
{ | ||
throw new GenealogyException("Invalid Date: Must have at least YYYY"); | ||
} | ||
|
||
_date = date; | ||
} | ||
} | ||
} |
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,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,17 @@ | ||
using System; | ||
|
||
namespace Genealogy | ||
{ | ||
public class GenealogyException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GenealogyException"/> class. | ||
/// message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public GenealogyException(string message) | ||
: base(message) | ||
{ | ||
} | ||
} | ||
} |
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,9 @@ | ||
using System; | ||
|
||
namespace Genealogy | ||
{ | ||
public interface IDate | ||
{ | ||
string ToGedcom(); | ||
} | ||
} |
Binary file not shown.
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