Esempio n. 1
0
 /// <summary>
 /// Create a new instance of <see cref="RepositoryBase"/>.
 /// </summary>
 /// <param name="mongoDbContext"></param>
 /// <param name="logger"></param>
 /// <param name="mapper"></param>
 protected RepositoryBase(IMongoDbContext mongoDbContext, ILogger <RepositoryBase> logger, IMapper mapper)
 {
     MongoDbContext = mongoDbContext;
     MongoDatabase  = MongoDbContext.GetDatabase();
     Logger         = logger;
     Mapper         = mapper;
 }
Esempio n. 2
0
        public DbRepository(IMongoDbContext mongoDbContext)
        {
            var collectionName = typeof(T).Name;
            var mongoDatabase  = mongoDbContext.GetDatabase();

            _mongoDbCollection = mongoDatabase.GetCollection <T>(collectionName);
        }
        public async Task CrudOperationWithServiceProvider_OnInsertOneAndFind_ShouldReturnInsertedDocument()
        {
            // Arrange
            var database   = _mongoDbContext.GetDatabase(_configuration.DatabaseName);
            var collection = database.GetCollection <BsonDocument>("bar2");

            // Act
            await collection.InsertOneAsync(new BsonDocument("name", "Jacky"));

            var entities = await collection.Find(new BsonDocument("name", "Jacky"))
                           .ToListAsync();

            // Assert
            entities.Should().NotBeNullOrEmpty();
            entities[0]["_id"].AsObjectId.Should().NotBeNull();
            entities[0]["name"].Should().Be("Jacky");
        }
Esempio n. 4
0
 public IMongoCollection <T> GetCollection <T>()
 {
     return(_context.GetDatabase().GetCollection <T>(typeof(T).Name));
 }
Esempio n. 5
0
 public DataImportService(ImportConfig config, IMongoDbContext mongoDbContext)
 {
     _importConfig  = config;
     _mongoDatabase = mongoDbContext.GetDatabase();
 }