keyed Delete unit tests
This commit is contained in:
@@ -4,11 +4,12 @@ using MongoDbGenericRepository.Models;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure.Model;
|
||||
|
||||
public class TestDocumentWithKey : IDocument<int>
|
||||
public class TestDocumentWithKey<TKey> : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public TKey Id { get; set; }
|
||||
public int Version { get; set; }
|
||||
|
||||
|
||||
public TestDocumentWithKey()
|
||||
{
|
||||
Version = 2;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository;
|
||||
using MongoDbGenericRepository.DataAccess.Create;
|
||||
using MongoDbGenericRepository.DataAccess.Delete;
|
||||
using MongoDbGenericRepository.DataAccess.Index;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedMongoRepository : BaseMongoRepository<int>
|
||||
public class TestKeyedMongoRepository<TKey> : BaseMongoRepository<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TestKeyedMongoRepository(IMongoDatabase mongoDatabase)
|
||||
: base(mongoDatabase)
|
||||
@@ -27,4 +30,9 @@ public class TestKeyedMongoRepository : BaseMongoRepository<int>
|
||||
{
|
||||
MongoDbReader = reader;
|
||||
}
|
||||
|
||||
public void SetEraser(IMongoDbEraser eraser)
|
||||
{
|
||||
MongoDbEraser = eraser;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,30 @@
|
||||
using System;
|
||||
using AutoFixture;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.DataAccess.Create;
|
||||
using MongoDbGenericRepository.DataAccess.Delete;
|
||||
using MongoDbGenericRepository.DataAccess.Index;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
|
||||
namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestKeyedMongoRepositoryContext
|
||||
public class TestKeyedMongoRepositoryContext<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
private readonly Mock<IMongoDatabase> _mongoDatabase;
|
||||
|
||||
private TestKeyedMongoRepository _sut;
|
||||
private TestKeyedMongoRepository<TKey> _sut;
|
||||
|
||||
protected TestKeyedMongoRepositoryContext()
|
||||
{
|
||||
_mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
protected TestKeyedMongoRepository Sut
|
||||
protected Fixture Fixture { get; set; }
|
||||
|
||||
protected TestKeyedMongoRepository<TKey> Sut
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -26,7 +33,7 @@ public class TestKeyedMongoRepositoryContext
|
||||
return _sut;
|
||||
}
|
||||
|
||||
_sut = new TestKeyedMongoRepository(_mongoDatabase.Object);
|
||||
_sut = new TestKeyedMongoRepository<TKey>(_mongoDatabase.Object);
|
||||
if (IndexHandler != null)
|
||||
{
|
||||
_sut.SetIndexHandler(IndexHandler.Object);
|
||||
@@ -42,12 +49,20 @@ public class TestKeyedMongoRepositoryContext
|
||||
_sut.SetReader(Reader.Object);
|
||||
}
|
||||
|
||||
if (Eraser != null)
|
||||
{
|
||||
_sut.SetEraser(Eraser.Object);
|
||||
}
|
||||
|
||||
return _sut;
|
||||
}
|
||||
}
|
||||
|
||||
protected Mock<IMongoDbIndexHandler> IndexHandler { get; set; }
|
||||
|
||||
protected Mock<IMongoDbCreator> Creator { get; set; }
|
||||
|
||||
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||
|
||||
protected Mock<IMongoDbEraser> Eraser { get; set; }
|
||||
}
|
||||
@@ -8,10 +8,11 @@ namespace CoreUnitTests.Infrastructure;
|
||||
|
||||
public class TestMongoRepository : BaseMongoRepository
|
||||
{
|
||||
public TestMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase)
|
||||
public TestMongoRepository(IMongoDatabase mongoDatabase)
|
||||
: base(mongoDatabase)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void SetIndexHandler(IMongoDbIndexHandler indexHandler)
|
||||
{
|
||||
MongoDbIndexHandler = indexHandler;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using AutoFixture;
|
||||
using MongoDB.Driver;
|
||||
using MongoDbGenericRepository.DataAccess.Create;
|
||||
using MongoDbGenericRepository.DataAccess.Delete;
|
||||
using MongoDbGenericRepository.DataAccess.Index;
|
||||
using MongoDbGenericRepository.DataAccess.Read;
|
||||
using Moq;
|
||||
@@ -15,8 +17,11 @@ public class TestMongoRepositoryContext
|
||||
protected TestMongoRepositoryContext()
|
||||
{
|
||||
_mongoDatabase = new Mock<IMongoDatabase>();
|
||||
Fixture = new Fixture();
|
||||
}
|
||||
|
||||
public Fixture Fixture { get; set; }
|
||||
|
||||
protected TestMongoRepository Sut
|
||||
{
|
||||
get
|
||||
@@ -31,7 +36,7 @@ public class TestMongoRepositoryContext
|
||||
|
||||
if (Creator != null)
|
||||
{
|
||||
_sut.SetDbCreator(Creator.Object);
|
||||
_sut.SetDbCreator(Creator.Object);
|
||||
}
|
||||
|
||||
if (Reader != null)
|
||||
@@ -45,7 +50,10 @@ public class TestMongoRepositoryContext
|
||||
}
|
||||
|
||||
protected Mock<IMongoDbIndexHandler> IndexHandler { get; set; }
|
||||
|
||||
protected Mock<IMongoDbCreator> Creator { get; set; }
|
||||
|
||||
protected Mock<IMongoDbReader> Reader { get; set; }
|
||||
|
||||
protected Mock<IMongoDbEraser> Eraser { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user