public MissionController(IUnitOfWork uow, ICurrentUser user, GameRulesService gameEngine, IMapper mapper)
 {
     this.uow        = uow;
     requestingUser  = user;
     this.gameEngine = gameEngine;
     this.mapper     = mapper;
 }
        /// <summary>
        ///     Builds a controller of the required type using any data previously supplied (or defaults).
        /// </summary>
        /// <returns>An initialized controller of type <typeparamref name="TController" />.</returns>
        /// <exception cref="SpecificationException">Thrown if the controller cannot be built.</exception>
        public TController Build()
        {
            var dataLoader = new ObjectDataLoader(data);

            UnitOfWork = uowBuilder.WithData(dataLoader).Build();
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <ViewModelMappingProfile>(); });

            mapperConfiguration.AssertConfigurationIsValid();
            Mapper = mapperConfiguration.CreateMapper();
            var notifier = new FakeNotificationService();

            RulesService = new GameRulesService(UnitOfWork, Mapper, notifier);
            HttpContextBase httpContext;

            if (postedFile == null)
            {
                httpContext = new FakeHttpContext(requestPath, requestMethod.ToString("G"));
            }
            else
            {
                var filesCollection = new FakeHttpFileCollection(postedFile);
                httpContext = new FakeHttpContext(requestPath, filesCollection);
            }
            var fakeIdentity  = new FakeIdentity(requestUsername);
            var fakePrincipal = new FakePrincipal(fakeIdentity, requestUserRoles);

            httpContext.User = fakePrincipal;
            var context = new ControllerContext {
                HttpContext = httpContext
            };

            /*
             * Use Ninject to create the controller, as we don't know in advance what
             * type of controller or how many constructor parameters it has.
             */
            var kernel     = BuildNinjectKernel(fakeIdentity, requestUserId, RulesService);
            var controller = kernel.Get <TController>();

            if (controller == null)
            {
                throw new SpecificationException(
                          $"ControllerContextBuilder: Unable to create controller instance of type {nameof(TController)}");
            }

            controller.ControllerContext = context;
            controller.TempData          = tempdata;
            return(controller);
        }