Ejemplo n.º 1
0
        public async void IsLoadingEventShouldTriggerTwice()
        {
            // Arrange
            var triggerCount = 0;
            var loader = new Loader(new Mock<IDialogService>().Object);
            loader.LoadingChanged += (sender, args) => ++triggerCount;

            // Act
            await loader.LoadAsync(token => Task.FromResult<object>(null));

            // Assert
            Assert.AreEqual(2, triggerCount);
        }
Ejemplo n.º 2
0
        public async void CancelledTaskDoesNotShowDialog()
        {
            // Arrange
            var dialogService = new Mock<IDialogService>();
            dialogService.Setup(d => d.ShowMessageAsync(It.IsAny<string>()));

            var tcs = new TaskCompletionSource<object>();
            tcs.SetCanceled();

            var loader = new Loader(dialogService.Object);

            // Act
            await loader.LoadAsync(token => tcs.Task);

            // Assert
            dialogService.Verify(s => s.ShowMessageAsync(It.IsAny<string>()), Times.Never);
        }
Ejemplo n.º 3
0
        public async void FailedTaskShowsDialog()
        {
            // Arrange
            var dialogService = new Mock<IDialogService>();
            dialogService.Setup(d => d.ShowMessageAsync(It.IsAny<string>())).Returns(Task.FromResult<object>(null));

            const string failedMessage = "Failed";
            var tcs = new TaskCompletionSource<object>();
            tcs.SetException(new Exception(failedMessage));

            var loader = new Loader(dialogService.Object);

            // Act
            await loader.LoadAsync(token => tcs.Task);

            // Assert
            dialogService.Verify(s => s.ShowMessageAsync(failedMessage), Times.Once);
        }