-
Notifications
You must be signed in to change notification settings - Fork 933
NH-3905 - Missings async tests #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,8 +156,6 @@ | |
applyChanges: true | ||
analyzation: | ||
methodConversion: | ||
- conversion: Ignore | ||
hasAttributeName: IgnoreAttribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule was causing tests from a base class overridden for marking them as NUnit Example of such a case in this fixture. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
- conversion: Smart | ||
hasAttributeName: TestAttribute | ||
- conversion: Smart | ||
|
@@ -180,6 +178,8 @@ | |
hasAttributeName: IgnoreAttribute | ||
- conversion: NewType | ||
hasAttributeName: TestFixtureAttribute | ||
- conversion: NewType | ||
anyBaseTypeRule: HasTestFixtureAttribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required for generating child classes of a base fixture if they are not themselves marked with the |
||
- conversion: Ignore | ||
rule: IsTestCase | ||
- conversion: Ignore | ||
|
@@ -246,3 +246,6 @@ typeRules: | |
- filters: | ||
- name: TestCase | ||
name: IsTestCase | ||
- filters: | ||
- hasAttributeName: TestFixtureAttribute | ||
name: HasTestFixtureAttribute |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Data.Common; | ||
using System.Data.Odbc; | ||
using System.Data.SqlClient; | ||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Dialect; | ||
using NHibernate.Exceptions; | ||
using NHibernate.Linq; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Component.Basic | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class ComponentWithUniqueConstraintTestsAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
|
||
mapper.Component<Person>(comp => | ||
{ | ||
comp.Property(p => p.Name); | ||
comp.Property(p => p.Dob); | ||
comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database | ||
}); | ||
|
||
mapper.Class<Employee>(cm => | ||
{ | ||
cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow)); | ||
cm.Property(employee => employee.HireDate); | ||
cm.Component(person => person.Person); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = Sfi.OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from Employee"); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CanBePersistedWithUniqueValuesAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } }; | ||
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Hillary", Dob = new DateTime(2000, 1, 1) } }; | ||
await (session.SaveAsync(e1)); | ||
await (session.SaveAsync(e2)); | ||
await (transaction.CommitAsync()); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var employees = await (session.Query<Employee>().ToListAsync()); | ||
Assert.That(employees.Count, Is.EqualTo(2)); | ||
Assert.That(employees.Select(employee => employee.Person.Name).ToArray(), Is.EquivalentTo(new[] { "Hillary", "Bill" })); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CannotBePersistedWithNonUniqueValuesAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var e1 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } }; | ||
var e2 = new Employee { HireDate = DateTime.Today, Person = new Person { Name = "Bill", Dob = new DateTime(2000, 1, 1) } }; | ||
|
||
var exception = Assert.ThrowsAsync<GenericADOException>(async () => | ||
{ | ||
await (session.SaveAsync(e1)); | ||
await (session.SaveAsync(e2)); | ||
await (session.FlushAsync()); | ||
}); | ||
Assert.That(exception.InnerException, Is.AssignableTo<DbException>()); | ||
Assert.That(exception.InnerException.Message, | ||
Does.Contain("unique").IgnoreCase.And.Contains("constraint").IgnoreCase | ||
.Or.Contains("duplicate entry").IgnoreCase); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required for newly generated tests, due to #41, #43, #44 & #45.