using System;
using Ninject.Infrastructure;
using Ninject.Injection;
using Ninject.Planning.Bindings;
using Ninject.Syntax;
namespace Ninject.Moq
{
///
/// Extensions for the fluent binding syntax API.
///
public static class ExtensionsForBindingSyntax
{
///
/// Indicates that the service should be bound to a mocked instance of the specified type.
///
/// The service that is being mocked.
/// The builder that is building the binding.
public static IBindingWhenInNamedWithOrOnSyntax ToMock(this IBindingToSyntax builder)
{
var haveBinding = builder as IHaveBinding;
if (haveBinding == null)
throw new NotSupportedException(String.Format("The binding builder for {0} is of type {1}, which does not implement IHaveBinding and is therefore not extensible.", typeof(T), builder.GetType()));
IBinding binding = haveBinding.Binding;
binding.ProviderCallback = ctx => new MockProvider(ctx.Kernel.Components.Get());
return builder as IBindingWhenInNamedWithOrOnSyntax;
}
}
}