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

Unit tests for OfficeJob #2306

Merged
merged 1 commit into from
Nov 10, 2024
Merged
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
64 changes: 64 additions & 0 deletions ImperatorToCK3.UnitTests/Imperator/Jobs/OfficeJobTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using commonItems;
using ImperatorToCK3.Imperator.Characters;
using ImperatorToCK3.Imperator.Jobs;
using System;
using Xunit;

namespace ImperatorToCK3.UnitTests.Imperator.Jobs;

public class OfficeJobTests {
private static readonly string officeJobString =
"""
{
who=1770
character=207696
start_date=1580.5.26
office="office_physician"
}
""";

[Fact]
public void OfficeJobCanBeLoaded() {
var reader = new BufferedReader(officeJobString);
var irCharacters = new CharacterCollection {new Character(207696)};

var officeJob = new OfficeJob(reader, irCharacters);
Assert.Equal((ulong)1770, officeJob.CountryId);
Assert.Equal((ulong)207696, officeJob.Character.Id);
Assert.Equal(new Date(827, 5, 26), officeJob.StartDate); // The original date is AUC.
Assert.Equal("office_physician", officeJob.OfficeType);
}

[Fact]
public void FormatExceptionIsThrownOnMissingCountryId() {
var officeJobStr = officeJobString.Replace("who=1770", "");

var reader = new BufferedReader(officeJobStr);
var irCharacters = new CharacterCollection {new Character(207696)};

var exception = Assert.Throws<FormatException>(() => new OfficeJob(reader, irCharacters));
Assert.Equal("Country ID missing!", exception.Message);
}

[Fact]
public void FormatExceptionIsThrownOnMissingCharacterId() {
var officeJobStr = officeJobString.Replace("character=207696", "");

var reader = new BufferedReader(officeJobStr);
var irCharacters = new CharacterCollection();

var exception = Assert.Throws<FormatException>(() => new OfficeJob(reader, irCharacters));
Assert.Equal("Character ID missing!", exception.Message);
}

[Fact]
public void FormatExceptionIsThrownOnMissingOfficeType() {
var officeJobStr = officeJobString.Replace("office=\"office_physician\"", "");

var reader = new BufferedReader(officeJobStr);
var irCharacters = new CharacterCollection {new Character(207696)};

var exception = Assert.Throws<FormatException>(() => new OfficeJob(reader, irCharacters));
Assert.Equal("Office type missing!", exception.Message);
}
}
Loading