read only and tests
This commit is contained in:
@@ -4,23 +4,21 @@ using MongoDbGenericRepository.Models;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure.Model;
|
||||
|
||||
|
||||
public class TestDocument : Document
|
||||
{
|
||||
public TestDocument()
|
||||
{
|
||||
Version = 2;
|
||||
Nested = new Nested
|
||||
{
|
||||
SomeDate = DateTime.UtcNow
|
||||
};
|
||||
Nested = new Nested {SomeDate = DateTime.UtcNow};
|
||||
Children = new List<Child>();
|
||||
}
|
||||
|
||||
public int SomeValue { get; set; }
|
||||
|
||||
public string SomeContent { get; set; }
|
||||
|
||||
public string SomeContent2 { get; set; }
|
||||
|
||||
public string SomeContent3 { get; set; }
|
||||
|
||||
public int GroupingKey { get; set; }
|
||||
@@ -29,4 +27,3 @@ public class TestDocument : Document
|
||||
|
||||
public List<Child> Children { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -7,4 +7,6 @@ public class TestProjection
|
||||
public Guid TestDocumentId { get; set; }
|
||||
|
||||
public DateTime NestedData { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
@@ -16,23 +16,11 @@ public class TestKeyedMongoRepository<TKey> : BaseMongoRepository<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
public void SetIndexHandler(IMongoDbIndexHandler indexHandler)
|
||||
{
|
||||
MongoDbIndexHandler = indexHandler;
|
||||
}
|
||||
public void SetIndexHandler(IMongoDbIndexHandler indexHandler) => MongoDbIndexHandler = indexHandler;
|
||||
|
||||
public void SetDbCreator(IMongoDbCreator creator)
|
||||
{
|
||||
MongoDbCreator = creator;
|
||||
}
|
||||
public void SetDbCreator(IMongoDbCreator creator) => MongoDbCreator = creator;
|
||||
|
||||
public void SetReader(IMongoDbReader reader)
|
||||
{
|
||||
MongoDbReader = reader;
|
||||
}
|
||||
public void SetReader(IMongoDbReader reader) => MongoDbReader = reader;
|
||||
|
||||
public void SetEraser(IMongoDbEraser eraser)
|
||||
{
|
||||
MongoDbEraser = eraser;
|
||||
}
|
||||
}
|
||||
public void SetEraser(IMongoDbEraser eraser) => MongoDbEraser = eraser;
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace CoreUnitTests.Infrastructure;
|
||||
public class TestKeyedMongoRepositoryContext<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private readonly Mock<IMongoDatabase> _mongoDatabase;
|
||||
private readonly Mock<IMongoDatabase> mongoDatabase;
|
||||
|
||||
private TestKeyedMongoRepository<TKey> _sut;
|
||||
private TestKeyedMongoRepository<TKey> sut;
|
||||
|
||||
protected TestKeyedMongoRepositoryContext()
|
||||
{
|
||||
_mongoDatabase = new Mock<IMongoDatabase>();
|
||||
mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
@@ -28,33 +28,33 @@ public class TestKeyedMongoRepositoryContext<TKey>
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_sut != null)
|
||||
if (sut != null)
|
||||
{
|
||||
return _sut;
|
||||
return sut;
|
||||
}
|
||||
|
||||
_sut = new TestKeyedMongoRepository<TKey>(_mongoDatabase.Object);
|
||||
sut = new TestKeyedMongoRepository<TKey>(mongoDatabase.Object);
|
||||
if (IndexHandler != null)
|
||||
{
|
||||
_sut.SetIndexHandler(IndexHandler.Object);
|
||||
sut.SetIndexHandler(IndexHandler.Object);
|
||||
}
|
||||
|
||||
if (Creator != null)
|
||||
{
|
||||
_sut.SetDbCreator(Creator.Object);
|
||||
sut.SetDbCreator(Creator.Object);
|
||||
}
|
||||
|
||||
if (Reader != null)
|
||||
{
|
||||
_sut.SetReader(Reader.Object);
|
||||
sut.SetReader(Reader.Object);
|
||||
}
|
||||
|
||||
if (Eraser != null)
|
||||
{
|
||||
_sut.SetEraser(Eraser.Object);
|
||||
sut.SetEraser(Eraser.Object);
|
||||
}
|
||||
|
||||
return _sut;
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +65,4 @@ public class TestKeyedMongoRepositoryContext<TKey>
|
||||
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||
|
||||
protected Mock<IMongoDbEraser> Eraser { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedReadOnlyMongoRepository<TKey> : ReadOnlyMongoRepository<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(string connectionString, string databaseName = null)
|
||||
: base(connectionString, databaseName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(IMongoDatabase mongoDatabase)
|
||||
: base(mongoDatabase)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TestKeyedReadOnlyMongoRepository(IMongoDbContext mongoDbContext)
|
||||
: base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetReader(IMongoDbReader reader) => MongoDbReader = reader;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using AutoFixture;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedReadOnlyMongoRepositoryContext<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private readonly Mock<IMongoDatabase> mongoDatabase;
|
||||
|
||||
private TestKeyedReadOnlyMongoRepository<TKey> sut;
|
||||
|
||||
protected TestKeyedReadOnlyMongoRepositoryContext()
|
||||
{
|
||||
mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
protected Fixture Fixture { get; set; }
|
||||
|
||||
protected TestKeyedReadOnlyMongoRepository<TKey> Sut
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sut != null)
|
||||
{
|
||||
return sut;
|
||||
}
|
||||
|
||||
sut = new TestKeyedReadOnlyMongoRepository<TKey>(mongoDatabase.Object);
|
||||
|
||||
if (Reader != null)
|
||||
{
|
||||
sut.SetReader(Reader.Object);
|
||||
}
|
||||
|
||||
return sut;
|
||||
}
|
||||
}
|
||||
|
||||
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user