private void SetRenderingFeatures(IRenderingFeatures renderingFeatures) { var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => renderingFeatures); ServiceLocator.SetLocatorProvider(() => serviceLocator); }
/// <summary> /// Creates a new <see cref="SqlTraceListener"/> using the specified settings name /// </summary> /// <param name="settingsName">the name of the SqlTraceListener settings to use from configuration</param> public SqlTraceListener(string settingsName) : base(settingsName) { UkadcDiagnosticsSection ukadcDiagnosticsSection = UkadcDiagnosticsSection.ReadConfigSection(); SqlTraceListenerElement sqlTraceListenerElement = ukadcDiagnosticsSection.SqlTraceListeners[settingsName]; if (null == sqlTraceListenerElement) { throw new ConfigurationErrorsException( string.Format(CultureInfo.CurrentCulture, Resources.SqlTraceListenerConfigError, settingsName)); } string connectionString = ConfigurationManager.ConnectionStrings[sqlTraceListenerElement.ConnectionStringName].ConnectionString; // use default data adapter IDataAccessAdapter adapter = new SqlDataAccessAdapter(); adapter.Initialize( connectionString, sqlTraceListenerElement.CommandText, sqlTraceListenerElement.CommandType); DataAccessAdapter = adapter; IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>(); foreach (ParameterElement param in sqlTraceListenerElement.Parameters) { PropertyReader propertyReader = readerFactory.Create(param); this.Parameters.Add( new SqlTraceParameter(param.Name, propertyReader, param.CallToString)); } }
public void SetUp() { _serviceLocator = DefaultServiceLocator.Create(); _stubColumnDefinition = new StubColumnDefinition(); _stubValueColumnDefinition = new StubValueColumnDefinition(); _wcagHelperStub = MockRepository.GenerateStub <WcagHelper>(); }
public void UsesSecurityFreeSectionToAccessTenantOfUser() { ISecurityContext userSecurityContext; ISecurityContext tenantSecurityContext; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var user = _userHandle.GetObject(); userSecurityContext = ((ISecurityContextFactory)user).CreateSecurityContext(); tenantSecurityContext = ((ISecurityContextFactory)user.Tenant).CreateSecurityContext(); } var securityProviderStub = MockRepository.GenerateStub <ISecurityProvider>(); securityProviderStub.Stub(stub => stub.IsNull).Return(false); securityProviderStub .Stub(_ => _.GetAccess(Arg.Is(userSecurityContext), Arg <ISecurityPrincipal> .Is.Anything)) .Throw(new AssertionException("GetAccess should not have been called.")); securityProviderStub .Stub(_ => _.GetAccess(Arg.Is(tenantSecurityContext), Arg <ISecurityPrincipal> .Is.Anything)) .Return(new AccessType[0]); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => securityProviderStub); serviceLocator.RegisterSingle <IPrincipalProvider> (() => new NullPrincipalProvider()); using (new ServiceLocatorScope(serviceLocator)) { SecurityManagerPrincipal principal = new SecurityManagerPrincipal(_rootTenantHandle, _userHandle, null); Assert.That(principal.GetTenants(true), Is.Empty); } }
public void ActiveSecurityProviderAddsSecurityClientTransactionExtension() { User user = User.FindByUserName("substituting.user"); Tenant tenant = user.Tenant; Substitution substitution = user.GetActiveSubstitutions().First(); var securityProviderStub = MockRepository.GenerateStub <ISecurityProvider>(); securityProviderStub.Stub(stub => stub.IsNull).Return(false); securityProviderStub .Stub(_ => _.GetAccess(Arg <ISecurityContext> .Is.Anything, Arg <ISecurityPrincipal> .Is.Anything)) .Return(new AccessType[0]); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => securityProviderStub); serviceLocator.RegisterSingle <IPrincipalProvider> (() => new NullPrincipalProvider()); using (new ServiceLocatorScope(serviceLocator)) { var principal = CreateSecurityManagerPrincipal(tenant, user, substitution); //Must test for observable effect Assert.That(principal.GetActiveSubstitutions(), Is.Empty); } }
public void SetUp() { _htmlHelper = new HtmlHelper(); _httpContextStub = MockRepository.GenerateStub <HttpContextBase>(); _control = MockRepository.GenerateStub <IListMenu>(); _control.Stub(stub => stub.UniqueID).Return("MyListMenu"); _control.Stub(stub => stub.ClientID).Return("MyListMenu"); _control.Stub(stub => stub.ControlType).Return("ListMenu"); _control.Stub(stub => stub.MenuItems).Return(new WebMenuItemCollection(_control)); _control.Stub(stub => stub.Enabled).Return(true); _control.Stub(stub => stub.HasClientScript).Return(true); _control.Stub(stub => stub.ResolveClientUrl(null)).IgnoreArguments().Do((Func <string, string>)(url => url.TrimStart('~'))); _control.Stub(stub => stub.GetUpdateScriptReference("null")).Return("Update();"); var pageStub = MockRepository.GenerateStub <IPage>(); _clientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>(); pageStub.Stub(page => page.ClientScript).Return(_clientScriptManagerMock); _control.Stub(stub => stub.Page).Return(pageStub); PopulateMenu(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IRenderingFeatures> (() => RenderingFeatures.WithDiagnosticMetadata); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public override void SetUp() { base.SetUp(); _securityProviderStub = MockRepository.GenerateStub <ISecurityProvider> (); _securityProviderStub.Stub(stub => stub.IsNull).Return(false); _securityPrincipalStub = MockRepository.GenerateStub <ISecurityPrincipal> (); var principalProviderStub = MockRepository.GenerateStub <IPrincipalProvider> (); principalProviderStub.Stub(stub => stub.GetPrincipal()).Return(_securityPrincipalStub); _functionalSecurityStrategyStub = MockRepository.GenerateStub <IFunctionalSecurityStrategy> (); _objectSecurityStrategyStub = MockRepository.GenerateStub <IObjectSecurityStrategy> (); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => _securityProviderStub); serviceLocator.RegisterSingle(() => principalProviderStub); serviceLocator.RegisterSingle(() => _functionalSecurityStrategyStub); serviceLocator.RegisterMultiple <IWebSecurityAdapter>(); serviceLocator.RegisterMultiple <IWxeSecurityAdapter> (() => new WxeSecurityAdapter()); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); _testAccessTypeValue = AccessType.Get(TestAccessTypes.Value); }
public void DefaultServiceLocator_ReturnsDomainObjectParticipant() { var serviceLocator = DefaultServiceLocator.Create(); var participants = serviceLocator.GetAllInstances <IParticipant>().ToArray(); Assert.That(participants.Select(p => p.GetType()), Has.Member(typeof(DomainObjectParticipant))); }
public override void SetUp() { base.SetUp(); _securityProviderStub = MockRepository.GenerateStub <ISecurityProvider>(); _principalProviderStub = MockRepository.GenerateStub <IPrincipalProvider>(); _securityPrincipalStub = MockRepository.GenerateStub <ISecurityPrincipal>(); _functionalSecurityStrategyStub = MockRepository.GenerateStub <IFunctionalSecurityStrategy>(); _principalProviderStub.Stub(stub => stub.GetPrincipal()).Return(_securityPrincipalStub); _securityContextStub = MockRepository.GenerateStub <ISecurityContext> (); _securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> (); _securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(_securityContextStub); _clientTransaction = ClientTransaction.CreateRootTransaction(); _clientTransaction.Extensions.Add(new SecurityClientTransactionExtension()); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => _securityProviderStub); serviceLocator.RegisterSingle(() => _principalProviderStub); serviceLocator.RegisterSingle(() => _functionalSecurityStrategyStub); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); _clientTransaction.EnterNonDiscardingScope(); }
public void DefaultServiceLocator_OrdersDomainObjectParticipantAfterMixinParticipant() { var serviceLocator = DefaultServiceLocator.Create(); var participants = serviceLocator.GetAllInstances <IParticipant>().ToArray(); Assert.That(participants.Select(p => p.GetType()), Is.EqualTo(new[] { typeof(MixinParticipant), typeof(DomainObjectParticipant) })); }
public void Test_WithSecurity_PermissionDeniedOnParent() { Tenant tenant = TestHelper.CreateTenant("Tenant", "UID: Tenant"); Group grandParent2 = TestHelper.CreateGroup("Grandparent1", "UID: Grandparent2", null, tenant); Group grandParent1 = TestHelper.CreateGroup("Grandparent1", "UID: Grandparent1", grandParent2, tenant); Group parent = TestHelper.CreateGroup("parent1", "UID: parent", grandParent1, tenant); Group root = TestHelper.CreateGroup("Root", "UID: Root", parent, tenant); ISecurityProvider securityProviderStub = MockRepository.GenerateStub <ISecurityProvider>(); var grandParent1SecurityContext = ((ISecurityContextFactory)grandParent1).CreateSecurityContext(); securityProviderStub.Stub( stub => stub.GetAccess( Arg <ISecurityContext> .Is.NotEqual(grandParent1SecurityContext), Arg <ISecurityPrincipal> .Is.Anything)).Return(new[] { AccessType.Get(GeneralAccessTypes.Read) }); securityProviderStub.Stub( stub => stub.GetAccess( Arg.Is(grandParent1SecurityContext), Arg <ISecurityPrincipal> .Is.Anything)).Return(new AccessType[0]); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => securityProviderStub); serviceLocator.RegisterSingle <IPrincipalProvider> (() => new NullPrincipalProvider()); using (new ServiceLocatorScope(serviceLocator)) { using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { var groups = root.GetParents().ToArray(); Assert.That(groups, Is.EquivalentTo(new[] { parent })); } } }
public void CreateLinqQuery_WithoutParserAndExecutor() { var factoryMock = MockRepository.GenerateStrictMock <ILinqProviderComponentFactory> (); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <ILinqProviderComponentFactory> (() => factoryMock); using (new ServiceLocatorScope(serviceLocator)) { var fakeExecutor = MockRepository.GenerateStub <IQueryExecutor> (); var fakeQueryParser = MockRepository.GenerateStub <IQueryParser> (); var fakeResult = MockRepository.GenerateStub <IQueryable <Order> > (); factoryMock .Expect(mock => mock.CreateQueryExecutor(TestDomainStorageProviderDefinition)) .Return(fakeExecutor); factoryMock .Expect(mock => mock.CreateQueryParser()) .Return(fakeQueryParser); factoryMock .Expect(mock => mock.CreateQueryable <Order> (fakeQueryParser, fakeExecutor)) .Return(fakeResult); var result = QueryFactory.CreateLinqQuery <Order> (); factoryMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(fakeResult)); } }
protected void Application_Start(object sender, EventArgs e) { var defaultServiceLocator = DefaultServiceLocator.Create(); //defaultServiceLocator.Register (typeof (Remotion.Data.DomainObjects.IClientTransactionExtensionFactory), typeof (Remotion.Data.DomainObjects.UberProfIntegration.LinqToSqlExtensionFactory), LifetimeKind.Singleton); //defaultServiceLocator.Register (typeof (Remotion.Data.DomainObjects.Tracing.IPersistenceExtensionFactory), typeof (Remotion.Data.DomainObjects.UberProfIntegration.LinqToSqlExtensionFactory), LifetimeKind.Singleton); //defaultServiceLocator.RegisterMultiple<IOrganizationalStructureEditControlFormGridRowProvider<EditUserControl>> (() => new EditUserControlFormGridRowProvider()); ServiceLocator.SetLocatorProvider(() => defaultServiceLocator); Assertion.IsTrue( defaultServiceLocator.GetInstance <IPrincipalProvider>() is SecurityManagerPrincipalProvider, "Wrong IPrincipalProvider is configured"); _resourceVirtualPathProvider = new ResourceVirtualPathProvider( new[] { new ResourcePathMapping("Remotion.Web", @"..\..\Remotion\Web\Core\res"), new ResourcePathMapping("Remotion.Web.Legacy", @"..\..\Remotion\Web\Legacy\Res"), new ResourcePathMapping("Remotion.ObjectBinding.Web", @"..\..\Remotion\ObjectBinding\Web\res"), new ResourcePathMapping("Remotion.ObjectBinding.Web.Legacy", @"..\..\Remotion\ObjectBinding\Web.Legacy\Res"), new ResourcePathMapping("Remotion.SecurityManager.Clients.Web/Html", @"..\Clients.Web\res\Html"), new ResourcePathMapping("Remotion.SecurityManager.Clients.Web/Themes", @"..\Clients.Web\res\Themes"), new ResourcePathMapping("Remotion.SecurityManager.Clients.Web/UI", @"..\Clients.Web\UI"), }, FileExtensionHandlerMapping.Default); _resourceVirtualPathProvider.Register(); }
public void Test_WithPermissionDeniedOnUser() { User substitutingUser = CreateUser(); Substitution substitution1 = Substitution.NewObject(); substitution1.SubstitutingUser = substitutingUser; substitution1.SubstitutedUser = CreateUser(); ISecurityProvider securityProviderStub = MockRepository.GenerateStub <ISecurityProvider> (); securityProviderStub .Stub(stub => stub.GetAccess(Arg <SecurityContext> .Is.Anything, Arg <ISecurityPrincipal> .Is.Anything)) .Return(new AccessType[0]); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => securityProviderStub); serviceLocator.RegisterSingle <IPrincipalProvider> (() => new NullPrincipalProvider()); using (new ServiceLocatorScope(serviceLocator)) { using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { ClientTransaction.Current.Extensions.Add(new SecurityClientTransactionExtension()); Assert.That(substitutingUser.GetActiveSubstitutions(), Is.Empty); } } }
private void Init() { if (!_initialised) { lock (_initlock) { if (!_initialised) { IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>(); _initialised = true; _filePathReader = readerFactory.CreateCombinedReader(FilePath); _outputReader = readerFactory.CreateCombinedReader(Output); _writerCache = DefaultServiceLocator.GetService <IStreamWriterCache>(); try { SafeParseCleanInterval(); } // need to start the timer with the default value, even if this throws finally { Timer timer = new Timer(_cleanInterval.TotalMilliseconds); timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); timer.Start(); } } } } }
public override void SetUp() { base.SetUp(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IRenderingFeatures> (() => RenderingFeatures.WithDiagnosticMetadata); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public void GetInstance_TypeWithGenericServiceInterface() { var serviceLocator = DefaultServiceLocator.Create(); Assert.That(serviceLocator.GetInstance(typeof(ITestOpenGenericService <int>)), Is.TypeOf(typeof(TestOpenGenericIntImplementation))); Assert.That(serviceLocator.GetInstance(typeof(ITestOpenGenericService <string>)), Is.TypeOf(typeof(TestOpenGenericStringImplementation))); Assert.That( SafeServiceLocator.Current.GetInstance <ITestOpenGenericService <int> >(), Is.InstanceOf(typeof(TestOpenGenericIntImplementation))); }
public override void SetUp() { base.SetUp(); _bindablePropertyReadAccessStrategyMock = MockRepository.GenerateStrictMock <IBindablePropertyReadAccessStrategy>(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => _bindablePropertyReadAccessStrategyMock); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public void SetUp() { _securityAdapter = new WebSecurityAdapter(); _testHelper = new WebPermissionProviderTestHelper(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterMultiple <IWebSecurityAdapter>(); serviceLocator.RegisterMultiple <IWxeSecurityAdapter> (() => _testHelper.WxeSecurityAdapter); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public void SetupSecurityIoCConfiguration() { var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => _mockSecurityProvider); serviceLocator.RegisterSingle(() => _stubPrincipalProvider); serviceLocator.RegisterSingle(() => _mockMemberResolver); serviceLocator.RegisterSingle(() => _mockPermissionReflector); serviceLocator.RegisterSingle(() => _mockFunctionalSecurityStrategy); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public void Setup() { _mocks = new MockRepository(); _mockWebSecurityAdapter = _mocks.StrictMock <IWebSecurityAdapter> (); _mockNavigationCommand = _mocks.StrictMock <NavigationCommand> (); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterMultiple <IWebSecurityAdapter> (() => _mockWebSecurityAdapter); serviceLocator.RegisterMultiple <IWxeSecurityAdapter>(); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public virtual void SetUp() { var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IErrorMessageGlobalizationService> (GetValidatorGlobalizationService); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); MemoryAppender = new MemoryAppender(); BasicConfigurator.Configure(MemoryAppender); ValidationBuilder = serviceLocator.GetInstance <IValidatorBuilder>(); }
public void Setup() { _mocks = new MockRepository(); _mockWebSecurityAdapter = _mocks.StrictMock <IWebSecurityAdapter> (); _mockSecurableObject = _mocks.StrictMock <ISecurableObject> (); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterMultiple <IWebSecurityAdapter> (() => _mockWebSecurityAdapter); serviceLocator.RegisterMultiple <IWxeSecurityAdapter>(); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
public void SetUp() { XmlNodeExtensions.Helper = new HtmlHelper(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IInfrastructureResourceUrlFactory> (() => new FakeInfrastructureResourceUrlFactory()); serviceLocator.RegisterSingle <IScriptUtility> (() => new FakeScriptUtility()); serviceLocator.RegisterSingle <IResourceUrlFactory> (() => new FakeResourceUrlFactory()); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
private static DefaultServiceLocator CreateServiceLocator(IEnumerable <ServiceConfigurationEntry> configuration) { ArgumentUtility.CheckNotNull("configuration", configuration); var defaultServiceLocator = DefaultServiceLocator.Create(); foreach (var stubbedRegistration in configuration) { defaultServiceLocator.Register(stubbedRegistration); } return(defaultServiceLocator); }
private static ServiceLocatorScope ScopeWithPersistenceExtension(IPersistenceExtension persistenceExtensionMock) { var persistenceExtensionFactoryStub = MockRepository.GenerateStub <IPersistenceExtensionFactory> (); persistenceExtensionFactoryStub .Stub(stub => stub.CreatePersistenceExtensions(Arg <Guid> .Is.Anything)) .Return(new[] { persistenceExtensionMock }); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IPersistenceExtensionFactory> (() => persistenceExtensionFactoryStub); return(new ServiceLocatorScope(serviceLocator)); }
public void SetUp() { _securityAdapter = new WebSecurityAdapter(); _testHelper = new WebPermissionProviderTestHelper(); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle(() => _testHelper.SecurityProvider); serviceLocator.RegisterSingle(() => _testHelper.PrincipalProvider); serviceLocator.RegisterSingle(() => _testHelper.FunctionalSecurityStrategy); _serviceLocatorScope = new ServiceLocatorScope(serviceLocator); }
/// <summary> /// Creates a new instance of the <see cref="PropertyReaderFactory"/> /// </summary> /// <param name="loadConfig">Indicates whether to load any tokens in the AppDomain's configuration file</param> /// <param name="loadInternalTokens">Indicates whether to load the hard-coded internal token list</param> public PropertyReaderFactory(bool loadConfig, bool loadInternalTokens) { _combinedFactory = DefaultServiceLocator.GetService <ICombinedPropertyReaderFactory>(); if (loadInternalTokens) { AddInternalTokens(); } if (loadConfig) { LoadConfiguredTokens(); } }
public void CreateDomainObjectCreator() { var registryStub = MockRepository.GenerateStub <IPipelineRegistry> (); var serviceLocator = DefaultServiceLocator.Create(); serviceLocator.RegisterSingle <IPipelineRegistry> (() => registryStub); using (new ServiceLocatorScope(serviceLocator)) { var creator = MappingReflector.CreateDomainObjectCreator(); Assert.That(creator.PipelineRegistry, Is.SameAs(registryStub)); } }
static ProcessPropertyReader() { try { _process = Process.GetCurrentProcess(); _readOK = true; } catch (Exception exc) { _readOK = false; DefaultServiceLocator.GetService <IInternalLogger>().LogException(exc); } }