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