PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/V4/PrismLibrary/Desktop/Prism.Tests/Modularity/ModuleInfoGroupExtensionsFixture.cs

#
C# | 92 lines | 61 code | 12 blank | 19 comment | 0 complexity | 51e8651e4696dbc74b47e9b15d863fc3 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Linq;
19using Microsoft.Practices.Prism.Modularity;
20using Microsoft.VisualStudio.TestTools.UnitTesting;
21
22namespace Microsoft.Practices.Prism.Tests.Modularity
23{
24    /// <summary>
25    /// Summary description for ModuleInfoGroupExtensionsFixture
26    /// </summary>
27    [TestClass]
28    public class ModuleInfoGroupExtensionsFixture
29    {
30        [TestMethod]
31        public void ShouldAddModuleToModuleInfoGroup()
32        {
33            string moduleName = "MockModule";
34            ModuleInfoGroup groupInfo = new ModuleInfoGroup();
35            groupInfo.AddModule(moduleName, typeof(MockModule));
36
37            Assert.AreEqual<int>(1, groupInfo.Count);
38            Assert.AreEqual<string>(moduleName, groupInfo.ElementAt(0).ModuleName);
39        }
40
41        [TestMethod]
42        public void ShouldSetModuleTypeCorrectly()
43        {
44            ModuleInfoGroup groupInfo = new ModuleInfoGroup();
45            groupInfo.AddModule("MockModule", typeof(MockModule));
46
47            Assert.AreEqual<int>(1, groupInfo.Count);
48            Assert.AreEqual<string>(typeof(MockModule).AssemblyQualifiedName, groupInfo.ElementAt(0).ModuleType);
49        }
50
51        [TestMethod]
52        [ExpectedException(typeof(ArgumentNullException))]
53        public void NullTypeThrows()
54        {
55            ModuleInfoGroup groupInfo = new ModuleInfoGroup();
56            groupInfo.AddModule("NullModule", null);
57        }
58
59        [TestMethod]
60        public void ShouldSetDependencies()
61        {
62            string dependency1 = "ModuleA";
63            string dependency2 = "ModuleB";
64
65            ModuleInfoGroup groupInfo = new ModuleInfoGroup();
66            groupInfo.AddModule("MockModule", typeof(MockModule), dependency1, dependency2);
67
68            Assert.IsNotNull(groupInfo.ElementAt(0).DependsOn);
69            Assert.AreEqual(2, groupInfo.ElementAt(0).DependsOn.Count);
70            Assert.IsTrue(groupInfo.ElementAt(0).DependsOn.Contains(dependency1));
71            Assert.IsTrue(groupInfo.ElementAt(0).DependsOn.Contains(dependency2));
72        }
73
74        [TestMethod]
75        public void ShouldUseTypeNameIfNoNameSpecified()
76        {
77            ModuleInfoGroup groupInfo = new ModuleInfoGroup();
78            groupInfo.AddModule(typeof(MockModule));
79
80            Assert.AreEqual<int>(1, groupInfo.Count);
81            Assert.AreEqual<string>(typeof(MockModule).Name, groupInfo.ElementAt(0).ModuleName);
82        }
83
84
85        public class MockModule : IModule
86        {
87            public void Initialize()
88            {
89            }
90        }
91    }
92}