Skip to content

Commit 68dae67

Browse files
Merge pull request #688 from johelvisguzman/GH-676
(GH-676) Add more info link to the no context provider configured exception
2 parents b7bdec1 + 73bd86e commit 68dae67

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

src/DotNetToolkit.Repository/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DotNetToolkit.Repository/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@
168168
<data name="GroupBySortingNotSupported" xml:space="preserve">
169169
<value>This context provider does not support groupby operation with sorting.</value>
170170
</data>
171+
<data name="ContextProviderNotConfiguered" xml:space="preserve">
172+
<value>No context provider has been configured. For more information on DotNetToolkit.Repository options configuration, visit the https://github.com/johelvisguzman/DotNetToolkit.Repository/wiki/Repository-Options-Configuration.</value>
173+
</data>
171174
</root>

src/DotNetToolkit.Repository/RepositoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ internal InternalRepositoryBase([NotNull] IRepositoryOptions options)
10391039

10401040
_options = optionsBuilder.Options;
10411041

1042-
_contextFactory = Guard.EnsureNotNull(_options.ContextFactory, "No context provider has been configured for this repository.");
1042+
_contextFactory = Guard.EnsureNotNull(_options.ContextFactory, Resources.ContextProviderNotConfiguered);
10431043

10441044
// Sets the default logger provider (prints all messages levels)
10451045
_loggerProvider = _options.LoggerProvider ?? new ConsoleLoggerProvider(LogLevel.Debug);

src/DotNetToolkit.Repository/Transactions/UnitOfWork.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using Configuration;
44
using JetBrains.Annotations;
5+
using Properties;
56
using Repository.Internal;
67
using System;
78
using Utility;
@@ -80,7 +81,7 @@ private void Initialize([NotNull] IRepositoryOptions options)
8081
{
8182
Guard.NotNull(options, nameof(options));
8283

83-
var contextFactory = Guard.EnsureNotNull(options.ContextFactory, "No context provider has been configured for this unit of work.");
84+
var contextFactory = Guard.EnsureNotNull(options.ContextFactory, Resources.ContextProviderNotConfiguered);
8485

8586
_context = contextFactory.Create();
8687
_transactionManager = _context.BeginTransaction();

test/DotNetToolkit.Repository.Integration.Test/Tests/Repository/RepositoryTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public void ThrowsIfEntityHasNoIdOnContextCreation()
4848
ForAllRepositoryFactories(TestThrowsIfEntityHasNoIdOnContextCreation);
4949
}
5050

51+
[Fact]
52+
public void ThrowsIfContextProviderNotConfiguered()
53+
{
54+
var options = new RepositoryOptionsBuilder().Options;
55+
var ex = Assert.Throws<InvalidOperationException>(() => new Repository<Customer>(options));
56+
57+
Assert.Equal("No context provider has been configured. For more information on DotNetToolkit.Repository options configuration, visit the https://github.com/johelvisguzman/DotNetToolkit.Repository/wiki/Repository-Options-Configuration.", ex.Message);
58+
}
59+
5160
private static void TestFactoryCreate(IRepositoryFactory repoFactory)
5261
{
5362
Assert.NotNull(repoFactory.Create<Customer>());

test/DotNetToolkit.Repository.Integration.Test/Tests/UnitOfWork/UnitOfWorkTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ private static void TestFactoryCreate(IUnitOfWorkFactory uowFactory)
5858
Assert.NotNull(uowFactory.CreateInstance<UnitOfWork>());
5959
}
6060

61+
[Fact]
62+
public void ThrowsIfContextProviderNotConfiguered()
63+
{
64+
var options = new RepositoryOptionsBuilder().Options;
65+
var ex = Assert.Throws<InvalidOperationException>(() => new UnitOfWork(options));
66+
67+
Assert.Equal("No context provider has been configured. For more information on DotNetToolkit.Repository options configuration, visit the https://github.com/johelvisguzman/DotNetToolkit.Repository/wiki/Repository-Options-Configuration.", ex.Message);
68+
}
69+
6170
private static void TestDisposeRollBackUnCommittedChanges(IUnitOfWorkFactory uowFactory)
6271
{
6372
using (var uow = uowFactory.Create())

0 commit comments

Comments
 (0)