public AddIfMissing ( string behaviorKey, |
||
behaviorKey | string | The behavior key that's used to find if a certain behavior is already added. |
behaviorType | Type of the behavior to add. | |
리턴 | void |
public void WillNotAddTypesWithDuplicateKeys() { RegionBehaviorFactory factory = new RegionBehaviorFactory(null); factory.AddIfMissing("key1", typeof(MockRegionBehavior)); factory.AddIfMissing("key1", typeof(MockRegionBehavior)); Assert.AreEqual(1, factory.Count()); }
public void CanRegisterType() { RegionBehaviorFactory factory = new RegionBehaviorFactory(null); factory.AddIfMissing("key1", typeof(MockRegionBehavior)); factory.AddIfMissing("key2", typeof(MockRegionBehavior)); Assert.AreEqual(2, factory.Count()); Assert.IsTrue(factory.ContainsKey("key1")); }
public void CanCreateRegisteredType() { var expectedBehavior = new MockRegionBehavior(); RegionBehaviorFactory factory = new RegionBehaviorFactory(new MockServiceLocator() { GetInstance = (t) => expectedBehavior }); factory.AddIfMissing("key1", typeof(MockRegionBehavior)); var behavior = factory.CreateFromKey("key1"); Assert.AreSame(expectedBehavior, behavior); }
public void AddTypeThatDoesNotInheritFromIRegionBehaviorThrows() { RegionBehaviorFactory factory = new RegionBehaviorFactory(null); Assert.ThrowsException<ArgumentException>(() => factory.AddIfMissing("key1", typeof(object))); }
public void AddTypeThatDoesNotInheritFromIRegionBehaviorThrows() { RegionBehaviorFactory factory = new RegionBehaviorFactory(null); factory.AddIfMissing("key1", typeof(object)); }