Skip to content

Commit 2c87477

Browse files
committed
Unit test fixes ahead of .net Standard merge
1 parent 318a59a commit 2c87477

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Principle4.DryLogic.Tests/Employee.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal static readonly PropertyDefinition<Boolean> IsPresidentProperty
163163
.IsRequired()
164164
.IsConvertable()
165165
.IsAdhearingTo(oi => oi.GetValue(IsPresidentProperty) == false)
166-
.When(oi => BirthDateProperty[oi].AddYears(40) >= DateTime.Today)
166+
.When(oi => BirthDateProperty[oi].AddYears(40) > DateTime.Today)
167167
.WithMessage("{0} cannot be true if the employee is not yet 40")
168168
.IdentifiedBy("PRES40");
169169
//New idea: I've started TypedPropertyRuleBuilder<T>
@@ -254,13 +254,14 @@ public void MakeValid()
254254
HireDate = DateTime.Today;
255255
BirthDate = DateTime.Today.AddYears(-25);
256256
LastName = "Levitt";
257+
FirstName = "Brandon";
258+
Score = 0;
257259
}
258260
public void MakeValidForPresident()
259261
{
260262
MakeValid();
261263
BirthDate = DateTime.Today.AddYears(-40);
262264
IsPresident = true;
263-
264265
}
265266

266267

Principle4.DryLogic.Tests/EmployeeTests.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ public void HireDateShouldBeAValidDate()
8686
Assert.That(violatedRule.AppliedRule is DBV.TypeConvertableRule, "Employee should not be valid since hire date cannot be converted to an datetime.");
8787
}
8888

89-
[Test]
90-
public void NeedsAScore()
91-
{
92-
Employee.MakeValidForPresident();
93-
var violatedRule = Employee.ScoreProperty.GetFirstRuleViolation(Employee.OI);
94-
Assert.That(Employee.Score == null);
95-
96-
}
97-
9889
[Test]
9990

10091
public void PropertyChanged()
@@ -125,13 +116,13 @@ public void PropertyChanged()
125116
[Test]
126117
public void TestConditionalRule_IsPresident()
127118
{
128-
Employee.MakeValid();
129-
Assert.That(Employee.OI.Validate(), "Employee should be valid.");
130-
Employee.BirthDate.AddDays(-1);
119+
Employee.MakeValidForPresident();
120+
Assert.That(Employee.OI.Validate(), "Employee should be valid." + (Employee.OI.GetRuleViolations().FirstOrDefault()?.ErrorMessage));
121+
Employee.BirthDate = Employee.BirthDate.AddDays(1);
131122

132123
var violatedRule = Employee.IsPresidentProperty.GetFirstRuleViolation(Employee.OI);
133124
//TODO: Need rule ID setter so we can identify the proper rule.
134-
Assert.That(violatedRule.AppliedRule.Id == "PRES40", "Employee should have violated the PRES40 rule.");
125+
Assert.That(violatedRule?.AppliedRule.Id == "PRES40", "Employee should have violated the PRES40 rule.");
135126

136127

137128

0 commit comments

Comments
 (0)