コード例 #1
1
		public void Setup()
		{
			_container = new MocksAndStubsContainer();	

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;

			_settingsRepository = _container.SettingsRepository;
			_userRepository = _container.UserRepository;
			_pageRepository = _container.PageRepository;

			_settingsService = _container.SettingsService;
			_userService = _container.UserService;
			_pageCache = _container.PageViewModelCache;
			_listCache = _container.ListCache;
			_siteCache = _container.SiteCache;
			_cache = _container.MemoryCache;
			_container.ClearCache();

			_pageService = _container.PageService;
			_wikiImporter = new WikiImporterMock();
			_pluginFactory = _container.PluginFactory;
			_searchService = _container.SearchService;

			// There's no point mocking WikiExporter (and turning it into an interface) as 
			// a lot of usefulness of these tests would be lost when creating fake Streams and zip files.
			_wikiExporter = new WikiExporter(_applicationSettings, _pageService, _settingsRepository, _pageRepository, _userRepository, _pluginFactory);
			_wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory;

			_toolsController = new ToolsController(_applicationSettings, _userService, _settingsService, _pageService,
													_searchService, _context, _listCache, _pageCache, _wikiImporter, 
													_pluginFactory, _wikiExporter);
		}
コード例 #2
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();
			_applicationSettings = _container.ApplicationSettings;

			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;
			_userRepository = _container.UserRepository;

			_pageService = _container.PageService;
			_pluginFactory = _container.PluginFactory;

			_wikiExporter = new WikiExporter(_applicationSettings, _pageService, _settingsRepository, _pageRepository, _userRepository, _pluginFactory);
			_wikiExporter.ExportFolder = AppDomain.CurrentDomain.BaseDirectory;
		}
コード例 #3
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;

			_pageRepository = _container.PageRepository;
			_userRepository = _container.UserRepository;

			_settingsService = _container.SettingsService;
			_userService = _container.UserService;

			_controller = new UserManagementController(_applicationSettings, _userService, _settingsService, _context);
		}
コード例 #4
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();
		}
コード例 #5
0
		public void should_export_users_with_all_fieldvalues()
		{
			// Arrange
			var settingsRepository = new SettingsRepositoryMock();
			var userRepositoryMock = new UserRepositoryMock();
			settingsRepository.SiteSettings.PluginLastSaveDate = DateTime.Today;

			Guid user1Id = new Guid("29a8ad19-b203-46f5-be10-11e0ebf6f812");
			Guid user2Id = new Guid("e63b0023-329a-49b9-97a4-5094a0e378a2");
			Guid user3Id = new Guid("a6ee19ef-c093-47de-97d2-83dec406d92d");

			Guid user1Activationkey = new Guid("0953cf95-f357-4e5b-ae2b-7541844d3b6b");
			Guid user2Activationkey = new Guid("aa87fe31-9781-4c93-b7e3-9092ed095810");
			Guid user3Activationkey = new Guid("b8ef994d-87f5-4543-85de-66b41244a20a");

			User user1 = new User()
			{
				Id = user1Id,
				ActivationKey = user1Activationkey.ToString(),
				Firstname = "firstname1",
				Lastname = "lastname1",
				Email = "user1@localhost", 
				Password = "******",
				Salt = "salt1",
				IsActivated = true,
				IsAdmin = true,
				Username = "******"
			};

			User user2 = new User()
			{
				Id = user2Id,
				ActivationKey = user2Activationkey.ToString(),
				Firstname = "firstname2",
				Lastname = "lastname2",
				Email = "user2@localhost",
				Password = "******",
				Salt = "salt2",
				IsActivated = true,
				IsEditor = true,
				Username = "******"
			};

			User user3 = new User()
			{
				Id = user3Id,
				ActivationKey = user3Activationkey.ToString(),
				Firstname = "firstname3",
				Lastname = "lastname3",
				Email = "user3@localhost",
				Password = "******",
				Salt = "salt3",
				IsActivated = false,
				IsEditor = true,
				Username = "******"
			};

			userRepositoryMock.Users.Add(user1);
			userRepositoryMock.Users.Add(user2);
			userRepositoryMock.Users.Add(user3);

			SqlExportBuilder builder = new SqlExportBuilder(settingsRepository, userRepositoryMock, new PageRepositoryMock(), new PluginFactoryMock());
			builder.IncludeConfiguration = false;
			builder.IncludePages = false;
			string expectedSql = ReadEmbeddedResource("expected-users-export.sql");

			// Act
			string actualSql = builder.Export();

			// Assert
			Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql);
		}