PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/V2/trunk/RI/Desktop/StockTraderRI.Modules.News.Tests/NewsModuleFixture.cs

#
C# | 87 lines | 56 code | 12 blank | 19 comment | 0 complexity | 478ae325012c21cb81e387e3c211f198 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 Microsoft.Practices.Unity;
18using Microsoft.VisualStudio.TestTools.UnitTesting;
19using StockTraderRI.Infrastructure.Interfaces;
20using StockTraderRI.Modules.News.Article;
21using StockTraderRI.Modules.News.Controllers;
22using StockTraderRI.Modules.News.Services;
23using StockTraderRI.Modules.News.Tests.Mocks;
24
25namespace StockTraderRI.Modules.News.Tests
26{
27    /// <summary>
28    /// Summary description for UnitTest1
29    /// </summary>
30    [TestClass]
31    public class NewsModuleFixture
32    {
33        private MockUnityResolver container;
34        private MockNewsController controller;
35
36        [TestMethod]
37        public void NewsModuleRegistersNewsViewAndNewsFeedService()
38        {
39            TestableNewsModule newsModule = CreateTestableNewsModule();
40
41            newsModule.InvokeRegisterViewsAndServices();
42
43            Assert.AreEqual(typeof(ArticleView), container.Types[typeof(IArticleView)]);
44            Assert.AreEqual(typeof(NewsController), container.Types[typeof(INewsController)]);
45            Assert.AreEqual(typeof(ArticlePresentationModel), container.Types[typeof(IArticlePresentationModel)]);
46            Assert.AreEqual(typeof(NewsFeedService), container.Types[typeof(INewsFeedService)]);
47#if !SILVERLIGHT
48            Assert.AreEqual(typeof(NewsReaderPresenter), container.Types[typeof(INewsReaderPresenter)]);
49            Assert.AreEqual(typeof(NewsReader), container.Types[typeof(INewsReaderView)]);
50#endif
51        }
52
53        [TestMethod]
54        public void InitCallsRunOnNewsController()
55        {
56            var newsModule = CreateTestableNewsModule();
57
58            newsModule.Initialize();
59
60            Assert.IsTrue(controller.RunCalled);
61        }
62
63        private TestableNewsModule CreateTestableNewsModule()
64        {
65            this.container = new MockUnityResolver();
66            this.controller = new MockNewsController();
67
68            container.Bag.Add(typeof(INewsController), controller);
69            container.Bag.Add(typeof(INewsReaderView), null);
70
71            return new TestableNewsModule(container);
72        }
73
74        internal class TestableNewsModule : NewsModule
75        {
76            public TestableNewsModule(IUnityContainer container)
77                : base(container)
78            {
79            }
80
81            public void InvokeRegisterViewsAndServices()
82            {
83                base.RegisterViewsAndServices();
84            }
85        }
86    }
87}