PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/V2/trunk/RI/Desktop/StockTraderRI.Modules.Position.Tests/PositionSummary/PositionSummaryPresentationModelFixture.cs

#
C# | 145 lines | 100 code | 25 blank | 20 comment | 0 complexity | b4271a70a714d0ebbf9d8003e4b38df0 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 System;
  18. using System.Collections.Generic;
  19. using System.ComponentModel;
  20. using System.Linq;
  21. using Microsoft.Practices.Composite.Events;
  22. using Microsoft.VisualStudio.TestTools.UnitTesting;
  23. using StockTraderRI.Infrastructure;
  24. using StockTraderRI.Infrastructure.Models;
  25. using StockTraderRI.Modules.Position.PositionSummary;
  26. using StockTraderRI.Modules.Position.Tests.Mocks;
  27. using Microsoft.Practices.Composite.Presentation.Events;
  28. using System.Collections.ObjectModel;
  29. namespace StockTraderRI.Modules.Position.Tests.PositionSummary
  30. {
  31. [TestClass]
  32. public class PositionSummaryPresentationModelFixture
  33. {
  34. MockPositionSummaryView view;
  35. MockOrdersController ordersController;
  36. MockEventAggregator eventAggregator;
  37. MockObservablePosition observablePosition;
  38. [TestInitialize]
  39. public void SetUp()
  40. {
  41. view = new MockPositionSummaryView();
  42. ordersController = new MockOrdersController();
  43. observablePosition = new MockObservablePosition();
  44. this.eventAggregator = new MockEventAggregator();
  45. eventAggregator.AddMapping<TickerSymbolSelectedEvent>(new MockTickerSymbolSelectedEvent());
  46. }
  47. [TestMethod]
  48. public void CanInitPresentationModel()
  49. {
  50. PositionSummaryPresentationModel presentationModel = CreatePresentationModel();
  51. Assert.AreEqual(view, presentationModel.View);
  52. }
  53. [TestMethod]
  54. public void CanSetPresentationModelIntoView()
  55. {
  56. var presentationModel = CreatePresentationModel();
  57. Assert.AreSame(presentationModel, view.Model);
  58. }
  59. [TestMethod]
  60. public void ShouldTriggerPropertyChangedEventOnCurrentPositionSummaryItemChange()
  61. {
  62. PositionSummaryPresentationModel presentationModel = CreatePresentationModel();
  63. string changedPropertyName = string.Empty;
  64. presentationModel.PropertyChanged += (o, e) =>
  65. {
  66. changedPropertyName = e.PropertyName;
  67. };
  68. presentationModel.CurrentPositionSummaryItem = new PositionSummaryItem("NewTickerSymbol", 0, 0, 0);
  69. Assert.AreEqual("CurrentPositionSummaryItem", changedPropertyName);
  70. }
  71. [TestMethod]
  72. public void TickerSymbolSelectedPublishesEvent()
  73. {
  74. var tickerSymbolSelectedEvent = new MockTickerSymbolSelectedEvent();
  75. eventAggregator.AddMapping<TickerSymbolSelectedEvent>(tickerSymbolSelectedEvent);
  76. var presentationModel = CreatePresentationModel();
  77. presentationModel.CurrentPositionSummaryItem = new PositionSummaryItem("FUND0", 0, 0, 0);
  78. Assert.IsTrue(tickerSymbolSelectedEvent.PublishCalled);
  79. Assert.AreEqual("FUND0", tickerSymbolSelectedEvent.PublishArgumentPayload);
  80. }
  81. [TestMethod]
  82. public void ControllerCommandsSetIntoPresentationModel()
  83. {
  84. var presentationModel = CreatePresentationModel();
  85. Assert.AreSame(presentationModel.BuyCommand, ordersController.BuyCommand);
  86. Assert.AreSame(presentationModel.SellCommand, ordersController.SellCommand);
  87. }
  88. private PositionSummaryPresentationModel CreatePresentationModel()
  89. {
  90. return new PositionSummaryPresentationModel(view
  91. , ordersController
  92. , eventAggregator
  93. , observablePosition);
  94. }
  95. [TestMethod]
  96. public void CurrentItemNullDoesNotThrow()
  97. {
  98. var model = CreatePresentationModel();
  99. model.CurrentPositionSummaryItem = null;
  100. }
  101. }
  102. internal class MockTickerSymbolSelectedEvent : TickerSymbolSelectedEvent
  103. {
  104. public bool PublishCalled;
  105. public string PublishArgumentPayload;
  106. public override void Publish(string payload)
  107. {
  108. PublishCalled = true;
  109. PublishArgumentPayload = payload;
  110. }
  111. }
  112. internal class MockObservablePosition : IObservablePosition
  113. {
  114. public ObservableCollection<PositionSummaryItem> Items { get; set; }
  115. }
  116. }
  117. /*
  118. *
  119. * market update with volume change should be reflected in presentation model
  120. */