public void AddingToSameKeyTwiceThrows() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o); locator.Add("foo1", o); }
public void ReadOnlyLocatorCountReflectsInnerLocatorCount() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 1); innerLocator.Add(2, 2); Assert.AreEqual(innerLocator.Count, locator.Count); }
public void ItemsContainedInLocatorContainedInReadOnlyLocator() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 1); innerLocator.Add(2, 2); Assert.IsTrue(locator.Contains(1)); Assert.IsTrue(locator.Contains(2)); Assert.IsFalse(locator.Contains(3)); }
public void CanEnumerate() { object o1 = new object(); object o2 = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o1); locator.Add("foo2", o2); foreach (KeyValuePair <object, object> kvp in locator) { Assert.IsNotNull(kvp); Assert.IsNotNull(kvp.Key); Assert.IsNotNull(kvp.Value); } }
protected override void OnStart() { Locator.Add <IDatabase>(new Database(DatabaseSettings.DatabasePath, DatabaseSettings.DatabaseName)); Locator.Add <IPublishedCameraRepository>(new PublishedCameraRepository()); Locator.Add <IStreamingManager>(new StreamingManager()); Locator.Add <IPublishedCameraManager>(new PublishedCameraManager().Restore()); }
private static void StartDiscoverService <T>() where T : class { // 主动搜索 Locator.Add <IAdHocDiscoveryClient <T> >(new AdHocDiscoveryClient <T>(Locator.Get <EndpointDiscoveryMetadataCollection>()).Start()); // 被动通知 Locator.Add <IAnnouncementMonitor <T> >(new AnnouncementMonitor <T>(Locator.Get <EndpointDiscoveryMetadataCollection>()).Start()); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyContainer"/> class. /// </summary> /// <param name="configurator">The container configurator.</param> public DependencyContainer(IBuilderConfigurator <BuilderStage> configurator) { builder = new BuilderBase <BuilderStage>(configurator); locator = new Locator(); lifetime = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), lifetime); }
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))); }
/// <summary> /// Constructor. /// </summary> public DependencyInjectionFactoryStrategy(FactoryConfigurationSection configSection) : base(configSection) { locator.Add(typeof(ILifetimeContainer), lifetimeContainer); builder = new Builder(); this.applyConfigurationToBuilder(configSection, this.builder); }
private Locator CreateLocator() { Locator locator = new Locator(); LifetimeContainer lifetime = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), lifetime); return(locator); }
public void SetUp() { locator = new Locator(); container = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), container); builder = new Builder(); builder.Policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true)); }
private TestableManagedObjectCollection <object> CreateManagedObjectCollection(SearchMode searchMode, ManagedObjectCollection <object> .IndexerCreationDelegate indexerCreationDelegate, Predicate <object> filter) { LifetimeContainer container = new LifetimeContainer(); Locator locator = new Locator(); locator.Add(typeof(ILifetimeContainer), container); return(new TestableManagedObjectCollection <object>(container, locator, CreateBuilder(), searchMode, indexerCreationDelegate, filter, null)); }
public void GenericGetEnforcesDataType() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 2); locator.Get<string>(1); }
static ServiceProvider() { // 服务缓存 Locator.Add <EndpointDiscoveryMetadataCollection>(new EndpointDiscoveryMetadataCollection()); // 主动搜索 Locator.Add <IAdHocDiscoveryClient <IServiceDiscoveryService> >(new AdHocDiscoveryClient <IServiceDiscoveryService>(Locator.Get <EndpointDiscoveryMetadataCollection>()).Start()); // 被动通知 Locator.Add <IAnnouncementMonitor <IServiceDiscoveryService> >(new AnnouncementMonitor <IServiceDiscoveryService>(Locator.Get <EndpointDiscoveryMetadataCollection>()).Start()); }
public void GenericGetEnforcesDataType() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 2); locator.Get <string>(1); }
public void GenericGetWithSearchModeEnforcesDataType() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 2); locator.Get <string>(1, SearchMode.Local); }
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 CanFindOutIfContainsAKey() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo", o); Assert.IsTrue(locator.Contains("foo")); Assert.IsFalse(locator.Contains("foo2")); }
private TestableServiceCollection CreateServiceCollection() { LifetimeContainer container = new LifetimeContainer(); Locator locator = new Locator(); locator.Add(typeof(ILifetimeContainer), container); return(new TestableServiceCollection(container, locator, CreateBuilder())); }
public void CanRegisterObjectByType() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add(typeof(object), o); Assert.IsNotNull(locator.Get <object>()); Assert.AreSame(o, locator.Get <object>()); }
public void CanRegisterObjectByName() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("Bar", o); Assert.IsNotNull(locator.Get("Bar")); Assert.AreSame(o, locator.Get("Bar")); }
public void RegistrationDoesNotPreventGarbageCollection() { IReadWriteLocator locator = new Locator(); locator.Add("foo", new object()); GC.Collect(); Assert.IsNull(locator.Get("foo")); }
public void CanRegisterObjectByTypeAndID() { object o = new object(); IReadWriteLocator locator = new Locator(); DependencyResolutionLocatorKey key = new DependencyResolutionLocatorKey(typeof(object), "foo"); locator.Add(key, o); Assert.IsNotNull(locator.Get(key)); Assert.AreSame(o, locator.Get(key)); }
public void LocalSearchFailsIfDependencyIsOnlyUpstream() { Locator parent = new Locator(); parent.Add(new DependencyResolutionLocatorKey(typeof(int), null), 25); Locator child = new Locator(parent); MockBuilderContext context = CreateContext(child); context.HeadOfChain.BuildUp(context, typeof(SearchLocalMockObject), null, null); }
public void CanRegisterObjectByTypeAndID() { object o = new object(); IReadWriteLocator locator = new Locator(); NamedTypeBuildKey key = new NamedTypeBuildKey(typeof(object), "foo"); locator.Add(key, o); Assert.IsNotNull(locator.Get(key)); Assert.AreSame(o, locator.Get(key)); }
public void DefaultBehaviorIsAskingParent() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("fiz", o); Assert.IsNotNull(childLocator.Get("fiz")); }
public void RetrievingARemovedObjectReturnsNull() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("Foo", o); locator.Remove("Foo"); Assert.IsNull(locator.Get("Foo")); }
public void CanCallContainsThroughParent() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("froz", o); Assert.IsTrue(childLocator.Contains("froz")); }
public void CanSearchDependencyUp() { Locator parent = new Locator(); parent.Add(new DependencyResolutionLocatorKey(typeof(int), null), 25); Locator child = new Locator(parent); MockBuilderContext context = CreateContext(child); context.HeadOfChain.BuildUp(context, typeof(SearchUpMockObject), null, null); }
public void CanCreateStronglyTypedConstructor() { BuilderBase <BuilderStage> builder = new BuilderBase <BuilderStage>(); builder.Strategies.AddNew <SingletonStrategy>(BuilderStage.PreCreation); builder.Strategies.AddNew <CreationStrategy>(BuilderStage.Creation); builder.Policies.SetDefault <ICreationPolicy>(new DefaultCreationPolicy()); Locator locator = new Locator(); IService service = new Service(); IFoo foo = new Foo(); locator.Add(new DependencyResolutionLocatorKey(typeof(IService), null), service); locator.Add(new DependencyResolutionLocatorKey(typeof(IFoo), null), foo); MockWithCtorDependencies mock = builder.BuildUp <MockWithCtorDependencies>(locator, null, null); Assert.IsNotNull(mock); Assert.AreSame(foo, mock.foo); Assert.AreSame(service, mock.service); }
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 RegisterSingletonInstance(Type typeToRegisterAs, object instance) { if (!typeToRegisterAs.IsInstanceOfType(instance)) { throw new ArgumentException("Object is not type compatible with registration type", "instance"); } locator.Add(typeToRegisterAs, instance); lifetime.Add(instance); }
public MockBuilderContext(IReadWriteLocator locator) { InnerLocator = locator; SetLocator(InnerLocator); StrategyChain = InnerChain; SetPolicies(InnerPolicies); if (!Locator.Contains(typeof(ILifetimeContainer))) { Locator.Add(typeof(ILifetimeContainer), lifetimeContainer); } }
public void GetCanAskParentLocatorForAnObject() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("Foo", o); object result = childLocator.Get("Foo"); Assert.IsNotNull(result); Assert.AreSame(o, result); }
public void CanEnumerateItemsInReadOnlyLocator() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 1); innerLocator.Add(2, 2); bool sawOne = false; bool sawTwo = false; foreach (KeyValuePair<object, object> pair in locator) { if (pair.Key.Equals(1)) sawOne = true; if (pair.Key.Equals(2)) sawTwo = true; } Assert.IsTrue(sawOne); Assert.IsTrue(sawTwo); }
public void AskingParentStopsAsSoonAsWeFindAMatch() { object o1 = new object(); object o2 = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); IReadWriteLocator grandchildLocator = new Locator(childLocator); rootLocator.Add("foo", o1); childLocator.Add("foo", o2); object result = grandchildLocator.Get("foo", SearchMode.Up); Assert.IsNotNull(result); Assert.AreSame(o2, result); }
public void LocalSearchGetsLocalIfDependencyIsAlsoUpstream() { Locator parent = new Locator(); parent.Add(new DependencyResolutionLocatorKey(typeof(int), null), 25); Locator child = new Locator(parent); child.Add(new DependencyResolutionLocatorKey(typeof(int), null), 15); MockBuilderContext context = CreateContext(child); SearchLocalMockObject obj = (SearchLocalMockObject)context.HeadOfChain.BuildUp(context, typeof(SearchLocalMockObject), null, null); Assert.AreEqual(15, obj.Value); }
public void CountReturnsNumberOfKeysWithLiveValues() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o); locator.Add("foo2", o); Assert.AreEqual(2, locator.Count); o = null; GC.Collect(); Assert.AreEqual(0, locator.Count); }
public void CanRegisterTwoObjectsWithDifferentKeys() { object o1 = new object(); object o2 = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o1); locator.Add("foo2", o2); Assert.AreSame(o1, locator.Get("foo1")); Assert.AreSame(o2, locator.Get("foo2")); }
public void GenericGetWithSearchModeEnforcesDataType() { Locator innerLocator = new Locator(); ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator); innerLocator.Add(1, 2); locator.Get<string>(1, SearchMode.Local); }
public void CanRegisterObjectByType() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add(typeof(object), o); Assert.IsNotNull(locator.Get<object>()); Assert.AreSame(o, locator.Get<object>()); }
public void RemovingOneObjectDoesntAffectOtherObjects() { object o1 = new object(); object o2 = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o1); locator.Add("foo2", o2); Assert.IsTrue(locator.Remove("foo1")); Assert.AreSame(o2, locator.Get("foo2")); }
public void FindingByPredicateReturnsClosestResultsOnDuplicateKey() { object o1 = new object(); object o2 = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("foo", o1); childLocator.Add("foo", o2); IReadableLocator results; results = childLocator.FindBy( SearchMode.Up, delegate(KeyValuePair<object, object> kvp) { return true; }); Assert.AreEqual(1, results.Count); Assert.AreSame(o2, results.Get("foo")); }
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))); }
public void GetCanAskParentLocatorForAnObject() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("Foo", o); object result = childLocator.Get("Foo", SearchMode.Up); Assert.IsNotNull(result); Assert.AreSame(o, result); }
public void NullKeyOnAddThrows() { IReadWriteLocator locator = new Locator(); locator.Add(null, 1); }
public void NullValueOnAddThrows() { IReadWriteLocator locator = new Locator(); locator.Add(1, null); }
public void RegisteringAnObjectWithTwoKeysAndRemovingOneKeyLeavesTheOtherOneInTheLocator() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("foo1", o); locator.Add("foo2", o); locator.Remove("foo1"); Assert.AreSame(o, locator.Get("foo2")); }
public void FindingByPredicateCanFindsResultsFromBothParentAndChild() { object o = new object(); string s = "Hello world"; IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("foo", o); childLocator.Add("bar", s); IReadableLocator results; results = childLocator.FindBy( SearchMode.Up, delegate(KeyValuePair<object, object> kvp) { return true; }); Assert.AreEqual(2, results.Count); Assert.AreSame(o, results.Get("foo")); Assert.AreSame(s, results.Get("bar")); }
public void CanRegisterObjectByStringKey() { object o = new object(); IReadWriteLocator locator = new Locator(); locator.Add("Bar", o); Assert.IsNotNull(locator.Get("Bar")); Assert.AreSame(o, locator.Get("Bar")); }
public void FindingByPredicateCanClimbTheTree() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("bar", o); IReadableLocator results; results = childLocator.FindBy( SearchMode.Up, delegate(KeyValuePair<object, object> kvp) { return true; }); Assert.AreEqual(1, results.Count); Assert.AreSame(o, results.Get("bar")); }
public void DefaultFindByBehaviorIsAskParent() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); rootLocator.Add("foo", o); IReadableLocator results; results = childLocator.FindBy(delegate(KeyValuePair<object, object> kvp) { return true; }); Assert.AreEqual(1, results.Count); }
private Locator CreateLocator() { Locator locator = new Locator(); LifetimeContainer lifetime = new LifetimeContainer(); locator.Add(typeof(ILifetimeContainer), lifetime); return locator; }
public void TripleNestedLocators() { object o = new object(); IReadWriteLocator rootLocator = new Locator(); IReadWriteLocator childLocator = new Locator(rootLocator); IReadWriteLocator grandchildLocator = new Locator(childLocator); rootLocator.Add("bar", o); object result = grandchildLocator.Get("bar", SearchMode.Up); Assert.IsNotNull(result); Assert.AreSame(o, result); }