added tests for the sumbyasync methods
This commit is contained in:
@@ -1075,6 +1075,33 @@ namespace CoreIntegrationTests.Infrastructure
|
||||
|
||||
#endregion Index Management
|
||||
|
||||
#region Math
|
||||
|
||||
[Fact]
|
||||
public async Task SumByAsync()
|
||||
{
|
||||
// Arrange
|
||||
var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}";
|
||||
var documents = CreateTestDocuments(5);
|
||||
var i = 1;
|
||||
documents.ForEach(e =>
|
||||
{
|
||||
e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++);
|
||||
e.Nested.SomeAmount = 5m;
|
||||
e.SomeContent = criteria;
|
||||
});
|
||||
SUT.AddMany<T>(documents);
|
||||
var expectedSum = documents.Sum(e => e.Nested.SomeAmount);
|
||||
|
||||
// Act
|
||||
var result = await SUT.SumByAsync<T>(e => e.SomeContent == criteria, e => e.Nested.SomeAmount, PartitionKey);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedSum, result);
|
||||
}
|
||||
|
||||
#endregion Math
|
||||
|
||||
#region Test Utils
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
|
||||
@@ -1068,6 +1068,33 @@ namespace CoreIntegrationTests.Infrastructure
|
||||
|
||||
#endregion Index Management
|
||||
|
||||
#region Math
|
||||
|
||||
[Fact]
|
||||
public async Task SumByAsync()
|
||||
{
|
||||
// Arrange
|
||||
var criteria = $"{GetTestName()}.{DocumentTypeName}.{Guid.NewGuid()}";
|
||||
var documents = CreateTestDocuments(5);
|
||||
var i = 1;
|
||||
documents.ForEach(e =>
|
||||
{
|
||||
e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++);
|
||||
e.Nested.SomeAmount = 5m;
|
||||
e.SomeContent = criteria;
|
||||
});
|
||||
SUT.AddMany<T, TKey>(documents);
|
||||
var expectedSum = documents.Sum(e => e.Nested.SomeAmount);
|
||||
|
||||
// Act
|
||||
var result = await SUT.SumByAsync<T, TKey>(e => e.SomeContent == criteria, e => e.Nested.SomeAmount, PartitionKey);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedSum, result);
|
||||
}
|
||||
|
||||
#endregion Math
|
||||
|
||||
#region Test Utils
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private string GetCurrentMethod()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using MongoDbGenericRepository.Utils;
|
||||
using System;
|
||||
@@ -21,6 +22,8 @@ namespace CoreIntegrationTests.Infrastructure
|
||||
public class Nested
|
||||
{
|
||||
public DateTime SomeDate { get; set; }
|
||||
[BsonRepresentation(BsonType.Decimal128)]
|
||||
public decimal SomeAmount { get; set; }
|
||||
}
|
||||
|
||||
public class Child
|
||||
|
||||
Reference in New Issue
Block a user