Skip to content

Commit d1ff749

Browse files
hazzikAlex Zaytsev
authored and
Alex Zaytsev
committed
Improve error message for SchemaValidationException
1 parent 375c032 commit d1ff749

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

src/NHibernate.Test/Async/NHSpecificTest/NH1274ExportExclude/NH1274ExportExcludeFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void SchemaExport_Validate_CausesValidateExceptionAsync()
9595
Assert.That(
9696
() => validator.ValidateAsync(),
9797
Throws.TypeOf<SchemaValidationException>()
98-
.And.Message.EqualTo("Schema validation failed: see list of validation errors")
98+
.And.Message.StartsWith("Schema validation failed: see list of validation errors")
9999
.And.Property("ValidationErrors").Contains("Missing table: Home_Validate"));
100100
}
101101

src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/PostgresSchemaValidateFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task ShouldBeInvalidIfTimestampTzIsExpectedAndGotTimestampAsync()
3737
var validator = new Tool.hbm2ddl.SchemaValidator(expected);
3838

3939
var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync());
40-
Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors"));
40+
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors"));
4141
Assert.That(
4242
error,
4343
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase
@@ -65,7 +65,7 @@ public async Task ShouldBeInvalidIfTimestampIsExpectedAndGotTimestampTzAsync()
6565
var validator = new Tool.hbm2ddl.SchemaValidator(expected);
6666

6767
var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync());
68-
Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors"));
68+
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors"));
6969
Assert.That(
7070
error,
7171
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase

src/NHibernate.Test/Async/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void ShouldNotVerifyModifiedTableAsync()
9090
Assert.That(
9191
() => validatorV2.ValidateAsync(),
9292
Throws.TypeOf<SchemaValidationException>()
93-
.And.Message.EqualTo("Schema validation failed: see list of validation errors")
93+
.And.Message.StartsWith("Schema validation failed: see list of validation errors")
9494
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase);
9595
}
9696

@@ -103,7 +103,7 @@ public void ShouldNotVerifyMultiModifiedTableAsync()
103103

104104
var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync());
105105
Assert.That(error,
106-
Has.Message.EqualTo("Schema validation failed: see list of validation errors")
106+
Has.Message.StartsWith("Schema validation failed: see list of validation errors")
107107
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase);
108108
Assert.That(error,
109109
Has.Property("ValidationErrors").Some.Contains("Missing column: Title in ").IgnoreCase.And.Contains("Version").IgnoreCase);

src/NHibernate.Test/NHSpecificTest/NH1274ExportExclude/NH1274ExportExcludeFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void SchemaExport_Validate_CausesValidateException()
8484
Assert.That(
8585
() => validator.Validate(),
8686
Throws.TypeOf<SchemaValidationException>()
87-
.And.Message.EqualTo("Schema validation failed: see list of validation errors")
87+
.And.Message.StartsWith("Schema validation failed: see list of validation errors")
8888
.And.Property("ValidationErrors").Contains("Missing table: Home_Validate"));
8989
}
9090

src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/PostgresSchemaValidateFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void ShouldBeInvalidIfTimestampTzIsExpectedAndGotTimestamp()
2626
var validator = new Tool.hbm2ddl.SchemaValidator(expected);
2727

2828
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate());
29-
Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors"));
29+
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors"));
3030
Assert.That(
3131
error,
3232
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase
@@ -54,7 +54,7 @@ public void ShouldBeInvalidIfTimestampIsExpectedAndGotTimestampTz()
5454
var validator = new Tool.hbm2ddl.SchemaValidator(expected);
5555

5656
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate());
57-
Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors"));
57+
Assert.That(error, Has.Message.StartsWith("Schema validation failed: see list of validation errors"));
5858
Assert.That(
5959
error,
6060
Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase

src/NHibernate.Test/Tools/hbm2ddl/SchemaValidator/SchemaValidateFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void ShouldNotVerifyModifiedTable()
7979
Assert.That(
8080
() => validatorV2.Validate(),
8181
Throws.TypeOf<SchemaValidationException>()
82-
.And.Message.EqualTo("Schema validation failed: see list of validation errors")
82+
.And.Message.StartsWith("Schema validation failed: see list of validation errors")
8383
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase);
8484
}
8585

@@ -92,7 +92,7 @@ public void ShouldNotVerifyMultiModifiedTable()
9292

9393
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate());
9494
Assert.That(error,
95-
Has.Message.EqualTo("Schema validation failed: see list of validation errors")
95+
Has.Message.StartsWith("Schema validation failed: see list of validation errors")
9696
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase);
9797
Assert.That(error,
9898
Has.Property("ValidationErrors").Some.Contains("Missing column: Title in ").IgnoreCase.And.Contains("Version").IgnoreCase);

src/NHibernate/SchemaValidationException.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Runtime.Serialization;
55
using System.Security;
6+
using System.Text;
67

78
namespace NHibernate
89
{
@@ -36,8 +37,12 @@ public override string Message
3637
var message = base.Message;
3738
if (ValidationErrors == null || ValidationErrors.Count == 0)
3839
return message;
39-
var errors = "ValidationErrors:" + string.Join(Environment.NewLine + "- ", ValidationErrors);
40-
return message + Environment.NewLine + errors;
40+
41+
var sb = new StringBuilder(message).AppendLine().AppendLine("Validation errors:");
42+
foreach (var error in ValidationErrors)
43+
sb.Append('-').AppendLine(error);
44+
45+
return sb.ToString();
4146
}
4247
}
4348
}

0 commit comments

Comments
 (0)