/V4/PrismLibrary/Desktop/Prism.Tests/Regions/RegionBehaviorFactoryFixture.cs
C# | 84 lines | 52 code | 16 blank | 16 comment | 0 complexity | 099bcae7a09c5d042e50f916c6de89ea MD5 | raw file
- //===================================================================================
- // Microsoft patterns & practices
- // Composite Application Guidance for Windows Presentation Foundation and Silverlight
- //===================================================================================
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
- // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
- // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- // FITNESS FOR A PARTICULAR PURPOSE.
- //===================================================================================
- // The example companies, organizations, products, domain names,
- // e-mail addresses, logos, people, places, and events depicted
- // herein are fictitious. No association with any real company,
- // organization, product, domain name, email address, logo, person,
- // places, or events is intended or should be inferred.
- //===================================================================================
- using System;
- using System.Linq;
- using Microsoft.Practices.Prism.Tests.Mocks;
- using Microsoft.Practices.Prism.Regions;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- namespace Microsoft.Practices.Prism.Tests.Regions
- {
- [TestClass]
- public class RegionBehaviorFactoryFixture
- {
- [TestMethod]
- 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"));
-
- }
-
- [TestMethod]
- public void WillNotAddTypesWithDuplicateKeys()
- {
- RegionBehaviorFactory factory = new RegionBehaviorFactory(null);
-
- factory.AddIfMissing("key1", typeof(MockRegionBehavior));
- factory.AddIfMissing("key1", typeof(MockRegionBehavior));
-
- Assert.AreEqual(1, factory.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void AddTypeThatDoesNotInheritFromIRegionBehaviorThrows()
- {
- RegionBehaviorFactory factory = new RegionBehaviorFactory(null);
-
- factory.AddIfMissing("key1", typeof(object));
- }
-
- [TestMethod]
- 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);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CreateWithUnknownKeyThrows()
- {
- RegionBehaviorFactory factory = new RegionBehaviorFactory(null);
-
- factory.CreateFromKey("Key1");
- }
-
- }
- }