Skip to content
Permalink
Browse files

Fixed issue with WithGroup on an empty match

  • Loading branch information
Turnerj committed Mar 1, 2020
1 parent 88cb774 commit d8bda7f76d505f668b7dd4339849a91e51347422
Showing with 19 additions and 2 deletions.
  1. +1 −2 src/MongoFramework/MongoDbBucketSet.cs
  2. +18 −0 tests/MongoFramework.Tests/MongoDbBucketSetTests.cs
@@ -81,8 +81,7 @@ public virtual void AddRange(TGroup group, IEnumerable<TSubEntity> entities)

public virtual IQueryable<TSubEntity> WithGroup(TGroup group)
{
var totalItemCount = EntityReader.AsQueryable().Where(e => e.Group == group).Sum(e => e.ItemCount);
return EntityReader.AsQueryable().Where(e => e.Group == group).OrderBy(e => e.Index).SelectMany(e => e.Items).Take(totalItemCount);
return EntityReader.AsQueryable().Where(e => e.Group == group).OrderBy(e => e.Index).SelectMany(e => e.Items);
}

public virtual IQueryable<TGroup> Groups()
@@ -350,5 +350,23 @@ public void ValueTypeSubEntity()
Assert.AreEqual(8, results[3]);
Assert.AreEqual(10, results[4]);
}

[TestMethod]
public void WithGroupOnEmptyBucket()
{
var dbSet = new MongoDbBucketSet<EntityGroup, SubEntityClass>(new BucketSetOptions
{
BucketSize = 2
});
dbSet.SetConnection(TestConfiguration.GetConnection());

var result = dbSet.WithGroup(new EntityGroup
{
Name = "Group1",
Reference = 123
}).Count();

Assert.AreEqual(0, result);
}
}
}

0 comments on commit d8bda7f

Please sign in to comment.
You can’t perform that action at this time.