Example #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));
		}
Example #2
0
		public void StartMVCInternal_should_create_service_locator_and_set_mvc_service_locator()
		{
			// Arrange
			var settings = new ApplicationSettings();
			var registry = new RoadkillRegistry(new ConfigReaderWriterStub() { ApplicationSettings = settings });

			// Act
			LocatorStartup.StartMVCInternal(registry, false);

			// Assert
			Assert.That(LocatorStartup.Locator, Is.Not.Null);
			Assert.That(DependencyResolver.Current, Is.EqualTo(LocatorStartup.Locator));
		}
Example #3
0
		internal static void StartMVCInternal(RoadkillRegistry registry, bool isWeb)
		{
			IContainer container = new Container(c =>
			{
				c.AddRegistry(registry);
				c.AddRegistry(new LightSpeedRegistry());
			});

			Locator = new StructureMapServiceLocator(container, isWeb);

			// MVC locator
			DependencyResolver.SetResolver(Locator);
			DynamicModuleUtility.RegisterModule(typeof(StructureMapHttpModule));
		}
Example #4
0
        internal static void StartMVCInternal(RoadkillRegistry registry, bool isWeb)
        {
            IContainer container = new Container(c =>
            {
                c.AddRegistry(registry);
                c.AddRegistry(new LightSpeedRegistry());
            });

            Locator = new StructureMapServiceLocator(container, isWeb);

            // MVC locator
            DependencyResolver.SetResolver(Locator);
            DynamicModuleUtility.RegisterModule(typeof(StructureMapHttpModule));
        }
Example #5
0
		public void AfterInitializationInternal_should_register_mvc_attributes_and_modelbinders()
		{
			// Arrange
			var settings = new ApplicationSettings();
			var registry = new RoadkillRegistry(new ConfigReaderWriterStub() { ApplicationSettings = settings });
			var container = new Container(registry);

			LocatorStartup.StartMVCInternal(registry, false);

			// Act
			LocatorStartup.AfterInitializationInternal(container, settings);

			// Assert
			Assert.True(ModelBinders.Binders.ContainsKey(typeof(SettingsViewModel)));
			Assert.True(ModelBinders.Binders.ContainsKey(typeof(UserViewModel)));
		}
Example #6
0
		public void AfterInitializationInternal_should_register_webapi_servicelocator_and_attributeprovider()
		{
			// Arrange
			var settings = new ApplicationSettings();
			var registry = new RoadkillRegistry(new ConfigReaderWriterStub() { ApplicationSettings = settings });
			var container = new Container(registry);

			LocatorStartup.StartMVCInternal(registry, false); // needed to register LocatorStartup.Locator

			// Act
			LocatorStartup.AfterInitializationInternal(container, settings);

			// Assert
			Assert.That(GlobalConfiguration.Configuration.DependencyResolver, Is.EqualTo(LocatorStartup.Locator));

			// Doesn't work...maybe it will work in 2016
			//Assert.That(GlobalConfiguration.Configuration.Services.GetService(typeof(System.Web.Http.Filters.IFilterProvider)), Is.TypeOf<MvcAttributeProvider>());
		}
Example #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);
        }
Example #8
0
        public void should_use_azurefileservice_when_setting_has_azure_true()
        {
            // Arrange
            ApplicationSettings settings = new ApplicationSettings();

            settings.ConnectionString    = "none empty connection string";
            settings.UseAzureFileStorage = true;

            var registry = new RoadkillRegistry(new ConfigReaderWriterStub()
            {
                ApplicationSettings = settings
            });
            var container = new Container(registry);

            // Act

            // Assert
            Assert.That(container.GetInstance <IFileService>(), Is.TypeOf(typeof(AzureFileService)));
        }
Example #9
0
        public void MongoDB_databaseType_should_load_repository()
        {
            // Arrange
            var settings = new ApplicationSettings();

            settings.DatabaseName     = "MongoDB";
            settings.ConnectionString = "none empty connection string";

            var registry = new RoadkillRegistry(new ConfigReaderWriterStub()
            {
                ApplicationSettings = settings
            });
            var container = new Container(registry);

            // Act +  Assert
            AssertDefaultType <ISettingsRepository, MongoDBSettingsRepository>(container);
            AssertDefaultType <IUserRepository, MongoDBUserRepository>(container);
            AssertDefaultType <IPageRepository, MongoDBPageRepository>(container);
        }
Example #10
0
        public void should_load_activedirectory_userservice_when_usewindowsauth_is_true()
        {
            // Arrange
            ApplicationSettings settings = new ApplicationSettings();

            settings.ConnectionString         = "none empty connection string";
            settings.UseWindowsAuthentication = true;
            settings.LdapConnectionString     = "LDAP://dc=roadkill.org";
            settings.AdminRoleName            = "admins";
            settings.EditorRoleName           = "editors";

            var registry = new RoadkillRegistry(new ConfigReaderWriterStub()
            {
                ApplicationSettings = settings
            });
            var container = new Container(registry);

            // Act

            // Assert
            Assert.That(container.GetInstance <UserServiceBase>(), Is.TypeOf(typeof(ActiveDirectoryUserService)));
        }
Example #11
0
        public void should_load_custom_userservice_using_assemblyqualifiedname()
        {
            // Arrange
            ApplicationSettings settings = new ApplicationSettings();

            settings.ConnectionString = "none empty connection string";
            settings.UserServiceType  = typeof(Roadkill.Plugins.TestUserService).AssemblyQualifiedName;
            Console.WriteLine(settings.UserServiceType);
            settings.PluginsBinPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");

            // Act
            var registry = new RoadkillRegistry(new ConfigReaderWriterStub()
            {
                ApplicationSettings = settings
            });
            var container = new Container(registry);

            // Act
            UserServiceBase userService = container.GetInstance <UserServiceBase>();

            Assert.That(userService, Is.Not.Null);
            Assert.That(userService.GetType().AssemblyQualifiedName, Is.EqualTo(settings.UserServiceType));
        }
Example #12
0
        public void should_register_services()
        {
            // Arrange
            var settings = new ApplicationSettings();

            settings.ConnectionString     = "none empty connection string";
            settings.LdapConnectionString = "LDAP://dc=roadkill.org";             // for ActiveDirectoryUserService
            settings.AdminRoleName        = "admins";
            settings.EditorRoleName       = "editors";

            var registry = new RoadkillRegistry(new ConfigReaderWriterStub()
            {
                ApplicationSettings = settings
            });
            var container = new Container(registry);

            // Act +  Assert
            Assert.That(container.GetInstance <SearchService>(), Is.Not.Null);
            Assert.That(container.GetInstance <PageHistoryService>(), Is.Not.Null);
            Assert.That(container.GetInstance <PageService>(), Is.Not.Null);
            Assert.That(container.GetInstance <FormsAuthUserService>(), Is.Not.Null);
            Assert.That(container.GetInstance <ActiveDirectoryUserService>(), Is.Not.Null);
        }