|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System; |
| 12 | +using NHibernate.Cfg; |
| 13 | +using NHibernate.Dialect; |
| 14 | +using NHibernate.Mapping.ByCode; |
| 15 | +using NHibernate.Tool.hbm2ddl; |
| 16 | +using NUnit.Framework; |
| 17 | + |
| 18 | +namespace NHibernate.Test.Tools.hbm2ddl.SchemaValidator |
| 19 | +{ |
| 20 | + using System.Threading.Tasks; |
| 21 | + [TestFixture] |
| 22 | + public class PostgresSchemaValidateFixtureAsync |
| 23 | + { |
| 24 | + [Test] |
| 25 | + public async Task ShouldBeInvalidIfTimestampTzIsExpectedAndGotTimestampAsync() |
| 26 | + { |
| 27 | + var actual = BuildConfiguration("timestamp"); |
| 28 | + Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); |
| 29 | + |
| 30 | + var expected = BuildConfiguration("timestamptz"); |
| 31 | + |
| 32 | + var export = new SchemaExport(actual); |
| 33 | + await (export.CreateAsync(true, true)); |
| 34 | + |
| 35 | + try |
| 36 | + { |
| 37 | + var validator = new Tool.hbm2ddl.SchemaValidator(expected); |
| 38 | + |
| 39 | + var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync()); |
| 40 | + Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors")); |
| 41 | + Assert.That( |
| 42 | + error, |
| 43 | + Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase |
| 44 | + .And.Contains("for column CreatedAt. Found: timestamp, Expected timestamptz").IgnoreCase); |
| 45 | + } |
| 46 | + finally |
| 47 | + { |
| 48 | + await (export.DropAsync(true, true)); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + [Test] |
| 53 | + public async Task ShouldBeInvalidIfTimestampIsExpectedAndGotTimestampTzAsync() |
| 54 | + { |
| 55 | + var actual = BuildConfiguration("timestamptz"); |
| 56 | + Assume.That(Dialect.Dialect.GetDialect(actual.Properties) is PostgreSQLDialect); |
| 57 | + |
| 58 | + var expected = BuildConfiguration("timestamp"); |
| 59 | + |
| 60 | + var export = new SchemaExport(actual); |
| 61 | + await (export.CreateAsync(true, true)); |
| 62 | + |
| 63 | + try |
| 64 | + { |
| 65 | + var validator = new Tool.hbm2ddl.SchemaValidator(expected); |
| 66 | + |
| 67 | + var error = Assert.ThrowsAsync<SchemaValidationException>(() => validator.ValidateAsync()); |
| 68 | + Assert.That(error, Has.Message.EqualTo("Schema validation failed: see list of validation errors")); |
| 69 | + Assert.That( |
| 70 | + error, |
| 71 | + Has.Property("ValidationErrors").Some.Contains("Wrong column type").IgnoreCase |
| 72 | + .And.Contains("for column CreatedAt. Found: timestamptz, Expected timestamp").IgnoreCase); |
| 73 | + } |
| 74 | + finally |
| 75 | + { |
| 76 | + await (export.DropAsync(true, true)); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + private static Configuration BuildConfiguration(string type) |
| 81 | + { |
| 82 | + var mapper = new ModelMapper(); |
| 83 | + mapper.Class<Entity>(c => |
| 84 | + { |
| 85 | + c.Table("Entity"); |
| 86 | + c.Id(x => x.Id); |
| 87 | + c.Property(x => x.CreatedAt, p => p.Column(cm => cm.SqlType(type))); |
| 88 | + }); |
| 89 | + |
| 90 | + var cfg = TestConfigurationHelper.GetDefaultConfiguration(); |
| 91 | + cfg.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Entity"); |
| 92 | + return cfg; |
| 93 | + } |
| 94 | + |
| 95 | + public class Entity |
| 96 | + { |
| 97 | + public virtual int Id { get; set; } |
| 98 | + public virtual DateTime CreatedAt { get; set; } |
| 99 | + } |
| 100 | + } |
| 101 | +} |
0 commit comments