From 657beeac9973e5a9a2abdcf3c610d48c085ffcdd Mon Sep 17 00:00:00 2001 From: alexandre-spieser Date: Wed, 1 Nov 2017 08:18:29 +0000 Subject: [PATCH] The MongoDbRepository now has a constructor that takes an IMongoDatabase. --- CoreIntegrationTests/CreatePartitionedTests.cs | 4 ++-- CoreIntegrationTests/CreateTests.cs | 4 ++-- CoreIntegrationTests/DeletePartitionedTests.cs | 4 ++-- CoreIntegrationTests/DeleteTests.cs | 4 ++-- CoreIntegrationTests/IdentityUserTests.cs | 6 ++---- .../Infrastructure/BaseMongoDbRepositoryTests.cs | 2 +- CoreIntegrationTests/Infrastructure/ITestRepository.cs | 2 +- CoreIntegrationTests/Infrastructure/MongoDbConfig.cs | 4 ++-- CoreIntegrationTests/Infrastructure/TestRepository.cs | 2 +- CoreIntegrationTests/ProjectPartitionedTests.cs | 4 ++-- CoreIntegrationTests/ProjectTests.cs | 4 ++-- CoreIntegrationTests/ReadPartitionedTests.cs | 4 ++-- CoreIntegrationTests/ReadTests.cs | 4 ++-- CoreIntegrationTests/UpdatePartitionedTests.cs | 4 ++-- CoreIntegrationTests/UpdateTests.cs | 4 ++-- MongoDbGenericRepository/BaseMongoDbRepository.cs | 10 ++++++++++ MongoDbGenericRepository/IMongoDbContext.cs | 6 ++++++ MongoDbGenericRepository/MongoDbContext.cs | 9 +++++++++ 18 files changed, 52 insertions(+), 29 deletions(-) diff --git a/CoreIntegrationTests/CreatePartitionedTests.cs b/CoreIntegrationTests/CreatePartitionedTests.cs index 5f11707..bfad21e 100644 --- a/CoreIntegrationTests/CreatePartitionedTests.cs +++ b/CoreIntegrationTests/CreatePartitionedTests.cs @@ -1,10 +1,10 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Collections.Generic; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class CreateTestsPartitionedDocument : PartitionedDocument { diff --git a/CoreIntegrationTests/CreateTests.cs b/CoreIntegrationTests/CreateTests.cs index 1437d87..e54be04 100644 --- a/CoreIntegrationTests/CreateTests.cs +++ b/CoreIntegrationTests/CreateTests.cs @@ -1,10 +1,10 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Collections.Generic; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class CreateTestsDocument : Document { diff --git a/CoreIntegrationTests/DeletePartitionedTests.cs b/CoreIntegrationTests/DeletePartitionedTests.cs index 823f853..486c462 100644 --- a/CoreIntegrationTests/DeletePartitionedTests.cs +++ b/CoreIntegrationTests/DeletePartitionedTests.cs @@ -1,9 +1,9 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class DeleteTestsPartitionedDocument : PartitionedDocument { diff --git a/CoreIntegrationTests/DeleteTests.cs b/CoreIntegrationTests/DeleteTests.cs index 4db073f..249b1b7 100644 --- a/CoreIntegrationTests/DeleteTests.cs +++ b/CoreIntegrationTests/DeleteTests.cs @@ -1,9 +1,9 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class DeleteTestsDocument : Document { diff --git a/CoreIntegrationTests/IdentityUserTests.cs b/CoreIntegrationTests/IdentityUserTests.cs index 04771b9..4554479 100644 --- a/CoreIntegrationTests/IdentityUserTests.cs +++ b/CoreIntegrationTests/IdentityUserTests.cs @@ -1,14 +1,12 @@ -using IntegrationTests.Infrastructure; -using MongoDB.Bson.Serialization.Attributes; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; -using System.Text; using Xunit; using Microsoft.AspNetCore.Identity; using System.Threading.Tasks; -namespace CoreIntegrationTests +namespace CoreCoreIntegrationTests { public class MongoIdentityUser : IdentityUser, IDocument where TKey : IEquatable diff --git a/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs b/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs index e8a31f9..22b5423 100644 --- a/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs +++ b/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System; -namespace IntegrationTests.Infrastructure +namespace CoreIntegrationTests.Infrastructure { public class BaseMongoDbRepositoryTests : IDisposable where T : new() diff --git a/CoreIntegrationTests/Infrastructure/ITestRepository.cs b/CoreIntegrationTests/Infrastructure/ITestRepository.cs index c2d672c..8354848 100644 --- a/CoreIntegrationTests/Infrastructure/ITestRepository.cs +++ b/CoreIntegrationTests/Infrastructure/ITestRepository.cs @@ -1,6 +1,6 @@ using MongoDbGenericRepository; -namespace IntegrationTests +namespace CoreIntegrationTests { public interface ITestRepository : IBaseMongoRepository { diff --git a/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs b/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs index 7dd3e84..8964789 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs @@ -1,9 +1,9 @@ -using CoreIntegrationTests; +using CoreCoreIntegrationTests; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Conventions; using System.Threading; -namespace IntegrationTests.Infrastructure +namespace CoreIntegrationTests.Infrastructure { internal static class MongoDbConfig { diff --git a/CoreIntegrationTests/Infrastructure/TestRepository.cs b/CoreIntegrationTests/Infrastructure/TestRepository.cs index ae2a1d6..8b3145e 100644 --- a/CoreIntegrationTests/Infrastructure/TestRepository.cs +++ b/CoreIntegrationTests/Infrastructure/TestRepository.cs @@ -1,6 +1,6 @@ using MongoDbGenericRepository; -namespace IntegrationTests.Infrastructure +namespace CoreIntegrationTests.Infrastructure { /// /// A singleton implementation of the TestRepository diff --git a/CoreIntegrationTests/ProjectPartitionedTests.cs b/CoreIntegrationTests/ProjectPartitionedTests.cs index c3bb73e..4d0caac 100644 --- a/CoreIntegrationTests/ProjectPartitionedTests.cs +++ b/CoreIntegrationTests/ProjectPartitionedTests.cs @@ -1,11 +1,11 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System; using System.Linq; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class ProjectTestsPartitionedDocument : PartitionedDocument { diff --git a/CoreIntegrationTests/ProjectTests.cs b/CoreIntegrationTests/ProjectTests.cs index 901d93e..fc30c46 100644 --- a/CoreIntegrationTests/ProjectTests.cs +++ b/CoreIntegrationTests/ProjectTests.cs @@ -1,11 +1,11 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System; using System.Linq; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class Nested { diff --git a/CoreIntegrationTests/ReadPartitionedTests.cs b/CoreIntegrationTests/ReadPartitionedTests.cs index abe20c5..b9e8c05 100644 --- a/CoreIntegrationTests/ReadPartitionedTests.cs +++ b/CoreIntegrationTests/ReadPartitionedTests.cs @@ -1,10 +1,10 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class ReadTestsPartitionedDocument : PartitionedDocument { diff --git a/CoreIntegrationTests/ReadTests.cs b/CoreIntegrationTests/ReadTests.cs index 3dfaf14..66ccea7 100644 --- a/CoreIntegrationTests/ReadTests.cs +++ b/CoreIntegrationTests/ReadTests.cs @@ -1,10 +1,10 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class ReadTestsDocument : Document { diff --git a/CoreIntegrationTests/UpdatePartitionedTests.cs b/CoreIntegrationTests/UpdatePartitionedTests.cs index 3f1c0a7..65658b6 100644 --- a/CoreIntegrationTests/UpdatePartitionedTests.cs +++ b/CoreIntegrationTests/UpdatePartitionedTests.cs @@ -1,9 +1,9 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class UpdateTestsPartitionedDocument : PartitionedDocument { diff --git a/CoreIntegrationTests/UpdateTests.cs b/CoreIntegrationTests/UpdateTests.cs index 69f7f9b..f8bd2da 100644 --- a/CoreIntegrationTests/UpdateTests.cs +++ b/CoreIntegrationTests/UpdateTests.cs @@ -1,9 +1,9 @@ -using IntegrationTests.Infrastructure; +using CoreIntegrationTests.Infrastructure; using MongoDbGenericRepository.Models; using Xunit; using System.Threading.Tasks; -namespace IntegrationTests +namespace CoreIntegrationTests { public class UpdateTestsDocument : Document { diff --git a/MongoDbGenericRepository/BaseMongoDbRepository.cs b/MongoDbGenericRepository/BaseMongoDbRepository.cs index 3059736..48ed66f 100644 --- a/MongoDbGenericRepository/BaseMongoDbRepository.cs +++ b/MongoDbGenericRepository/BaseMongoDbRepository.cs @@ -900,6 +900,15 @@ namespace MongoDbGenericRepository MongoDbContext = mongoDbContext; } + /// + /// The contructor taking a . + /// + /// A mongodb context implementing + protected BaseMongoRepository(IMongoDatabase mongoDatabase) + { + MongoDbContext = new MongoDbContext(mongoDatabase); + } + /// /// The MongoDbContext /// @@ -2009,6 +2018,7 @@ namespace MongoDbGenericRepository } + /// /// Groups filtered a collection of documents given a grouping criteria, /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. /// diff --git a/MongoDbGenericRepository/IMongoDbContext.cs b/MongoDbGenericRepository/IMongoDbContext.cs index ca2b297..f3497fc 100644 --- a/MongoDbGenericRepository/IMongoDbContext.cs +++ b/MongoDbGenericRepository/IMongoDbContext.cs @@ -53,5 +53,11 @@ namespace MongoDbGenericRepository /// /// void DropCollection(string partitionKey); + + /// + /// Sets the Guid representation of the MongoDb Driver. + /// + /// The new value of the GuidRepresentation + void SetGuidRepresentation(MongoDB.Bson.GuidRepresentation guidRepresentation); } } \ No newline at end of file diff --git a/MongoDbGenericRepository/MongoDbContext.cs b/MongoDbGenericRepository/MongoDbContext.cs index 2223fe3..f3854e9 100644 --- a/MongoDbGenericRepository/MongoDbContext.cs +++ b/MongoDbGenericRepository/MongoDbContext.cs @@ -25,6 +25,15 @@ namespace MongoDbGenericRepository MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard; } + /// + /// Sets the Guid representation of the MongoDb Driver. + /// + /// The new value of the GuidRepresentation + public void SetGuidRepresentation(MongoDB.Bson.GuidRepresentation guidRepresentation) + { + MongoDefaults.GuidRepresentation = guidRepresentation; + } + /// /// The constructor of the MongoDbContext, it needs a an object implementing . ///