Skip to content
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

DelayedQueryWithDtoCtorParamTest test #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,77 @@ public void DelayedQueryWithEqualityTest()
Assert.AreEqual(0, OtherService3.InstanceCount);
}


public class SomeConfig
{
public int Id { get; set; }

public static volatile int InstanceCount;

public SomeConfig()
{
_ = Interlocked.Increment(ref InstanceCount);
}

~SomeConfig()
{
_ = Interlocked.Decrement(ref InstanceCount);
}
}

public class ItemDto
{
public int ItemId { get; set; }

public ItemDto(SomeConfig config)
{
}
}

public class Service4
{
public Session Session;

private readonly SomeConfig configuration = new SomeConfig() { Id = 1 };

public ItemDto DelayedQueryWithDTOCtorParamweter(int id)
{
ItemDto model = null;
{ // This curly brace does matter. Without it the Closure is different
var item2 = Session.Query.Single<Item>(id);
var query = Session.Query.CreateDelayedQuery(
q => {
return (from inv in q.All<Item>().Where(o => o == item2)
select new ItemDto(configuration) {
ItemId = inv.Id
}).Single();
}
);
model = query.Value;
}
var invoice2 = Session.Query.All<Item>().Single(i => i.Id == model.ItemId);
return model;
}
}

[Test]
public void DelayedQueryWithDtoCtorParamTest()
{
using (var session = Domain.OpenSession())
using (var t = session.OpenTransaction()) {
var item = new Item { Tag = 10 };
DelayedQueryWithDTOCtorParamweter(session);
t.Complete();
}
TestHelper.CollectGarbage(true);
Assert.AreEqual(0, SomeConfig.InstanceCount);
}

private void DelayedQueryWithDTOCtorParamweter(Session session)
{
_ = new Service4() { Session = session }.DelayedQueryWithDTOCtorParamweter(1);
}

private void DelayedQueryWithEquality(Session session)
{
var id = 1;
Expand Down