Created
March 22, 2021 17:45
-
-
Save jasper-zanjani/8914789c8e587b2bae0b3725e2c2250b to your computer and use it in GitHub Desktop.
Starships
This file contains hidden or 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
using System; | |
using Starships.Models; | |
namespace Starships | |
{ | |
public interface IOfficerEvaluator | |
{ | |
bool Evaluate(IOfficer officer); | |
} | |
public class OfficerEvaluator : IOfficerEvaluator | |
{ | |
public IOfficer Officer; | |
public OfficerEvaluator() | |
{ | |
} | |
public bool Evaluate(IOfficer officer) | |
{ | |
if (officer.Grade == 'A') | |
{ | |
return true; | |
} | |
else { throw new Exception("Unacceptable officer"); } | |
} | |
} | |
} |
This file contains hidden or 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
using System; | |
using Xunit; | |
using Moq; | |
using Starships; | |
using Starships.Models; | |
namespace Starships.Tests | |
{ | |
public class OfficerEvaluatorShould | |
{ | |
[Theory] | |
[InlineData('A')] | |
public void ApproveGoodOfficers(char grade) | |
{ | |
var officer = new Mock<IOfficer>(); | |
officer.Setup(x => x.Grade).Returns(grade); | |
OfficerEvaluator sut = new OfficerEvaluator(); | |
Assert.True(sut.Evaluate(officer.Object)); | |
} | |
[Theory] | |
[InlineData('B')] | |
[InlineData('C')] | |
[InlineData('D')] | |
[InlineData('F')] | |
public void ThrowOnPoorOfficers(char grade) | |
{ | |
var officer = new Mock<IOfficer>(); | |
officer.Setup(x => x.Grade).Returns(grade); | |
OfficerEvaluator sut = new OfficerEvaluator(); | |
//Assert.Throws<Exception>(sut.Evaluate(officer.Object)); | |
Assert.Throws<Exception>(() => sut.Evaluate(officer.Object)); | |
} | |
} | |
} |
This file contains hidden or 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
using System; | |
namespace Starships.Models | |
{ | |
public interface IOfficer | |
{ | |
string FirstName { get; set; } | |
string LastName { get; set; } | |
DateTime BirthDate { get; set; } | |
char Grade { get; set; } | |
string Name { get; } | |
} | |
public interface IStarship | |
{ | |
string Name { get; set; } | |
string Registry { get; set; } | |
int Crew { get; set; } | |
StarshipClass StarshipClass { get; set; } | |
IOfficer Captain { get; set; } | |
} | |
public class Officer : IOfficer | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public DateTime BirthDate { get; set; } | |
public string Name { get { return $"{FirstName} {LastName}"; } } | |
public char Grade { get; set; } | |
} | |
public class Starship : IStarship | |
{ | |
public string Name { get; set; } | |
public string Registry { get; set; } | |
public int Crew { get; set; } | |
public StarshipClass StarshipClass { get; set; } | |
public IOfficer Captain { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment