Ejemplo n.º 1
0
		private void MockServiceLocator()
		{
			var settings = new ApplicationSettings();

			var configReader = new ConfigReaderWriterStub();
			configReader.ApplicationSettings = settings;

			var registry = new RoadkillRegistry(configReader);
			var container = new Container(registry);
			container.Configure(x =>
			{
				x.Scan(a => a.AssemblyContainingType<TestHelpers>());
				x.For<IPageRepository>().Use(new PageRepositoryMock());
				x.For<IUserContext>().Use(new UserContextStub());
			});

			LocatorStartup.Locator = new StructureMapServiceLocator(container, false);
			DependencyResolver.SetResolver(LocatorStartup.Locator);

			var all =
				container.Model.AllInstances.OrderBy(t => t.PluginType.Name)
					.Select(t => String.Format("{0}:{1}", t.PluginType.Name, t.ReturnedType.AssemblyQualifiedName));

			Console.WriteLine(String.Join("\n", all));
		}
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings = _container.ApplicationSettings;
            _applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments");
            _context            = _container.UserContext;
            _repository         = _container.Repository;
            _settingsService    = _container.SettingsService;
            _userService        = new FormsAuthUserService(_applicationSettings, _repository);
            _configReaderWriter = new ConfigReaderWriterStub();

            _upgradeController = new UpgradeController(_applicationSettings, _repository, _userService, _context, _settingsService, _configReaderWriter);
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings           = _container.ApplicationSettings;
            _applicationSettings.Installed = false;

            _context                     = _container.UserContext;
            _settingsService             = _container.SettingsService;
            _userService                 = _container.UserService;
            _configReaderWriter          = new ConfigReaderWriterStub();
            _activeDirectoryProviderMock = new ActiveDirectoryProviderMock();

            _configTesterController = new ConfigurationTesterController(_applicationSettings, _context, _configReaderWriter, _activeDirectoryProviderMock);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings = _container.ApplicationSettings;
            _context             = _container.UserContext;
            _settingsService     = _container.SettingsService;
            _userService         = _container.UserService;

            _controller = new ControllerBaseStub(_applicationSettings, _userService, _context, _settingsService);
            _controller.SetFakeControllerContext("~/");

            // InstallController
            _configReaderWriter  = new ConfigReaderWriterStub();
            _databaseTester      = _container.DatabaseTester;
            _installationService = _container.InstallationService;
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings           = _container.ApplicationSettings;
            _applicationSettings.Installed = false;

            _settingsService     = _container.SettingsService;
            _userService         = _container.UserService;
            _configReaderWriter  = _container.ConfigReaderWriter;
            _repositoryFactory   = _container.RepositoryFactory;
            _installationService = _container.InstallationService;
            _databaseTester      = _container.DatabaseTester;
            _installerRepository = _container.InstallerRepository;

            _installController = new InstallController(_applicationSettings, _configReaderWriter, _installationService, _databaseTester);
        }
        public void Setup()
        {
            _container = new MocksAndStubsContainer();
            _container.ClearCache();

            _applicationSettings = _container.ApplicationSettings;
            _applicationSettings.AttachmentsFolder = AppDomain.CurrentDomain.BaseDirectory;
            _context            = _container.UserContext;
            _repository         = _container.Repository;
            _settingsService    = _container.SettingsService;
            _userService        = _container.UserService;
            _pageCache          = _container.PageViewModelCache;
            _listCache          = _container.ListCache;
            _siteCache          = _container.SiteCache;
            _cache              = _container.MemoryCache;
            _configReaderWriter = new ConfigReaderWriterStub();

            _settingsController = new SettingsController(_applicationSettings, _userService, _settingsService, _context, _siteCache, _configReaderWriter);
        }
Ejemplo n.º 7
0
        private IContainer CreateContainer()
        {
            var configReaderWriterStub = new ConfigReaderWriterStub();

            configReaderWriterStub.ApplicationSettings.ConnectionString = "none empty connection string";

            var roadkillRegistry = new RoadkillRegistry(configReaderWriterStub);
            var container        = new Container(c =>
            {
                c.AddRegistry(roadkillRegistry);
            });

            container.Inject(typeof(IUnitOfWork), new UnitOfWork());

            // Some places that require bastard injection reference the LocatorStartup.Locator
            LocatorStartup.Locator = new StructureMapServiceLocator(container, false);

            return(container);
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings           = _container.ApplicationSettings;
            _applicationSettings.Installed = false;

            _context            = _container.UserContext;
            _repository         = _container.Repository;
            _pluginFactory      = _container.PluginFactory;
            _settingsService    = _container.SettingsService;
            _userService        = _container.UserService;
            _historyService     = _container.HistoryService;
            _pageService        = _container.PageService;
            _searchService      = _container.SearchService;
            _configReaderWriter = new ConfigReaderWriterStub();

            _installController = new InstallController(_applicationSettings, _userService, _pageService, _searchService, _repository, _settingsService, _context, _configReaderWriter);
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings = _container.ApplicationSettings;
            _context             = _container.UserContext;
            _settingsService     = _container.SettingsService;
            _userService         = _container.UserService;

            _controller = new ControllerBaseStub(_applicationSettings, _userService, _context, _settingsService);
            MvcMockContainer container = _controller.SetFakeControllerContext("~/");

            // Used by InstallController
            _repository         = _container.Repository;
            _pluginFactory      = _container.PluginFactory;
            _historyService     = _container.HistoryService;
            _pageService        = _container.PageService;
            _searchService      = _container.SearchService;
            _configReaderWriter = new ConfigReaderWriterStub();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new instance of MocksAndStubsContainer.
        /// </summary>
        /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with
        /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic
        /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param>
        public MocksAndStubsContainer(bool useCacheMock = false)
        {
            ApplicationSettings                   = new ApplicationSettings();
            ApplicationSettings.Installed         = true;
            ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments");
            ConfigReaderWriter = new ConfigReaderWriterStub();

            // Cache
            MemoryCache        = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache;
            ListCache          = new ListCache(ApplicationSettings, MemoryCache);
            SiteCache          = new SiteCache(MemoryCache);
            PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache);

            // Repositories
            SettingsRepository = new SettingsRepositoryMock();
            SettingsRepository.SiteSettings            = new SiteSettings();
            SettingsRepository.SiteSettings.MarkupType = "Creole";
            UserRepository      = new UserRepositoryMock();
            PageRepository      = new PageRepositoryMock();
            InstallerRepository = new InstallerRepositoryMock();

            RepositoryFactory = new RepositoryFactoryMock()
            {
                SettingsRepository  = SettingsRepository,
                UserRepository      = UserRepository,
                PageRepository      = PageRepository,
                InstallerRepository = InstallerRepository
            };
            DatabaseTester = new DatabaseTesterMock();

            // Plugins
            PluginFactory   = new PluginFactoryMock();
            MarkupConverter = new MarkupConverter(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory);

            // Services
            // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock.
            SettingsService            = new SettingsService(RepositoryFactory, ApplicationSettings);
            UserService                = new UserServiceMock(ApplicationSettings, UserRepository);
            UserContext                = new UserContext(UserService);
            SearchService              = new SearchServiceMock(ApplicationSettings, SettingsRepository, PageRepository, PluginFactory);
            SearchService.PageContents = PageRepository.PageContents;
            SearchService.Pages        = PageRepository.Pages;
            HistoryService             = new PageHistoryService(ApplicationSettings, SettingsRepository, PageRepository, UserContext,
                                                                PageViewModelCache, PluginFactory);
            FileService = new FileServiceMock();
            PageService = new PageService(ApplicationSettings, SettingsRepository, PageRepository, SearchService, HistoryService,
                                          UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory);

            StructureMapContainer = new Container(x =>
            {
                x.AddRegistry(new TestsRegistry(this));
            });

            Locator = new StructureMapServiceLocator(StructureMapContainer, false);

            InstallationService = new InstallationService((databaseName, connectionString) =>
            {
                InstallerRepository.DatabaseName     = databaseName;
                InstallerRepository.ConnectionString = connectionString;

                return(InstallerRepository);
            }, Locator);

            // EmailTemplates
            EmailClient = new EmailClientMock();
        }