예제 #1
0
        public void WhenNotSelectedButtonsOnDisplayActionSheetRequested()
        {
            var commandExecutorMock = new Mock <ICommandExecutor>();

            var request  = new DisplayActionSheetRequest();
            var behavior = new DisplayActionSheetBehavior()
            {
                CommandExecutor     = commandExecutorMock.Object,
                NotificationRequest = request,
            };

            var actionSheetButtonMockA = new Mock <IActionSheetButton>();

            actionSheetButtonMockA.SetupGet(x => x.Message).Returns(() => "actionSheetButtonMockA");
            behavior.ActionSheetButtons.Add(actionSheetButtonMockA.Object);

            var actionSheetButtonMockB = new Mock <IActionSheetButton>();

            actionSheetButtonMockB.SetupGet(x => x.Message).Returns(() => "actionSheetButtonMockB");
            behavior.ActionSheetButtons.Add(actionSheetButtonMockB.Object);

            var page = new PageMock();

            page.Behaviors.Add(behavior);
            MessagingCenter.Subscribe <Page, ActionSheetArguments>(this, Page.ActionSheetSignalName, (page1, arguments) =>
            {
                if (arguments.Title == "WhenNotSelectedButtonsOnDisplayActionSheetRequested")
                {
                    Assert.Equal("ReplacedCancel", arguments.Cancel);
                    Assert.Equal("ReplacedDestruction", arguments.Destruction);
                    Assert.Equal(2, arguments.Buttons.Count());
                    Assert.Equal("actionSheetButtonActionA", arguments.Buttons.ToArray()[0]);
                    Assert.Equal("actionSheetButtonActionB", arguments.Buttons.ToArray()[1]);
                    arguments.SetResult(null);
                }
            });

            bool   calledActionSheetButtonActionCancel      = false;
            bool   calledActionSheetButtonActionDestruction = false;
            bool   calledActionSheetButtonActionA           = false;
            bool   calledActionSheetButtonActionB           = false;
            string param = null;
            var    actionSheetButtonActionCancel = new ActionSheetButton {
                Message = "ReplacedCancel", Action = () => { calledActionSheetButtonActionCancel = true; }
            };
            var actionSheetButtonActionDestruction = new ActionSheetButton {
                Message = "ReplacedDestruction", Action = () => { calledActionSheetButtonActionDestruction = true; }
            };
            var actionSheetButtonActionA = new ActionSheetButton {
                Message = "actionSheetButtonActionA", Action = () => { calledActionSheetButtonActionA = true; }
            };
            var actionSheetButtonActionB = new ActionSheetButton {
                Message = "actionSheetButtonActionB", Action = () => { calledActionSheetButtonActionB = true; }
            };

            request.Raise("WhenNotSelectedButtonsOnDisplayActionSheetRequested", actionSheetButtonActionCancel, actionSheetButtonActionDestruction, actionSheetButtonActionA, actionSheetButtonActionB);

            page.RiseTestEvent(this, EventArgs.Empty);

            commandExecutorMock.Verify(
                commandExecutor => commandExecutor.Execute(
                    It.IsAny <ICommand>(),
                    It.IsAny <object>(),
                    It.IsAny <EventArgs>(),
                    It.IsAny <IValueConverter>(),
                    It.IsAny <object>(),
                    It.IsAny <string>()),
                Times.Never);

            Assert.False(calledActionSheetButtonActionCancel);
            Assert.False(calledActionSheetButtonActionDestruction);
            Assert.False(calledActionSheetButtonActionA);
            Assert.False(calledActionSheetButtonActionB);
        }
