1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Core.Test/Ninject.Moq/MockingKernel.cs

42 lines
1.3 KiB
C#
Raw Normal View History

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