sonarr-repo-only/NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2010-09-27 00:22:44 +00:00
using System;
using Ninject.Activation.Caching;
using Ninject.Planning.Bindings;
namespace Ninject.Moq
{
2010-10-18 18:04:07 +00:00
/// <summary>
2011-04-10 02:44:01 +00:00
/// A kernel that will create mocked instances (via Moq) for any service that is
/// requested for which no binding is registered.
2010-10-18 18:04:07 +00:00
/// </summary>
public class MockingKernel : StandardKernel
{
/// <summary>
2011-04-10 02:44:01 +00:00
/// Clears the kernel's cache, immediately deactivating all activated instances regardless of scope.
/// This does not remove any modules, extensions, or bindings.
2010-10-18 18:04:07 +00:00
/// </summary>
public void Reset()
{
Components.Get<ICache>().Clear();
}
2010-09-27 00:22:44 +00:00
2010-10-18 18:04:07 +00:00
/// <summary>
2011-04-10 02:44:01 +00:00
/// Attempts to handle a missing binding for a service.
2010-10-18 18:04:07 +00:00
/// </summary>
2011-04-10 02:44:01 +00:00
/// <param name = "service">The service.</param>
2010-10-18 18:04:07 +00:00
/// <returns><c>True</c> if the missing binding can be handled; otherwise <c>false</c>.</returns>
protected override bool HandleMissingBinding(Type service)
{
var binding = new Binding(service)
2011-04-10 02:44:01 +00:00
{
ProviderCallback = MockProvider.GetCreationCallback(),
ScopeCallback = ctx => null,
IsImplicit = true
};
2010-09-27 00:22:44 +00:00
2010-10-18 18:04:07 +00:00
AddBinding(binding);
2010-09-27 00:22:44 +00:00
2010-10-18 18:04:07 +00:00
return true;
}
}
2011-04-10 02:44:01 +00:00
}