예제 #2
0
        public void WhenSelectedDestructionOnEventRaised()
        {
            var commandExecutorMock = new Mock <ICommandExecutor>();

            var cancelCommand                     = new Mock <ICommand>().Object;
            var cancelCommandParameter            = new object();
            var cancelEventArgsConverter          = new Mock <IValueConverter>().Object;
            var cancelEventArgsConverterParameter = new object();
            var cancelEventArgsPropertyPath       = "cancelEventArgsPropertyPath";

            var destructionCommand                     = new Mock <ICommand>().Object;
            var destructionCommandParameter            = new object();
            var destructionEventArgsConverter          = new Mock <IValueConverter>().Object;
            var destructionEventArgsConverterParameter = new object();
            var destructionEventArgsPropertyPath       = "destructionEventArgsPropertyPath";

            var behavior = new DisplayActionSheetBehavior()
            {
                CommandExecutor                        = commandExecutorMock.Object,
                EventName                              = "TestEvent",
                Title                                  = "WhenSelectedDestructionOnEventRaised",
                Cancel                                 = "Cancel",
                CancelCommand                          = cancelCommand,
                CancelCommandParameter                 = cancelCommandParameter,
                CancelEventArgsConverter               = cancelEventArgsConverter,
                CancelEventArgsConverterParameter      = cancelEventArgsConverterParameter,
                CancelEventArgsPropertyPath            = cancelEventArgsPropertyPath,
                Destruction                            = "Destruction",
                DestructionCommand                     = destructionCommand,
                DestructionCommandParameter            = destructionCommandParameter,
                DestructionEventArgsConverter          = destructionEventArgsConverter,
                DestructionEventArgsConverterParameter = destructionEventArgsConverterParameter,
                DestructionEventArgsPropertyPath       = destructionEventArgsPropertyPath,
            };

            var actionSheetButtonMockA = new Mock <IActionSheetButton>();

            actionSheetButtonMockA.SetupGet(x => x.Message).Returns(() => "actionSheetButtonMockA");
            behavior.ActionSheetButtons.Add(actionSheetButtonMockA.Object);

            var actionSheetButtonMockB = new Mock <IActionSheetButton>();

            actionSheetButtonMockB.SetupGet(x => x.Message).Returns(() => "actionSheetButtonMockB");
            behavior.ActionSheetButtons.Add(actionSheetButtonMockB.Object);

            var page = new PageMock();

            page.Behaviors.Add(behavior);
            MessagingCenter.Subscribe <Page, ActionSheetArguments>(this, Page.ActionSheetSignalName, (page1, arguments) =>
            {
                if (arguments.Title == "WhenSelectedDestructionOnEventRaised")
                {
                    Assert.Equal("Cancel", arguments.Cancel);
                    Assert.Equal("Destruction", arguments.Destruction);
                    Assert.Equal(2, arguments.Buttons.Count());
                    Assert.Equal("actionSheetButtonMockA", arguments.Buttons.ToArray()[0]);
                    Assert.Equal("actionSheetButtonMockB", arguments.Buttons.ToArray()[1]);
                    arguments.SetResult(arguments.Destruction);
                }
            });

            page.RiseTestEvent(this, EventArgs.Empty);

            commandExecutorMock.Verify(
                commandExecutor => commandExecutor.Execute(
                    destructionCommand,
                    destructionCommandParameter,
                    EventArgs.Empty,
                    destructionEventArgsConverter,
                    destructionEventArgsConverterParameter,
                    destructionEventArgsPropertyPath),
                Times.Once);
        }
        public void WhenSelectAcceptOfConfirmDialog()
        {
            var commandExecutorMock               = new Mock <ICommandExecutor>();
            var acceptCommand                     = new Mock <ICommand>().Object;
            var acceptCommandParameter            = new object();
            var acceptEventArgsConverter          = new Mock <IValueConverter>().Object;
            var acceptEventArgsConverterParameter = new object();
            var acceptEventArgsPropertyPath       = "acceptEventArgsPropertyPath";

            var cancelCommand                     = new Mock <ICommand>().Object;
            var cancelCommandParameter            = new object();
            var cancelEventArgsConverter          = new Mock <IValueConverter>().Object;
            var cancelEventArgsConverterParameter = new object();
            var cancelEventArgsPropertyPath       = "cancelEventArgsPropertyPath";

            var behavior = new DisplayAlertBehavior
            {
                CommandExecutor                   = commandExecutorMock.Object,
                EventName                         = "TestEvent",
                Title                             = "WhenSelectAcceptOfConfirmDialog",
                Message                           = "Message",
                Accept                            = "Accept",
                Cancel                            = "Cancel",
                AcceptCommand                     = acceptCommand,
                AcceptCommandParameter            = acceptCommandParameter,
                AcceptEventArgsConverter          = acceptEventArgsConverter,
                AcceptEventArgsConverterParameter = acceptEventArgsConverterParameter,
                AcceptEventArgsPropertyPath       = acceptEventArgsPropertyPath,
                CancelCommand                     = cancelCommand,
                CancelCommandParameter            = cancelCommandParameter,
                CancelEventArgsConverter          = cancelEventArgsConverter,
                CancelEventArgsConverterParameter = cancelEventArgsConverterParameter,
                CancelEventArgsPropertyPath       = cancelEventArgsPropertyPath
            };
            var page = new PageMock();

            page.Behaviors.Add(behavior);

            MessagingCenter.Subscribe <Page, AlertArguments>(this, Page.AlertSignalName, (page1, arguments) =>
            {
                if (arguments.Title == "WhenSelectAcceptOfConfirmDialog")
                {
                    Assert.Equal("Message", arguments.Message);
                    Assert.Equal("Accept", arguments.Accept);
                    Assert.Equal("Cancel", arguments.Cancel);
                    arguments.SetResult(true);
                }
            });

            page.RiseTestEvent(this, EventArgs.Empty);

            commandExecutorMock.Verify(
                commandExecutor => commandExecutor.Execute(
                    acceptCommand,
                    acceptCommandParameter,
                    EventArgs.Empty,
                    acceptEventArgsConverter,
                    acceptEventArgsConverterParameter,
                    acceptEventArgsPropertyPath),
                Times.Once);
        }