Skip to content

Commit 3e9576d

Browse files
Merge pull request #277 from Avanade/feat/newcartridges
test: fix Mongo Repository Unit tests.
2 parents 9fa0862 + 1c6aaf7 commit 3e9576d

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

src/Liquid.Repository.Mongo/Exceptions/MongoException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Liquid.Repository.Mongo.Exceptions
88
/// Occurs when an exception has occurred in Mongo Db.
99
/// </summary>
1010
/// <seealso cref="LiquidException" />
11-
[Serializable]
1211
[ExcludeFromCodeCoverage]
1312
public class MongoException : LiquidException
1413
{

src/Liquid.Repository.Mongo/MongoClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MongoClientFactory : IMongoClientFactory
2020
public MongoClientFactory(IOptions<MongoDbSettings> settings)
2121
{
2222
_mongoClients = new Dictionary<string, IMongoClient>();
23-
_settings = settings;
23+
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
2424
}
2525

2626
///<inheritdoc/>

test/Liquid.Repository.Mongo.Tests/IServiceCollectionExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IServiceCollectionExtensionsTests()
2929
var options = new MongoRunnerOptions
3030
{
3131
UseSingleNodeReplicaSet = false,
32-
AdditionalArguments = "--quiet"
32+
AdditionalArguments = "--quiet",
3333
};
3434

3535
_runner = MongoRunner.Run(options);
@@ -43,7 +43,7 @@ public IServiceCollectionExtensionsTests()
4343
{
4444
{"MyMongoEntityOptions:Settings:1:DatabaseName", _databaseName},
4545
{"MyMongoEntityOptions:Settings:1:ConnectionString", _runner.ConnectionString},
46-
{"MyMongoEntityOptions:Settings:1:CollectionName", "TestEntity"},
46+
{"MyMongoEntityOptions:Settings:1:CollectionName", "ATestEntity"},
4747
{"MyMongoEntityOptions:Settings:1:ShardKey", "id"},
4848
{"MyMongoEntityOptions:Settings:2:DatabaseName", _databaseName},
4949
{"MyMongoEntityOptions:Settings:2:ConnectionString", _runner.ConnectionString},
@@ -60,7 +60,7 @@ public IServiceCollectionExtensionsTests()
6060
[Fact]
6161
public void AddLiquidMongoRepository_WhenAdded_ServicesIsFilledForTestEntity()
6262
{
63-
_services.AddLiquidMongoRepository<TestEntity, int>("MyMongoEntityOptions","TestEntity");
63+
_services.AddLiquidMongoRepository<TestEntity, int>("MyMongoEntityOptions","ATestEntity");
6464
_services.AddLiquidMongoRepository<AnotherTestEntity, int>("MyMongoEntityOptions", "AnotherTestEntity");
6565
_serviceProvider = _services.BuildServiceProvider();
6666
Assert.NotNull(_serviceProvider.GetService<IMongoDataContext<TestEntity>>());

test/Liquid.Repository.Mongo.Tests/Liquid.Repository.Mongo.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
1919
<PackageReference Include="EphemeralMongo.Core" Version="2.0.0" />
20-
<PackageReference Include="EphemeralMongo6.runtime.linux-x64" Version="1.1.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
21-
<PackageReference Include="EphemeralMongo6.runtime.osx-x64" Version="1.1.0" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
22-
<PackageReference Include="EphemeralMongo6.runtime.win-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
20+
<PackageReference Include="EphemeralMongo8.runtime.linux-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
21+
<PackageReference Include="EphemeralMongo8.runtime.osx-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
22+
<PackageReference Include="EphemeralMongo8.runtime.win-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
2323
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.4" />
2424
<PackageReference Include="NSubstitute" Version="5.3.0" />
2525
<PackageReference Include="xunit" Version="2.9.3" />

test/Liquid.Repository.Mongo.Tests/MongoClientFactoryTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public MongoClientFactoryTests()
2121
var options = new MongoRunnerOptions
2222
{
2323
UseSingleNodeReplicaSet = false,
24-
AdditionalArguments = "--quiet"
24+
AdditionalArguments = "--quiet",
2525
};
2626

2727
_runner = MongoRunner.Run(options);
@@ -44,7 +44,7 @@ public MongoClientFactoryTests()
4444
{
4545
CollectionName = "TestEntities2",
4646
ShardKey = "id",
47-
ConnectionString = "incorrect connection string",
47+
ConnectionString = "",
4848
DatabaseName = $"{_databaseName}-2"
4949
}
5050
}
@@ -78,5 +78,11 @@ public void GetClient_WhenDatabaseSettingsIsWrong_ThrowException()
7878
MongoEntitySettings settings = null;
7979
Assert.Throws<MongoDB.Driver.MongoConfigurationException>(() => _sut.GetClient("TestEntities2", out settings));
8080
}
81+
82+
[Fact]
83+
public void Constructor_WhenSettingsIsNull_ThrowException()
84+
{
85+
Assert.Throws<ArgumentNullException>(() => new MongoClientFactory(null));
86+
}
8187
}
8288
}

0 commit comments

Comments
 (0)