Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: C#-ify #12

Merged
merged 9 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/PreRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
with:
useConfigFile: true
- name: Pack
run: dotnet pack --no-build /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/johnkors/NoCommonsNET/releases/tag/${{ steps.gitversion.outputs.NuGetVersionV2 }}" -o ./releases
run: dotnet pack --no-build /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }}-${{ steps.gitversion.outputs.ShortSha }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/johnkors/NoCommonsNET/releases/tag/${{ steps.gitversion.outputs.NuGetVersionV2 }}" -o ./releases
- name: Publish
run: dotnet nuget push ./releases/NoCommons.${{ steps.gitversion.outputs.NuGetVersionV2 }}.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
run: dotnet nuget push ./releases/NoCommons.${{ steps.gitversion.outputs.NuGetVersionV2 }}-${{ steps.gitversion.outputs.ShortSha }}.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
- run: git log $(git describe --tags --abbrev=0)..HEAD --oneline
- name: Log commit messages since last release
id: releasenotes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
useConfigFile: true
- name: Pack
run: dotnet pack --no-build /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} -o ./releases
run: dotnet pack --no-build /p:Version=${{ steps.gitversion.outputs.NuGetVersionV2 }} /p:InformationalVersion=${{ steps.gitversion.outputs.informationalVersion }} /p:PackageReleaseNotes="https://github.com/johnkors/NoCommonsNET/releases/tag/${{ steps.gitversion.outputs.NuGetVersionV2 }}" -o ./releases
- name: Publish
run: dotnet nuget push ./releases/NoCommons.${{ steps.gitversion.outputs.NuGetVersionV2 }}.nupkg -k=${{ secrets.NUGETORGAPIKEY }} -s=nuget.org
- run: git log $(git describe --tags --abbrev=0)..HEAD --oneline
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dev requirements
- .NET 5 SDK

# Workflow
- Open a issue
- If discussion leads to agreeing to a change by you, create a feature branch: `feature/adds-my-thing`
- Pull Requests should target `master`
- Pre-releases are deployed to nuget.org on demand
3 changes: 3 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ branches:
tag: ""
feature:
regex: ^features?[/-]|(?!^master$|^(hotfix|bugfix)(es)?[/-]|^support[/-]|(^(pull|pull\-requests|pr)[/-]))(^.*$)
mode: ContinuousDeployment
tag: "feature"
pull-request:
tag: "pull"
mode: ContinuousDeployment
hotfix:
regex: ^(hotfix|bugfix)(es)?[/-]
mode: ContinuousDeployment
increment: Inherit
tag: "bug"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2010-2016 Google, Inc. http://angularjs.org
Copyright (c) 2010-2016 John Korsnes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion NoCommons.Tests/Banking/KidnummerValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class KidnummerValidatorTests
private const string KIDNUMMER_INVALID_LENGTH_SHORT = "1";
private const string KIDNUMMER_INVALID_LENGTH_LONG = "12345678901234567890123456";

protected void assertMessageContains(ArgumentException e, String message)
protected void assertMessageContains(ArgumentException e, string message)
{
Assert.Contains(message, e.Message);
}
Expand Down
26 changes: 13 additions & 13 deletions NoCommons.Tests/Date/NorwegianDateUtilTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NorwegianDateUtilTest
public void testAdd2DaysWithinSameWeek()
{
var date = new DateTime(2007,3,21);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 2);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 2);

Assert.Equal(23, newDate.Day);
}
Expand All @@ -21,7 +21,7 @@ public void testAdd2DaysWithinSameWeek()
public void testAdd2DaysToLastDayOfMonth()
{
var date = new DateTime(2007, 2, 28);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 2);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 2);

Assert.Equal(2, newDate.Day);
Assert.Equal(3, newDate.Month);
Expand All @@ -31,7 +31,7 @@ public void testAdd2DaysToLastDayOfMonth()
public void testAdd5DaysWithNoHolidays()
{
var date = new DateTime(2007, 03, 21);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 5);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 5);

