2021-08-20 12:41:27 +10:00
|
|
|
|
using Moq;
|
|
|
|
|
using Ninject;
|
2021-08-19 16:43:04 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Routing;
|
2021-08-20 12:41:27 +10:00
|
|
|
|
using SportsStore.Domain.Abstract;
|
|
|
|
|
using SportsStore.Domain.Entities;
|
2021-08-19 16:43:04 +10:00
|
|
|
|
|
|
|
|
|
namespace SportsStore.WebUI.Infrastructure
|
|
|
|
|
{
|
|
|
|
|
public class NinjectControllerFactory : DefaultControllerFactory
|
|
|
|
|
{
|
|
|
|
|
private IKernel ninjectKernel;
|
|
|
|
|
|
|
|
|
|
public NinjectControllerFactory()
|
|
|
|
|
{
|
|
|
|
|
ninjectKernel = new StandardKernel();
|
|
|
|
|
AddBindings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IController GetControllerInstance(RequestContext requestContext,
|
|
|
|
|
Type controllerType)
|
|
|
|
|
{
|
|
|
|
|
return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddBindings()
|
|
|
|
|
{
|
2021-08-20 12:41:27 +10:00
|
|
|
|
// Mock implementation of the IProductRepository Interface
|
|
|
|
|
Mock<IProductRepository> mock = new Mock<IProductRepository>();
|
|
|
|
|
mock.Setup(m => m.Products).Returns(new List<Product>
|
|
|
|
|
{
|
|
|
|
|
new Product { Name = "Football", Price = 25 },
|
|
|
|
|
new Product { Name = "Surf board", Price = 179 },
|
|
|
|
|
new Product { Name = "Running shoes", Price = 95 }
|
|
|
|
|
}.AsQueryable());
|
|
|
|
|
|
|
|
|
|
ninjectKernel.Bind<IProductRepository>().ToConstant(mock.Object);
|
2021-08-19 16:43:04 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|