PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/V4/MVVM RI/MVVM.Client.Tests/Infrastructure/ViewFactoryFixture.cs

#
C# | 64 lines | 38 code | 10 blank | 16 comment | 0 complexity | 77fa9a8d07fde7c63a11d81b5f56dfe8 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.Composition.Hosting;
19using System.Windows.Controls;
20using Microsoft.VisualStudio.TestTools.UnitTesting;
21using MVVM.Client.Infrastructure;
22
23namespace MVVM.Client.Tests.Infrastructure
24{
25    [TestClass]
26    public class ViewFactoryFixture
27    {
28        [TestMethod]
29        public void WhenViewRequested_ThenReturnsFromContainer()
30        {
31            var catalog = new TypeCatalog(typeof(TestView));
32            var container = new CompositionContainer(catalog);
33
34            var viewFactory = new ViewFactory(container);
35
36            var view = viewFactory.GetView("TestView");
37            Assert.IsNotNull(view);
38        }
39
40        [TestMethod]
41        public void WhenNonExistingVeiwRequested_ThenThrowsException()
42        {
43            var catalog = new TypeCatalog(typeof(TestView));
44            var container = new CompositionContainer(catalog);
45
46            var viewFactory = new ViewFactory(container);
47
48            ExceptionAssert.Throws<Exception>(
49                () =>
50                {
51                    viewFactory.GetView("NonExistentView");
52                }
53            );
54        }
55
56        [ExportView("TestView")]
57        public class TestView : UserControl
58        {
59        }
60    }
61
62
63
64}