Assert.Equal(28, newDate.Day);
}
Expand All @@ -40,7 +40,7 @@ public void testAdd5DaysWithNoHolidays()
public void testAdd5DaysBeforeEasterHoliday()
{
var date = new DateTime(2007, 4, 4);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 5);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 5);

Assert.Equal(16, newDate.Day);
}
Expand All @@ -49,7 +49,7 @@ public void testAdd5DaysBeforeEasterHoliday()
public void testAdd5DaysBeforeNationalDay()
{
var date = new DateTime(2007, 5, 16);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 5);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 5);

Assert.Equal(24, newDate.Day);
}
Expand All @@ -58,7 +58,7 @@ public void testAdd5DaysBeforeNationalDay()
public void testAdd5DaysBeforeChristmas()
{
var date = new DateTime(2007, 12, 21);
var newDate = NorwegianDateUtil.addWorkingDaysToDate(date, 5);
var newDate = NorwegianDateUtil.AddWorkingDaysToDate(date, 5);

Assert.Equal(2, newDate.Day);
Assert.Equal(1, newDate.Month);
Expand All @@ -68,10 +68,10 @@ public void testAdd5DaysBeforeChristmas()
[Fact]
public void testWorkingDays()
{
Assert.False(NorwegianDateUtil.isWorkingDay(new DateTime(2007,3,25)), "Sunday not working day");
Assert.True(NorwegianDateUtil.isWorkingDay(new DateTime(2007, 3, 26)), "Monday is working day");
Assert.False(NorwegianDateUtil.isWorkingDay(new DateTime(2007,1,1)), "New years day not working day");
Assert.False(NorwegianDateUtil.isWorkingDay(new DateTime(2007,4,8)), "Easter day not working day");
Assert.False(NorwegianDateUtil.IsWorkingDay(new DateTime(2007,3,25)), "Sunday not working day");
Assert.True(NorwegianDateUtil.IsWorkingDay(new DateTime(2007, 3, 26)), "Monday is working day");
Assert.False(NorwegianDateUtil.IsWorkingDay(new DateTime(2007,1,1)), "New years day not working day");
Assert.False(NorwegianDateUtil.IsWorkingDay(new DateTime(2007,4,8)), "Easter day not working day");
}

[Fact]
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testVariousNorwegianHolidays()
public void testGetAllNorwegianHolidaysForYear()
{
const string format = "dd.MM.yyyy";
var holidays = NorwegianDateUtil.getHolidays(2008);
var holidays = NorwegianDateUtil.GetHolidays(2008);
Assert.Equal(12, holidays.Count());
Assert.Equal("01.01.2008", holidays.ElementAt(0).ToString(format));
Assert.Equal("16.03.2008", holidays.ElementAt(1).ToString(format));
Expand All @@ -125,10 +125,10 @@ public void testGetAllNorwegianHolidaysForYear()
Assert.Equal("26.12.2008", holidays.ElementAt(11).ToString(format));
}

private void checkHoliday(String date)
private void checkHoliday(string date)
{
var dateTime = DateTime.ParseExact(date, "dd.MM.yyyy", CultureInfo.InvariantCulture);
Assert.True(NorwegianDateUtil.isHoliday(dateTime));
Assert.True(NorwegianDateUtil.IsHoliday(dateTime));
}
}
}
16 changes: 8 additions & 8 deletions NoCommons.Tests/Person/FodselsnummerCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ public FodselsnummerCalculatorTest()
[Fact]
public void testGetFodselsnummerForDateAndGender()
{
List<Fodselsnummer> options = FodselsnummerCalculator.getFodselsnummerForDateAndGender(date, KJONN.KVINNE);
List<Fodselsnummer> options = FodselsnummerCalculator.GetFodselsnummerForDateAndGender(date, KJONN.KVINNE);
Assert.Equal(207, options.Count);
}

[Fact]
public void getValidFodselsnummerForDate()
{
List<Fodselsnummer> validOptions = FodselsnummerCalculator.getManyFodselsnummerForDate(date);
List<Fodselsnummer> validOptions = FodselsnummerCalculator.GetManyFodselsnummerForDate(date);
Assert.True(validOptions.Count == 412, "Forventet 412 fødselsnumre, men fikk " + validOptions.Count);
}

