Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH3652/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//------------------------------------------------------------------------------
// <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.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3652;
using System.Threading.Tasks;

[TestFixture]
public class FixtureAsync : BugTestCase
{
private Department _department1;
private Department _department2;
private Employee _employee1;
private Employee _employee2;

protected override void OnSetUp()
{
using var session = OpenSession();
using var tx = session.BeginTransaction();
_department1 = new Department();
_department2 = new Department();

_employee1 = new Employee();
_employee2 = new Employee();

_employee1.Departments.Add(_department1);
_employee2.Departments.Add(_department1);
_employee2.Departments.Add(_department2);

session.Save(_department1);
session.Save(_department2);
session.Save(_employee1);
session.Save(_employee2);

tx.Commit();
}

protected override void OnTearDown()
{
using var session = OpenSession();
using var tx = session.BeginTransaction();
session.Delete(_employee1);
session.Delete(_employee2);
session.Delete(_department1);
session.Delete(_department2);

tx.Commit();
}

[Theory]
public async Task Querying_Employees_Departments_ManyToMany_With_FilterAsync(bool enableFilter)
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
_department1.DeletedAt = DateTime.UtcNow;
_department2.DeletedAt = DateTime.UtcNow;

await (session.UpdateAsync(_department1));
await (session.UpdateAsync(_department2));

await (tx.CommitAsync());
}

using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
if (enableFilter)
session.EnableFilter("NotDeletedFilter");

var departments = session.Query<Department>();
var employee2 = await (session.GetAsync<Employee>(_employee2.Id));

if (enableFilter)
{
Assert.That(departments, Is.Empty);
Assert.That(employee2.Departments, Is.Empty);
}
else
{
Assert.That(departments.Count, Is.EqualTo(2));
Assert.That(employee2.Departments, Has.Count.EqualTo(2));
}


await (tx.CommitAsync());
}
}
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3652/BaseClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace NHibernate.Test.NHSpecificTest.GH3652;

public class BaseClass
{
public virtual Guid Id { get; set; }
}
11 changes: 11 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3652/Department.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH3652;

public class Department : BaseClass
{
public virtual ISet<Employee> Employees { get; set; } = new HashSet<Employee>();

public virtual DateTime? DeletedAt { get; set; }
}
8 changes: 8 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3652/Employee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH3652;

public class Employee : BaseClass
{
public virtual ISet<Department> Departments { get; set; } = new HashSet<Department>();
}
88 changes: 88 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3652/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Linq;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3652;

[TestFixture]
public class Fixture : BugTestCase
{
private Department _department1;
private Department _department2;
private Employee _employee1;
private Employee _employee2;

protected override void OnSetUp()
{
using var session = OpenSession();
using var tx = session.BeginTransaction();
_department1 = new Department();
_department2 = new Department();

_employee1 = new Employee();
_employee2 = new Employee();

_employee1.Departments.Add(_department1);
_employee2.Departments.Add(_department1);
_employee2.Departments.Add(_department2);

session.Save(_department1);
session.Save(_department2);
session.Save(_employee1);
session.Save(_employee2);

tx.Commit();
}

protected override void OnTearDown()
{
using var session = OpenSession();
using var tx = session.BeginTransaction();
session.Delete(_employee1);
session.Delete(_employee2);
session.Delete(_department1);
session.Delete(_department2);

tx.Commit();
}

[Theory]
public void Querying_Employees_Departments_ManyToMany_With_Filter(bool enableFilter)
{
using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
_department1.DeletedAt = DateTime.UtcNow;
_department2.DeletedAt = DateTime.UtcNow;

session.Update(_department1);
session.Update(_department2);

tx.Commit();
}

using (var session = OpenSession())
using (var tx = session.BeginTransaction())
{
if (enableFilter)
session.EnableFilter("NotDeletedFilter");

var departments = session.Query<Department>();
var employee2 = session.Get<Employee>(_employee2.Id);

if (enableFilter)
{
Assert.That(departments, Is.Empty);
Assert.That(employee2.Departments, Is.Empty);
}
else
{
Assert.That(departments.Count, Is.EqualTo(2));
Assert.That(employee2.Departments, Has.Count.EqualTo(2));
}


tx.Commit();
}
}
}
31 changes: 31 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3652/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernate.Test.NHSpecificTest.GH3652"
assembly="NHibernate.Test">

<class name="BaseClass">
<id name="Id">
<generator class="guid.comb" />
</id>
<discriminator column="discriminator" type="String" />

<subclass name="Employee" discriminator-value="Emp">
<set name="Departments" table="EmployeeDepartment" cascade="all-delete-orphan" inverse="false">
<key column="EmployeeId"/>
<many-to-many class="Department" column="DepartmentId"/>
</set>
</subclass>

<subclass name="Department" discriminator-value="Dep">
<property name="DeletedAt" column="DeletedAt" type="DateTime"/>
<set name="Employees" table="EmployeeDepartment" cascade="none" inverse="true">
<key column="DepartmentId"/>
<many-to-many class="Employee" column="EmployeeId"/>
</set>
<filter name="NotDeletedFilter" condition="DeletedAt IS NULL"/>
</subclass>
</class>
<filter-def name="NotDeletedFilter"/>

</hibernate-mapping>