Skip to content

Commit

Permalink
#79 enhancement/improve enginebuilder error message (#80)
Browse files Browse the repository at this point in the history
* test, and fix

* undo unused change

* neaten up hint message

* not using list of candidates in message any more

* shorten test name
  • Loading branch information
goblinfactory authored and rofr committed Jan 20, 2020
1 parent 2e94c03 commit c47bd8e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Memstate.Core/Configuration/Providers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ protected T AutoResolve()
return provider;
}
}
throw new Exception("Autoresolve failed for " + typeof(T));

var hint = "Please check to see if you need to add a reference to 'Memstate.Wire', or 'Memstate.JsonNet'. Adding any of these two nuget packages will automatically use either package for serialisation.";
throw new Exception($"Autoresolve failed for {typeof(T)}. {hint}");
}

internal class Registry : Dictionary<string, Func<T>>
Expand Down
41 changes: 41 additions & 0 deletions src/Memstate.Test/EngineBuilderTests/BuildTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Memstate.Configuration;
using NUnit.Framework;
using System.Threading.Tasks;

namespace Memstate.Test.EngineBuilderTests
{
[TestFixture]
class BuildTests
{
internal class TestSerializers : Serializers
{
internal TestSerializers()
{
RegisteredProviders.Remove("Wire");
RegisteredProviders.Remove("NewtonSoft.Json");
}
}

[Test]
public async Task WhenNoSerializers_BuildShould_ReturnErrorMessageContainingSuggestedPackagesToReference()
{
// pretend this is a new users project and no defaults could be loaded
// remove the default storage providers that will be picked up
// because this test project references Wire and JsonNet,
var config = Config.Reset();
config.Serializers = new TestSerializers();

try
{
var engine = await new EngineBuilder().Build<List<int>>();
Assert.Fail("Should not get here");
}
catch (Exception ex)
{
StringAssert.Contains("Please check to see if you need to add a reference to 'Memstate.Wire', or 'Memstate.JsonNet'. Adding any of these two nuget packages will automatically use either package for serialisation.", ex.Message);
}
}
}
}

0 comments on commit c47bd8e

Please sign in to comment.