コード例 #1
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        public void AddingToSameKeyTwiceThrows()
        {
            object o = new object();
            IReadWriteLocator locator = new Locator();

            locator.Add("foo1", o);
            locator.Add("foo1", o);
        }
コード例 #2
0
		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);
		}
コード例 #3
0
		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));
		}
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 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());
 }
コード例 #6
0
 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());
 }
コード例 #7
0
 /// <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);
 }
コード例 #8
0
        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)));
        }
コード例 #9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public DependencyInjectionFactoryStrategy(FactoryConfigurationSection configSection)
            : base(configSection)
        {
            locator.Add(typeof(ILifetimeContainer), lifetimeContainer);

            builder = new Builder();
            this.applyConfigurationToBuilder(configSection, this.builder);
        }
コード例 #10
0
        private Locator CreateLocator()
        {
            Locator           locator  = new Locator();
            LifetimeContainer lifetime = new LifetimeContainer();

            locator.Add(typeof(ILifetimeContainer), lifetime);
            return(locator);
        }
コード例 #11
0
 public void SetUp()
 {
     locator   = new Locator();
     container = new LifetimeContainer();
     locator.Add(typeof(ILifetimeContainer), container);
     builder = new Builder();
     builder.Policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true));
 }
コード例 #12
0
        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));
        }
コード例 #13
0
        public void GenericGetEnforcesDataType()
        {
            Locator innerLocator = new Locator();
            ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator);

            innerLocator.Add(1, 2);

            locator.Get<string>(1);
        }
コード例 #14
0
 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());
 }
コード例 #15
0
        public void GenericGetEnforcesDataType()
        {
            Locator         innerLocator = new Locator();
            ReadOnlyLocator locator      = new ReadOnlyLocator(innerLocator);

            innerLocator.Add(1, 2);

            locator.Get <string>(1);
        }
コード例 #16
0
        public void GenericGetWithSearchModeEnforcesDataType()
        {
            Locator         innerLocator = new Locator();
            ReadOnlyLocator locator      = new ReadOnlyLocator(innerLocator);

            innerLocator.Add(1, 2);

            locator.Get <string>(1, SearchMode.Local);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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"));
        }
コード例 #19
0
        private TestableServiceCollection CreateServiceCollection()
        {
            LifetimeContainer container = new LifetimeContainer();
            Locator           locator   = new Locator();

            locator.Add(typeof(ILifetimeContainer), container);

            return(new TestableServiceCollection(container, locator, CreateBuilder()));
        }
コード例 #20
0
        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>());
        }
コード例 #21
0
        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"));
        }
コード例 #22
0
        public void RegistrationDoesNotPreventGarbageCollection()
        {
            IReadWriteLocator locator = new Locator();

            locator.Add("foo", new object());
            GC.Collect();

            Assert.IsNull(locator.Get("foo"));
        }
コード例 #23
0
        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));
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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));
        }
コード例 #26
0
        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"));
        }
コード例 #27
0
        public void RetrievingARemovedObjectReturnsNull()
        {
            object            o       = new object();
            IReadWriteLocator locator = new Locator();

            locator.Add("Foo", o);
            locator.Remove("Foo");

            Assert.IsNull(locator.Get("Foo"));
        }
コード例 #28
0
        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"));
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }
コード例 #31
0
        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);
        }
コード例 #32
0
        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);
        }
コード例 #33
0
        public MockBuilderContext(IReadWriteLocator locator)
        {
            InnerLocator = locator;
            SetLocator(InnerLocator);
            StrategyChain = InnerChain;
            SetPolicies(InnerPolicies);

            if (!Locator.Contains(typeof(ILifetimeContainer)))
            {
                Locator.Add(typeof(ILifetimeContainer), lifetimeContainer);
            }
        }
コード例 #34
0
        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);
        }
コード例 #35
0
        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);
        }
コード例 #36
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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);
        }
コード例 #37
0
        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);
        }
コード例 #38
0
        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);
        }
コード例 #39
0
        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);
        }
コード例 #40
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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);
        }
コード例 #41
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #42
0
		public void GenericGetWithSearchModeEnforcesDataType()
		{
			Locator innerLocator = new Locator();
			ReadOnlyLocator locator = new ReadOnlyLocator(innerLocator);

			innerLocator.Add(1, 2);

			locator.Get<string>(1, SearchMode.Local);
		}
コード例 #43
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #44
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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>());
        }
コード例 #45
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #46
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #47
0
        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)));
        }
コード例 #48
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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);
        }
コード例 #49
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        public void NullKeyOnAddThrows()
        {
            IReadWriteLocator locator = new Locator();

            locator.Add(null, 1);
        }
コード例 #50
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        public void NullValueOnAddThrows()
        {
            IReadWriteLocator locator = new Locator();

            locator.Add(1, null);
        }
コード例 #51
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #52
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        public void RegistrationDoesNotPreventGarbageCollection()
        {
            IReadWriteLocator locator = new Locator();

            locator.Add("foo", new object());
            GC.Collect();

            Assert.IsNull(locator.Get("foo"));
        }
コード例 #53
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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));
        }
コード例 #54
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #55
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #56
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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"));
        }
コード例 #57
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        public void RetrievingARemovedObjectReturnsNull()
        {
            object o = new object();
            IReadWriteLocator locator = new Locator();

            locator.Add("Foo", o);
            locator.Remove("Foo");

            Assert.IsNull(locator.Get("Foo"));
        }
コード例 #58
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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);
        }
コード例 #59
0
ファイル: BuilderFixture.cs プロジェクト: bnantz/NCS-V2-0
 private Locator CreateLocator()
 {
     Locator locator = new Locator();
     LifetimeContainer lifetime = new LifetimeContainer();
     locator.Add(typeof(ILifetimeContainer), lifetime);
     return locator;
 }
コード例 #60
0
ファイル: LocatorFixture.cs プロジェクト: bnantz/NCS-V2-0
        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);
        }