public void Configure03() { Locator locator; ServiceCollection serviceCollection; locator = new Locator((IReadableLocator)null); serviceCollection = new ServiceCollection((ILifetimeContainer)null, (IReadWriteLocator)locator, (IBuilder<WCSFBuilderStage>)null, (IServiceCollection)null); BeheerThemasModuleInitializer s0 = new BeheerThemasModuleInitializer(); this.Configure(s0, (IServiceCollection)serviceCollection, (global::System.Configuration.Configuration)null); Assert.IsNotNull((object)s0); }
public void CanCreateSingletonObjectWithDefaultObjectBuilder() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = new Locator(); LifetimeContainer lifetime = new LifetimeContainer(); locator.Add(typeof (ILifetimeContainer), lifetime); builder.Policies.Set<ISingletonPolicy>(new SingletonPolicy(true), typeof (MockObject), "foo"); MockObject obj1 = builder.BuildUp<MockObject>(locator, "foo", null); MockObject obj2 = builder.BuildUp<MockObject>(locator, "foo", null); Assert.AreSame(obj1, obj2); }
public void BuildUpReturnsInstanceOfStateValueWithCorrespondantValueFromSessionWhenInjectingProperties() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof (ILifetimeContainer), container); WCSFBuilder builder = new WCSFBuilder(); builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); MockSessionStateLocatorService stateLocator = new MockSessionStateLocatorService(); locator.Add(new DependencyResolutionLocatorKey(typeof (ISessionStateLocatorService), null), stateLocator); stateLocator.SessionState["intKey"] = 5; SampleClass builtObject = builder.BuildUp(locator, typeof (SampleClass), Guid.NewGuid().ToString(), null) as SampleClass; Assert.IsNotNull(builtObject.MyIntValue); Assert.AreEqual(5, builtObject.MyIntValue.Value); }
public void RequestForLogWriterWithLocatorAddsSingleton() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), container); MockBuilderContext context = CreateContext(locator, new SystemConfigurationSource()); createdObject1 = context.HeadOfChain.BuildUp(context, typeof(LogWriter), null, null); createdObject2 = context.HeadOfChain.BuildUp(context, typeof(LogWriter), null, null); Assert.IsNotNull(createdObject1); Assert.AreSame(typeof(LogWriter), createdObject1.GetType()); Assert.IsTrue(object.ReferenceEquals(createdObject1, createdObject2)); }
private Locator CreateLocator(ILifetimeContainer lifetimeContainer) { Locator locator = new Locator(); locator.Add(typeof (ILifetimeContainer), lifetimeContainer); return locator; }
public void BuildUpReturnsNewInstanceOfStateValue() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof (ILifetimeContainer), container); WCSFBuilder builder = new WCSFBuilder(); builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); MockSessionStateLocatorService stateLocator = new MockSessionStateLocatorService(); locator.Add(new DependencyResolutionLocatorKey(typeof (ISessionStateLocatorService), null), stateLocator); SampleClass builtObject = builder.BuildUp(locator, typeof (SampleClass), Guid.NewGuid().ToString(), null) as SampleClass; Assert.IsNotNull(builtObject.MyStringValue); }
public void BuildUpThrowsWhenTryingToInjectNonIStateValueParameters() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof (ILifetimeContainer), container); WCSFBuilder builder = new WCSFBuilder(); builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); locator.Add(new DependencyResolutionLocatorKey(typeof (ISessionStateLocatorService), null), new MockSessionStateLocatorService()); builder.BuildUp(locator, typeof (InvalidClass), Guid.NewGuid().ToString(), null); }
private TestableServiceCollection CreateServiceCollection() { LifetimeContainer container = new LifetimeContainer(); Locator locator = new Locator(); locator.Add(typeof (ILifetimeContainer), container); return new TestableServiceCollection(container, locator, CreateBuilder()); }
private MockBuilderContext CreateContext(Locator locator) { IBuilderStrategy[] strategies = { new SingletonStrategy(), new ConstructorReflectionStrategy(), new CreationStrategy() }; MockBuilderContext result = new MockBuilderContext(strategies); result.Locator = locator; LifetimeContainer lifetimeContainer = new LifetimeContainer(); if (!result.Locator.Contains(typeof (ILifetimeContainer))) result.Locator.Add(typeof (ILifetimeContainer), lifetimeContainer); result.Policies.SetDefault<ICreationPolicy>(new DefaultCreationPolicy()); result.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); return result; }
public void LocalSearchGetsLocalIfDependencyIsAlsoUpstream() { Locator parent = new Locator(); object parentValue = 25; object childValue = 15; parent.Add(new DependencyResolutionLocatorKey(typeof (int), null), parentValue); Locator child = new Locator(parent); child.Add(new DependencyResolutionLocatorKey(typeof (int), null), childValue); MockBuilderContext context = CreateContext(child); SearchLocalMockObject obj = (SearchLocalMockObject) context.HeadOfChain.BuildUp(context, typeof (SearchLocalMockObject), null, null); Assert.AreEqual(15, obj.Value); }
public void LocalSearchFailsIfDependencyIsOnlyUpstream() { Locator parent = new Locator(); object parentValue = 25; parent.Add(new DependencyResolutionLocatorKey(typeof (int), null), parentValue); Locator child = new Locator(parent); MockBuilderContext context = CreateContext(child); context.HeadOfChain.BuildUp(context, typeof (SearchLocalMockObject), null, null); }
public void CanSearchDependencyUp() { Locator parent = new Locator(); object intValue = 25; parent.Add(new DependencyResolutionLocatorKey(typeof (int), null), intValue); Locator child = new Locator(parent); MockBuilderContext context = CreateContext(child); context.HeadOfChain.BuildUp(context, typeof (SearchUpMockObject), null, null); }
public void CanSearchDependencyUp() { Locator parent = new Locator(); // We're having a problem with this test intermittently failing. // Since the locator is a weak referencing container, our current // theory is that the GC is collecting this dependency before // the buildup call runs. By boxing it explicitly, we can keep // the object alive until after the test completes. object intValue = 25; parent.Add(new DependencyResolutionLocatorKey(typeof (int), null), intValue); Locator child = new Locator(parent); MockBuilderContext context = CreateContext(child); GC.Collect(); context.HeadOfChain.BuildUp(context, typeof (SearchUpMockObject), null, null); GC.KeepAlive(intValue); }
public void Configure07() { Locator locator; Locator locator1; ServiceCollection serviceCollection; ServiceCollection serviceCollection1; ServiceCollection serviceCollection2; locator = new Locator((IReadableLocator)null); locator1 = new Locator((IReadableLocator)null); serviceCollection = new ServiceCollection((ILifetimeContainer)null, (IReadWriteLocator)null, (IBuilder<WCSFBuilderStage>)null, (IServiceCollection)null); serviceCollection1 = new ServiceCollection((ILifetimeContainer)null, (IReadWriteLocator)locator1, (IBuilder<WCSFBuilderStage>)null, (IServiceCollection)serviceCollection); serviceCollection2 = new ServiceCollection((ILifetimeContainer)null, (IReadWriteLocator)locator, (IBuilder<WCSFBuilderStage>)null, (IServiceCollection)serviceCollection1); BeheerThemasModuleInitializer s0 = new BeheerThemasModuleInitializer(); this.Configure(s0, (IServiceCollection)serviceCollection2, (global::System.Configuration.Configuration)null); }
public void CreationPolicyWillRecordSingletonsUsingLocalLifetimeContainerOnly() { BuilderStrategyChain chain = new BuilderStrategyChain(); chain.Add(new CreationStrategy()); Locator parentLocator = new Locator(); LifetimeContainer container = new LifetimeContainer(); parentLocator.Add(typeof (ILifetimeContainer), container); Locator childLocator = new Locator(parentLocator); PolicyList policies = new PolicyList(); policies.SetDefault<ICreationPolicy>(new DefaultCreationPolicy()); policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); BuilderContext ctx = new BuilderContext(chain, childLocator, policies); object obj = ctx.HeadOfChain.BuildUp(ctx, typeof (object), null, null); Assert.IsNotNull(obj); Assert.IsNull(childLocator.Get(new DependencyResolutionLocatorKey(typeof (object), null))); }