diff --git a/src/Context.Tests/MongoCollectionBuilderTests.cs b/src/Context.Tests/MongoCollectionBuilderTests.cs index db074a3..597306f 100644 --- a/src/Context.Tests/MongoCollectionBuilderTests.cs +++ b/src/Context.Tests/MongoCollectionBuilderTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Driver; @@ -190,54 +189,6 @@ public void WithMongoCollectionSettings_DefaultCollectionSettingsConfigured_Defa Assert.True(result.Settings.AssignIdOnInsert); } - #endregion - - #region WithMongoCollectionSettings Tests - - [Fact] - public async Task WithCreateCollectionOptions_SetCappedCollectionOptions_MongoCollectionOptionsChangedToCappedSuccessfully() - { - // Arrange - var mongoCollectionBuilder = new MongoCollectionBuilder(_mongoDatabase); - - // Act - mongoCollectionBuilder.WithCreateCollectionOptions(createCollectionOptions => - { - createCollectionOptions.Capped = true; - createCollectionOptions.MaxSize = 1; - createCollectionOptions.MaxDocuments = 1; - }); - IMongoCollection result = mongoCollectionBuilder.Build(); - - // Assert - var command = new BsonDocumentCommand(new BsonDocument - { - {"collstats", nameof(Order)} - }); - - BsonDocument stats = await _mongoDatabase.RunCommandAsync(command); - Assert.True(stats["capped"].AsBoolean); - } - - [Fact] - public async Task WithCreateCollectionOptions_NoCappedCollectionOptions_DefaultMongoCollectionSettingsSet() - { - // Arrange - var mongoCollectionBuilder = new MongoCollectionBuilder(_mongoDatabase); - - // Act - IMongoCollection result = mongoCollectionBuilder.Build(); - - // Assert - var command = new BsonDocumentCommand(new BsonDocument - { - {"collstats", nameof(Order)} - }); - - BsonDocument stats = await _mongoDatabase.RunCommandAsync(command); - Assert.False(stats["capped"].AsBoolean); - } - #endregion #region WithMongoCollectionConfiguration Tests diff --git a/src/Context/IMongoCollectionBuilder.cs b/src/Context/IMongoCollectionBuilder.cs index 1f12500..a6017e1 100644 --- a/src/Context/IMongoCollectionBuilder.cs +++ b/src/Context/IMongoCollectionBuilder.cs @@ -10,10 +10,7 @@ public interface IMongoCollectionBuilder IMongoCollectionBuilder AddBsonClassMap( Action> bsonClassMapAction) where TMapDocument : class; - - IMongoCollectionBuilder WithCreateCollectionOptions( - Action createCollectionOptions); - + IMongoCollectionBuilder WithCollectionSettings( Action collectionSettings); diff --git a/src/Context/Internal/MongoCollectionBuilder.cs b/src/Context/Internal/MongoCollectionBuilder.cs index cc73ef1..ebc5664 100644 --- a/src/Context/Internal/MongoCollectionBuilder.cs +++ b/src/Context/Internal/MongoCollectionBuilder.cs @@ -10,7 +10,6 @@ internal class MongoCollectionBuilder : IMongoCollectionBuilder _classMapActions; - private readonly List> _createCollectionOptionsActions; private readonly List> _collectionSettingsActions; private readonly List>> _collectionConfigurations; @@ -26,7 +25,6 @@ public MongoCollectionBuilder(IMongoDatabase mongoDatabase) _classMapActions = new List(); _collectionConfigurations = new List>>(); _collectionSettingsActions = new List>(); - _createCollectionOptionsActions = new List>(); } public IMongoCollectionBuilder WithCollectionName(string collectionName) @@ -46,14 +44,6 @@ public IMongoCollectionBuilder AddBsonClassMap( return this; } - - public IMongoCollectionBuilder WithCreateCollectionOptions( - Action createCollectionOptions) - { - _createCollectionOptionsActions.Add(createCollectionOptions); - - return this; - } public IMongoCollectionBuilder WithCollectionSettings( Action collectionSettings) @@ -74,9 +64,7 @@ public IMongoCollectionBuilder WithCollectionConfiguration( internal IMongoCollection Build() { _classMapActions.ForEach(action => action()); - - CreateMongoCollection(); - + IMongoCollection mongoCollection = GetMongoCollection(); _collectionConfigurations.ForEach(configuration => configuration(mongoCollection)); @@ -95,16 +83,6 @@ private IMongoCollection GetMongoCollection() .GetCollection(_collectionName, mongoCollectionSettings); } - private void CreateMongoCollection() - { - var createCollectionOptions = new CreateCollectionOptions(); - - _createCollectionOptionsActions - .ForEach(configure => configure(createCollectionOptions)); - - _mongoDatabase.CreateCollection(_collectionName, createCollectionOptions); - } - private void RegisterClassMapSync( Action> bsonClassMapAction) where TMapDocument : class {