PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/PrismLibrary/Desktop/Prism.Tests/Regions/NavigationAsyncExtensionsFixture.cs

#
C# | 122 lines | 87 code | 19 blank | 16 comment | 9 complexity | 65240f2ff4f7e5b707fa5c6ae8636715 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 Microsoft.Practices.Prism.Regions;
  19. using Microsoft.Practices.Prism.TestSupport;
  20. using Microsoft.VisualStudio.TestTools.UnitTesting;
  21. using Moq;
  22. namespace Microsoft.Practices.Prism.Tests.Regions
  23. {
  24. [TestClass]
  25. public class NavigationAsyncExtensionsFixture
  26. {
  27. [TestMethod]
  28. public void WhenNavigatingWithANullThis_ThenThrows()
  29. {
  30. INavigateAsync navigate = null;
  31. string target = "";
  32. ExceptionAssert.Throws<ArgumentNullException>(
  33. () =>
  34. {
  35. navigate.RequestNavigate(target);
  36. });
  37. }
  38. [TestMethod]
  39. public void WhenNavigatingWithANullStringTarget_ThenThrows()
  40. {
  41. INavigateAsync navigate = new Mock<INavigateAsync>().Object;
  42. string target = null;
  43. ExceptionAssert.Throws<ArgumentNullException>(
  44. () =>
  45. {
  46. navigate.RequestNavigate(target);
  47. });
  48. }
  49. [TestMethod]
  50. public void WhenNavigatingWithARelativeStringTarget_ThenNavigatesToRelativeUri()
  51. {
  52. var navigateMock = new Mock<INavigateAsync>();
  53. navigateMock
  54. .Setup(nv =>
  55. nv.RequestNavigate(
  56. It.Is<Uri>(u => !u.IsAbsoluteUri && u.OriginalString == "relative"),
  57. It.Is<Action<NavigationResult>>(c => c != null)))
  58. .Verifiable();
  59. string target = "relative";
  60. navigateMock.Object.RequestNavigate(target);
  61. navigateMock.VerifyAll();
  62. }
  63. [TestMethod]
  64. public void WhenNavigatingWithAnAbsoluteStringTarget_ThenNavigatesToAbsoluteUri()
  65. {
  66. var navigateMock = new Mock<INavigateAsync>();
  67. navigateMock
  68. .Setup(nv =>
  69. nv.RequestNavigate(
  70. It.Is<Uri>(u => u.IsAbsoluteUri && u.Host == "test" && u.AbsolutePath == "/path"),
  71. It.Is<Action<NavigationResult>>(c => c != null)))
  72. .Verifiable();
  73. string target = "http://test/path";
  74. navigateMock.Object.RequestNavigate(target);
  75. navigateMock.VerifyAll();
  76. }
  77. [TestMethod]
  78. public void WhenNavigatingWithANullThisAndAUri_ThenThrows()
  79. {
  80. INavigateAsync navigate = null;
  81. Uri target = new Uri("test", UriKind.Relative);
  82. ExceptionAssert.Throws<ArgumentNullException>(
  83. () =>
  84. {
  85. navigate.RequestNavigate(target);
  86. });
  87. }
  88. [TestMethod]
  89. public void WhenNavigatingWithAUri_ThenNavigatesToUriWithCallback()
  90. {
  91. Uri target = new Uri("relative", UriKind.Relative);
  92. var navigateMock = new Mock<INavigateAsync>();
  93. navigateMock
  94. .Setup(nv =>
  95. nv.RequestNavigate(
  96. target,
  97. It.Is<Action<NavigationResult>>(c => c != null)))
  98. .Verifiable();
  99. navigateMock.Object.RequestNavigate(target);
  100. navigateMock.VerifyAll();
  101. }
  102. }
  103. }