[Fact]
public void getValidFodselsnummerForDNumberDate()
{
List<Fodselsnummer> validOptions = FodselsnummerCalculator.getManyFodselsnummerForDate(date, true);
List<Fodselsnummer> validOptions = FodselsnummerCalculator.GetManyFodselsnummerForDate(date, true);
Assert.True(validOptions.Count == 413, "Forventet 412 fødselsnumre som er d-nummer, men fikk " + validOptions.Count);
}

[Fact]
public void testThatAllGeneratedNumbersAreValid()
{
foreach (Fodselsnummer fnr in FodselsnummerCalculator.getManyFodselsnummerForDate(date))
foreach (Fodselsnummer fnr in FodselsnummerCalculator.GetManyFodselsnummerForDate(date))
{
Assert.True(FodselsnummerValidator.IsValid(fnr.ToString()), "Ugyldig fødselsnummer: " + fnr);
}
Expand All @@ -49,7 +49,7 @@ public void testThatAllGeneratedNumbersAreValid()
[Fact]
public void testThatAllGeneratedDFodselsnumbersAreValid()
{
foreach (Fodselsnummer fnr in FodselsnummerCalculator.getManyFodselsnummerForDate(date, true))
foreach (Fodselsnummer fnr in FodselsnummerCalculator.GetManyFodselsnummerForDate(date, true))
{
Assert.True(FodselsnummerValidator.IsValid(fnr.ToString()), "Ugyldig fødselsnummer: " + fnr);
}
Expand All @@ -59,23 +59,23 @@ public void testThatAllGeneratedDFodselsnumbersAreValid()
public void testInvalidDateTooEarly()
{
date = DateTime.ParseExact("09091853", _dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None);
List<Fodselsnummer> options = FodselsnummerCalculator.getManyFodselsnummerForDate(date);
List<Fodselsnummer> options = FodselsnummerCalculator.GetManyFodselsnummerForDate(date);
Assert.Empty(options);
}

[Fact]
public void testInvalidDateTooLate()
{
date = DateTime.ParseExact("09092040", _dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None);
List<Fodselsnummer> options = FodselsnummerCalculator.getManyFodselsnummerForDate(date);
List<Fodselsnummer> options = FodselsnummerCalculator.GetManyFodselsnummerForDate(date);
Assert.Empty(options);
}

[Fact]
public void testOneFodselsnummer()
{
date = DateTime.ParseExact("01121980", _dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None);
Fodselsnummer fodselsnummer = FodselsnummerCalculator.getFodselsnummerForDate(date);
Fodselsnummer fodselsnummer = FodselsnummerCalculator.GetFodselsnummerForDate(date);
Assert.True(FodselsnummerValidator.IsValid(fodselsnummer.ToString()));
}
}
Expand Down
64 changes: 32 additions & 32 deletions NoCommons.Tests/Person/FodselsnummerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,134 +17,134 @@ public FodselsnummerTest() {

[Fact]
public void testGetDateAndMonth() {
Assert.Equal("0101", sut.getDateAndMonth());
Assert.Equal("0101", sut.GetDateAndMonth());
}

[Fact]
public void testGetDayInMonth() {
Assert.Equal("01", sut.getDayInMonth());
Assert.Equal("01", sut.GetDayInMonth());
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.Equal("01", sut.getDayInMonth());
Assert.Equal("01", sut.GetDayInMonth());
}

[Fact]
public void testGetMonth() {
Assert.Equal("01", sut.getMonth());
Assert.Equal("01", sut.GetMonth());
}

[Fact]
public void testGetDateAndMonthDNumber() {
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.Equal("0101", sut.getDateAndMonth());
Assert.Equal("0101", sut.GetDateAndMonth());
}

[Fact]
public void testGetCentury() {
sut = new Fodselsnummer("01016666609");
Assert.Equal("18", sut.getCentury());
Assert.Equal("18", sut.GetCentury());

sut = new Fodselsnummer("01016633301");
Assert.Equal("19", sut.getCentury());
Assert.Equal("19", sut.GetCentury());

sut = new Fodselsnummer("01019196697");
Assert.Equal("19", sut.getCentury());
Assert.Equal("19", sut.GetCentury());

sut = new Fodselsnummer("01013366671");
Assert.Equal("20", sut.getCentury());
Assert.Equal("20", sut.GetCentury());

// DNumber...
sut = new Fodselsnummer("41016666609");
Assert.Equal("18", sut.getCentury());
Assert.Equal("18", sut.GetCentury());

sut = new Fodselsnummer("01015466609");
Assert.Equal("18", sut.getCentury());
Assert.Equal("18", sut.GetCentury());

sut = new Fodselsnummer("41016633301");
Assert.Equal("19", sut.getCentury());
Assert.Equal("19", sut.GetCentury());

sut = new Fodselsnummer("41019196697");
Assert.Equal("19", sut.getCentury());
Assert.Equal("19", sut.GetCentury());

sut = new Fodselsnummer("41013366671");
Assert.Equal("20", sut.getCentury());
Assert.Equal("20", sut.GetCentury());
}

[Fact]
public void testGet2DigitBirthYear() {
Assert.Equal("01", sut.get2DigitBirthYear());
Assert.Equal("01", sut.Get2DigitBirthYear());
}

[Fact]
public void testGetBirthYear() {
Assert.Equal("1901", sut.getBirthYear());
Assert.Equal("1901", sut.GetBirthYear());
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.Equal("1901", sut.getBirthYear());
Assert.Equal("1901", sut.GetBirthYear());
}

[Fact]
public void testGetDateOfBirth() {
Assert.Equal("010101", sut.getDateOfBirth());
Assert.Equal("010101", sut.GetDateOfBirth());
}

[Fact]
public void testGetDateOfBirthDNumber() {
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.Equal("010101", sut.getDateOfBirth());
Assert.Equal("010101", sut.GetDateOfBirth());
}

[Fact]
public void testGetPersonnummer() {
Assert.Equal("23476", sut.getPersonnummer());
Assert.Equal("23476", sut.GetPersonnummer());
}

[Fact]
public void testGetIndividnummer() {
Assert.Equal("234", sut.getIndividnummer());
Assert.Equal("234", sut.GetIndividnummer());
}

[Fact]
public void testGetGenderDigit() {
Assert.Equal(4, sut.getGenderDigit());
Assert.Equal(4, sut.GetGenderDigit());
}

[Fact]
public void testGetChecksumDigits() {
Assert.Equal(7, sut.getChecksumDigit1());
Assert.Equal(6, sut.getChecksumDigit2());
Assert.Equal(7, sut.GetChecksumDigit1());
Assert.Equal(6, sut.GetChecksumDigit2());
}

[Fact]
public void testIsMale() {
Assert.False(sut.isMale());
Assert.False(sut.IsMale());
}

[Fact]
public void testIsMaleDNumber() {
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.False(sut.isMale());
Assert.False(sut.IsMale());
}

[Fact]
public void testIsFemale() {
Assert.True(sut.isFemale());
Assert.True(sut.IsFemale());
}

[Fact]
public void testIsFemaleDNumber() {
sut = new Fodselsnummer(VALID_D_FODSELSNUMMER);
Assert.True(sut.isFemale());
Assert.True(sut.IsFemale());
}

[Fact]
public void testIsDNumber() {
Assert.False(Fodselsnummer.isDNumber("01010101006"));
Assert.False(Fodselsnummer.isDNumber("80000000000"));
Assert.True(Fodselsnummer.isDNumber("47086303651"));
Assert.False(Fodselsnummer.IsDNumber("01010101006"));
Assert.False(Fodselsnummer.IsDNumber("80000000000"));
Assert.True(Fodselsnummer.IsDNumber("47086303651"));
}

[Fact]
public void testParseDNumber() {
Assert.Equal("07086303651", Fodselsnummer.parseDNumber("47086303651"));
Assert.Equal("07086303651", Fodselsnummer.ParseDNumber("47086303651"));
}
}
}
Loading