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