public void ThrowsWhenCandidateIsNull() { // Arrange ILogger <FantasticReasonService> logger = Substitute.For <ILogger <FantasticReasonService> >(); FantasticReasonService uut = CreateService(db: _db, logger: logger); // Act Action act = () => uut.GetReasonsByCandidate(null); // Assert act.Should().Throw <Exception>(); logger.ReceivedCalls().Should().ContainSingle() .Which.GetArguments().Should().Contain(LogLevel.Error); }
public void GetsCorrectReasons() { // Arrange const int targetCandidateId = 10; // Seed our target candidate Candidate c1 = new Candidate() { Id = targetCandidateId, FirstName = "Test", LastName = "Person1", FantasticReasons = new List <FantasticReason>() { new FantasticReason() { Reason = "reason 1", DisplayOrder = 1 }, new FantasticReason() { Reason = "reason 2", DisplayOrder = 2 }, new FantasticReason() { Reason = "reason 3", DisplayOrder = 3 } } }; // Seed some other candidate Candidate c2 = new Candidate() { Id = targetCandidateId + 2, FirstName = "Test", LastName = "Person2", FantasticReasons = new List <FantasticReason>() { new FantasticReason() { Reason = "reason 1", DisplayOrder = 1 }, new FantasticReason() { Reason = "reason 2", DisplayOrder = 2 }, new FantasticReason() { Reason = "reason 3", DisplayOrder = 3 } } }; _db.AddRange(c1, c2); _db.SaveChanges(); FantasticReasonService uut = CreateService(db: _db); // Act List <FantasticReasonDto> result = uut.GetReasonsByCandidateId(targetCandidateId); // Assert // Database should contain 6 total reasons _db.Candidates.SelectMany(c => c.FantasticReasons).Should().HaveCount(6); // Our result should only contain 3 result.Should().HaveCount(3); }