• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / MongoDB.Abstracts / 13118055932

03 Feb 2025 04:24PM UTC coverage: 77.474% (-1.4%) from 78.879%
13118055932

push

github

pwelter34
add tests, update readme

32 of 64 branches covered (50.0%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

21 existing lines in 4 files now uncovered.

195 of 229 relevant lines covered (85.15%)

7.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/src/MongoDB.Abstracts/MongoEntityRepository.cs
1
// Ignore Spelling: Mongo
2

3
using System.Linq.Expressions;
4

5
using MongoDB.Driver;
6

7
namespace MongoDB.Abstracts;
8

9
/// <summary>
10
/// A MongoDB data repository base class.
11
/// </summary>
12
/// <typeparam name="TEntity">The type of the entity.</typeparam>
13
public class MongoEntityRepository<TEntity> : MongoRepository<TEntity, string>, IMongoEntityRepository<TEntity>
14
    where TEntity : class, IMongoEntity
15
{
16
    /// <summary>
17
    /// Initializes a new instance of the <see cref="MongoEntityRepository{TEntity}"/> class.
18
    /// </summary>
19
    /// <exception cref="ArgumentNullException"><paramref name="mongoDatabase"/> is <see langword="null" />.</exception>
20
    public MongoEntityRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase)
15✔
21
    {
22

23
    }
15✔
24

25

26
    /// <inheritdoc/>
27
    protected override void BeforeInsert(TEntity entity)
28
    {
29
        entity.Created = DateTimeOffset.UtcNow;
19✔
30
        entity.Updated = DateTimeOffset.UtcNow;
19✔
31

32
        base.BeforeInsert(entity);
19✔
33
    }
19✔
34

35
    /// <inheritdoc/>
36
    protected override void BeforeUpdate(TEntity entity)
37
    {
38
        if (entity.Created == DateTimeOffset.MinValue)
13!
UNCOV
39
            entity.Created = DateTimeOffset.UtcNow;
×
40

41
        entity.Updated = DateTimeOffset.UtcNow;
13✔
42

43
        base.BeforeUpdate(entity);
13✔
44
    }
13✔
45

46

47
    /// <inheritdoc/>
48
    protected override string EntityKey(TEntity entity)
49
    {
50
        return entity.Id;
21✔
51
    }
52

53
    /// <inheritdoc/>
54
    protected override Expression<Func<TEntity, bool>> KeyExpression(string key)
55
    {
56
        return entity => entity.Id == key;
40✔
57
    }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc