public ContentsQueryFixture() { mongoDatabase = mongoClient.GetDatabase("QueryTests"); SetupJson(); var contentRepository = new MongoContentRepository( mongoDatabase, CreateAppProvider(), CreateTextIndexer(), JsonHelper.DefaultSerializer); Task.Run(async() => { await contentRepository.InitializeAsync(); await mongoDatabase.RunCommandAsync <BsonDocument>("{ profile : 0 }"); await mongoDatabase.DropCollectionAsync("system.profile"); var collections = contentRepository.GetInternalCollections(); foreach (var collection in collections) { var contentCount = await collection.Find(new BsonDocument()).CountDocumentsAsync(); if (contentCount == 0) { var batch = new List <MongoContentEntity>(); async Task ExecuteBatchAsync(MongoContentEntity? entity) { if (entity != null) { batch.Add(entity); } if ((entity == null || batch.Count >= 1000) && batch.Count > 0) { await collection.InsertManyAsync(batch); batch.Clear(); } } foreach (var appId in AppIds) { foreach (var schemaId in SchemaIds) { for (var i = 0; i < numValues; i++) { var data = new IdContentData() .AddField(1, new ContentFieldData() .AddJsonValue(JsonValue.Create(i))) .AddField(2, new ContentFieldData() .AddJsonValue(JsonValue.Create(Lorem.Paragraph(200, 20)))); var content = new MongoContentEntity { DocumentId = DomainId.NewGuid(), AppId = appId, DataByIds = data, IndexedAppId = appId.Id, IndexedSchemaId = schemaId.Id, IsDeleted = false, SchemaId = schemaId, Status = Status.Published }; await ExecuteBatchAsync(content); } } } await ExecuteBatchAsync(null); } } await mongoDatabase.RunCommandAsync <BsonDocument>("{ profile : 2 }"); }).Wait(); ContentRepository = contentRepository; }
private async Task SetupAsync(MongoContentRepository contentRepository, IMongoDatabase database) { await contentRepository.InitializeAsync(); await database.RunCommandAsync <BsonDocument>("{ profile : 0 }"); await database.DropCollectionAsync("system.profile"); var collections = contentRepository.GetInternalCollections(); foreach (var collection in collections) { var contentCount = await collection.Find(new BsonDocument()).CountDocumentsAsync(); if (contentCount == 0) { var batch = new List <MongoContentEntity>(); async Task ExecuteBatchAsync(MongoContentEntity?entity) { if (entity != null) { batch.Add(entity); } if ((entity == null || batch.Count >= 1000) && batch.Count > 0) { await collection.InsertManyAsync(batch); batch.Clear(); } } foreach (var appId in AppIds) { foreach (var schemaId in SchemaIds) { for (var i = 0; i < numValues; i++) { var data = new ContentData() .AddField("field1", new ContentFieldData() .AddInvariant(JsonValue.Create(i))) .AddField("field2", new ContentFieldData() .AddInvariant(JsonValue.Create(Lorem.Paragraph(200, 20)))); var content = new MongoContentEntity { DocumentId = DomainId.NewGuid(), AppId = appId, Data = data, IndexedAppId = appId.Id, IndexedSchemaId = schemaId.Id, IsDeleted = false, SchemaId = schemaId, Status = Status.Published }; await ExecuteBatchAsync(content); } } } await ExecuteBatchAsync(null); } } await database.RunCommandAsync <BsonDocument>("{ profile : 2 }"); }
public static bool HasStatus(this MongoContentEntity content, Status[]?status) { return(status == null || status.Contains(content.Status)); }