public void SingletonPolicyBasedOnConcreteTypeRatherThanRequestedType() { WCSFBuilder builder = new WCSFBuilder(); LifetimeContainer lifetimeContainer = new LifetimeContainer(); Locator locator = CreateLocator(lifetimeContainer); builder.Policies.Set <ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Foo), null), typeof(IFoo), null); builder.Policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true)); GC.Collect(); object obj1 = builder.BuildUp(locator, typeof(IFoo), null, null); object obj2 = builder.BuildUp(locator, typeof(IFoo), null, null); Assert.AreSame(obj1, obj2); GC.KeepAlive(lifetimeContainer); }
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 EmptyBuilderWillCreateAnyValueTypeWithDefaultValue() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); int actual = builder.BuildUp <int>(locator, null, null); Assert.AreEqual(default(int), actual); }
public void EmptyBuilderWillCreateSimpleInstances() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); SimpleObject o = builder.BuildUp <SimpleObject>(locator, null, null); Assert.IsNotNull(o); Assert.AreEqual(0, o.IntParam); }
public void EmptyBuilderWillCreateComplexInstances() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); ComplexObject o = builder.BuildUp <ComplexObject>(locator, null, null); Assert.IsNotNull(o); Assert.IsNotNull(o.SimpleObject); Assert.AreEqual(default(int), o.SimpleObject.IntParam); }
public void CanMapTypesWithDefaultObjectBuilder() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); TypeMappingPolicy policy = new TypeMappingPolicy(typeof(MockObject), null); builder.Policies.Set <ITypeMappingPolicy>(policy, typeof(IMockObject), null); IMockObject obj = builder.BuildUp <IMockObject>(locator, null, null); Assert.IsTrue(obj is MockObject); }
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); }
public void TestSimpleDependency() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), container); WCSFBuilder builder = new WCSFBuilder(); TestProviderHost.Provider = new MockProvider(); TestSimpleDependency obj = builder.BuildUp <TestSimpleDependency>(locator, "foo", null); Assert.IsNotNull(obj.Provider); Assert.AreSame(TestProviderHost.Provider, obj.Provider); }
public void TestPareameteDependencyWithNamedGetter() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), container); WCSFBuilder builder = new WCSFBuilder(); TestProviderHost.AnotherProvider = new MockProvider(); TestNamedParameterDependency obj = builder.BuildUp <TestNamedParameterDependency>(locator, "foo", null); Assert.IsNotNull(obj.Provider); Assert.AreSame(TestProviderHost.AnotherProvider, obj.Provider); }
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 BuildUpReturnsInstanceOfStateValueWithCorrespondantValueFromSessionWhenInjectingConstructor() { 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["stringKey"] = "value"; SampleClass builtObject = builder.BuildUp(locator, typeof (SampleClass), Guid.NewGuid().ToString(), null) as SampleClass; Assert.IsNotNull(builtObject.MyStringValue); Assert.IsNotNull(builtObject.MyStringValue.Value); Assert.AreEqual("value", builtObject.MyStringValue.Value); }
public void TestBuildWithSimpleDependency() { Locator locator = new Locator(); WCSFBuilder builder = new WCSFBuilder(); builder.Policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true)); TestableRootCompositionContainer compositionContainer = new TestableRootCompositionContainer(builder); locator.Add(new DependencyResolutionLocatorKey(typeof(CompositionContainer), null), compositionContainer); ITestService service = compositionContainer.Services.AddNew <TestService, ITestService>(); TestSimpleDependency builtObject = builder.BuildUp(locator, typeof(TestSimpleDependency), Guid.NewGuid().ToString(), null) as TestSimpleDependency; Assert.IsNotNull(builtObject); Assert.IsNotNull(builtObject.TestService); Assert.AreEqual(service, builtObject.TestService); }
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 TestDependantProviderDependency() { Locator locator = new Locator(); LifetimeContainer container = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), container); TestableRootCompositionContainer compositionContainer = new TestableRootCompositionContainer(); locator.Add(new DependencyResolutionLocatorKey(typeof(CompositionContainer), null), compositionContainer); MockDependencyObject mockDependency = compositionContainer.Services.AddNew <MockDependencyObject, MockDependencyObject>(); WCSFBuilder builder = new WCSFBuilder(); TestDependentProviderHost.Provider = new MockDependentProvider(); TestDependentParameterDependency obj = builder.BuildUp <TestDependentParameterDependency>(locator, "foo", null); Assert.IsNotNull(obj.Provider); Assert.AreSame(TestDependentProviderHost.Provider, obj.Provider); Assert.IsNotNull(TestDependentProviderHost.Provider.DependencyObject); Assert.AreSame(mockDependency, TestDependentProviderHost.Provider.DependencyObject); }
public void EmptyBuilderWillCreateComplexInstances() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); ComplexObject o = builder.BuildUp<ComplexObject>(locator, null, null); Assert.IsNotNull(o); Assert.IsNotNull(o.SimpleObject); Assert.AreEqual(default(int), o.SimpleObject.IntParam); }
public void CanMapTypesWithDefaultObjectBuilder() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); TypeMappingPolicy policy = new TypeMappingPolicy(typeof (MockObject), null); builder.Policies.Set<ITypeMappingPolicy>(policy, typeof (IMockObject), null); IMockObject obj = builder.BuildUp<IMockObject>(locator, null, null); Assert.IsTrue(obj is MockObject); }
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 SingletonPolicyBasedOnConcreteTypeRatherThanRequestedType() { WCSFBuilder builder = new WCSFBuilder(); LifetimeContainer lifetimeContainer = new LifetimeContainer(); Locator locator = CreateLocator(lifetimeContainer); builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof (Foo), null), typeof (IFoo), null); builder.Policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true)); GC.Collect(); object obj1 = builder.BuildUp(locator, typeof (IFoo), null, null); object obj2 = builder.BuildUp(locator, typeof (IFoo), null, null); Assert.AreSame(obj1, obj2); GC.KeepAlive(lifetimeContainer); }
public void EmptyBuilderWillCreateSimpleInstances() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); SimpleObject o = builder.BuildUp<SimpleObject>(locator, null, null); Assert.IsNotNull(o); Assert.AreEqual(0, o.IntParam); }
public void EmptyBuilderWillCreateAnyValueTypeWithDefaultValue() { WCSFBuilder builder = new WCSFBuilder(); Locator locator = CreateLocator(); int actual = builder.BuildUp<int>(locator, null, null); Assert.AreEqual(default(int), actual); }
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); }