PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/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. //===================================================================================
  17. using System;
  18. using System.ComponentModel.Composition.Hosting;
  19. using System.Windows.Controls;
  20. using Microsoft.VisualStudio.TestTools.UnitTesting;
  21. using MVVM.Client.Infrastructure;
  22. namespace MVVM.Client.Tests.Infrastructure
  23. {
  24. [TestClass]
  25. public class ViewFactoryFixture
  26. {
  27. [TestMethod]
  28. public void WhenViewRequested_ThenReturnsFromContainer()
  29. {
  30. var catalog = new TypeCatalog(typeof(TestView));
  31. var container = new CompositionContainer(catalog);
  32. var viewFactory = new ViewFactory(container);
  33. var view = viewFactory.GetView("TestView");
  34. Assert.IsNotNull(view);
  35. }
  36. [TestMethod]
  37. public void WhenNonExistingVeiwRequested_ThenThrowsException()
  38. {
  39. var catalog = new TypeCatalog(typeof(TestView));
  40. var container = new CompositionContainer(catalog);
  41. var viewFactory = new ViewFactory(container);
  42. ExceptionAssert.Throws<Exception>(
  43. () =>
  44. {
  45. viewFactory.GetView("NonExistentView");
  46. }
  47. );
  48. }
  49. [ExportView("TestView")]
  50. public class TestView : UserControl
  51. {
  52. }
  53. }
  54. }