PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/StockTrader RI/Desktop/StockTraderRI.Modules.News.Tests/Controllers/NewsControllerFixture.cs

#
C# | 75 lines | 45 code | 11 blank | 19 comment | 0 complexity | 658378317f682e42e34686baf6cdff4a 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.ComponentModel;
19using Microsoft.Practices.Prism.Events;
20using Microsoft.VisualStudio.TestTools.UnitTesting;
21using Moq;
22using StockTraderRI.Infrastructure;
23using StockTraderRI.Infrastructure.Models;
24using StockTraderRI.Modules.News.Article;
25using StockTraderRI.Modules.News.Controllers;
26using StockTraderRI.Infrastructure.Interfaces;
27using Microsoft.Practices.Prism.Regions;
28
29namespace StockTraderRI.Modules.News.Tests.Controllers
30{
31    [TestClass]
32    public class NewsControllerFixture
33    {
34        [TestMethod]
35        public void WhenArticleViewModelSelectedArticleChanged_NewsReaderViewModelNewsArticleUpdated()
36        {
37            // Prepare
38            INewsFeedService newsFeedService = new Mock<INewsFeedService>().Object;
39            IRegionManager regionManager = new Mock<IRegionManager>().Object;
40
41            var tickerSymbolSelectedEvent = new Mock<TickerSymbolSelectedEvent>().Object;
42
43            var mockEventAggregator = new Mock<IEventAggregator>();
44            mockEventAggregator.Setup(x => x.GetEvent<TickerSymbolSelectedEvent>()).Returns(tickerSymbolSelectedEvent);
45            IEventAggregator eventAggregator = mockEventAggregator.Object;
46
47
48            ArticleViewModel articleViewModel = new ArticleViewModel(newsFeedService, regionManager, eventAggregator);
49            NewsReaderViewModel newsReaderViewModel = new NewsReaderViewModel();
50
51            var controller = new NewsController(articleViewModel, newsReaderViewModel);
52
53            NewsArticle newsArticle = new NewsArticle() { Title = "SomeTitle", Body = "Newsbody" };
54
55            // Act
56            articleViewModel.SelectedArticle = newsArticle;
57
58            // Verify
59            Assert.AreSame(newsArticle, newsReaderViewModel.NewsArticle);
60        }
61
62        internal class MockTickerSymbolSelectedEvent : TickerSymbolSelectedEvent
63        {
64            public Action<string> SubscribeArgumentAction;
65            public Predicate<string> SubscribeArgumentFilter;
66            public override SubscriptionToken Subscribe(Action<string> action, ThreadOption threadOption, bool keepSubscriberReferenceAlive, Predicate<string> filter)
67            {
68                SubscribeArgumentAction = action;
69                SubscribeArgumentFilter = filter;
70                return null;
71            }
72        }
73
74    }
75}