Skip to content

Commit

Permalink
Fixup unit test exception specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Mar 14, 2023
1 parent b3ae244 commit 65e7129
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Rdmp.Core.Tests/Validation/PredictionValidationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public void Validate_NullTargetField_GeneratesException(string targetField)
var prediction = new Prediction(new ChiSexPredictor(), targetField);
var v = CreateInitialisedValidator(prediction);

var ex = Assert.Throws<Exception>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<MissingFieldException>(ex.InnerException);
var ex = Assert.Throws<InvalidOperationException>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<MissingFieldException>(ex?.InnerException);
}

[Test]
public void Validate_NullRule_GeneratesException()
{
var ex = Assert.Throws<ArgumentException>(()=>new Prediction(null, "gender"));
StringAssert.Contains("You must specify a PredictionRule to follow",ex.Message);
var ex = Assert.Throws<ArgumentException>(()=>_=new Prediction(null, "gender"));
StringAssert.Contains("You must specify a PredictionRule to follow",ex?.Message);
}

[Test]
Expand All @@ -44,28 +44,30 @@ public void Validate_Uninitialized_GeneratesException()
var prediction = new Prediction();
var v = CreateInitialisedValidator(prediction);

var ex = Assert.Throws <Exception>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<InvalidOperationException>(ex.InnerException);
var ex = Assert.Throws<InvalidOperationException>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
}

[Test]
public void Validate_UninitializedTarget_GeneratesException()
{
var prediction = new Prediction();
prediction.Rule = new ChiSexPredictor();
var prediction = new Prediction
{
Rule = new ChiSexPredictor()
};
var v = CreateInitialisedValidator(prediction);
var ex = Assert.Throws<Exception>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<InvalidOperationException>(ex.InnerException);
var ex = Assert.Throws<InvalidOperationException>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<InvalidOperationException>(ex?.InnerException);
}

[Test]
public void Validate_UninitializedRule_GeneratesException()
{
var prediction = new Prediction();
prediction.TargetColumn = "chi";
var prediction = new Prediction
{
TargetColumn = "chi"
};
var v = CreateInitialisedValidator(prediction);
var ex = Assert.Throws<Exception>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
Assert.IsInstanceOf<InvalidOperationException>(ex.InnerException);
var ex = Assert.Throws<InvalidOperationException>(()=>v.Validate(TestConstants.ValidChiAndInconsistentSex));
}
#endregion

Expand Down Expand Up @@ -160,8 +162,10 @@ public void Validate_NoPrimaryConstraintChiIsInvalid_ValidBecauseWhoCaresIfChiIs

private static Validator CreateInitialisedValidator(SecondaryConstraint prediction)
{
var i = new ItemValidator();
i.PrimaryConstraint = new Chi();
var i = new ItemValidator
{
PrimaryConstraint = new Chi()
};
i.SecondaryConstraints.Add(prediction);

var v = new Validator();
Expand Down

0 comments on commit 65e7129

Please sign in to comment.