コード例 #1
0
        public async Task ShouldIgnoreInvalidUrls()
        {
            var url = "invalidurl";

            var dialog = Dialog;

            dialog.Setup(d => d.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true)
            .Verifiable();

            var browser = Browser;

            browser.Setup(b => b.ShowInBrowserAsync(It.IsAny <Uri>(), It.IsAny <bool>()))
            .ReturnsAsync(true)
            .Verifiable();

            var sut = new StoryViewModel(Share.Object, Browser.Object, dialog.Object);

            await sut.HandleExternalLinkAsync(url);

            browser.Verify(b => b.ShowInBrowserAsync(It.IsAny <Uri>(), It.IsAny <bool>()),
                           Times.Never);
            dialog.Verify(d => d.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()),
                          Times.Never);
        }
コード例 #2
0
        public async Task ShouldAskUserToOpenExternalLinks()
        {
            var    dialog = Dialog;
            string msg    = null;

            dialog.Setup(d => d.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback((string title, string text, string pB, string nB) => msg = text)
            .ReturnsAsync(true)
            .Verifiable();

            var sut = new StoryViewModel(Share.Object, Browser.Object, dialog.Object);

            var fakeUrl = "https://kipters.net";
            await sut.HandleExternalLinkAsync(fakeUrl);

            dialog.Verify();
            Assert.Contains("kipters.net", msg);
        }
コード例 #3
0
        public async Task ShouldOpenExternalLinksInInternalBrowserIfUserAllows()
        {
            var fakeUrl = "https://kipters.net";

            var dialog = Dialog;

            dialog.Setup(d => d.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true);

            var browser = Browser;

            browser.Setup(b => b.ShowInBrowserAsync(new Uri(fakeUrl), true))
            .ReturnsAsync(true)
            .Verifiable();

            var sut = new StoryViewModel(Share.Object, browser.Object, dialog.Object);

            await sut.HandleExternalLinkAsync(fakeUrl);

            browser.Verify();
        }
コード例 #4
0
        public async Task ShouldNotOpenExternalLinksIfUserDenies()
        {
            var fakeUrl = "https://kipters.net";

            var dialog = Dialog;

            dialog.Setup(d => d.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(false);

            var browser = Browser;

            browser.Setup(b => b.ShowInBrowserAsync(It.IsAny <Uri>(), It.IsAny <bool>()))
            .ReturnsAsync(true)
            .Verifiable();

            var sut = new StoryViewModel(Share.Object, Browser.Object, dialog.Object);

            await sut.HandleExternalLinkAsync(fakeUrl);

            browser.Verify(b => b.ShowInBrowserAsync(It.IsAny <Uri>(), It.IsAny <bool>()),
                           Times.Never);
        }