added tests for the sumbyasync methods

This commit is contained in:
Alexandre SPIESER
2019-02-04 23:11:36 +00:00
parent eaa90d67f5
commit 4ac0ffe91c
8 changed files with 158 additions and 19 deletions
@@ -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