Exemple #1
0
        public void WhenCancelAndDestructionIsNullOnDisplayActionSheetRequested()
        {
            var commandExecutorMock = new Mock <ICommandExecutor>();

            var request  = new DisplayActionSheetRequest();
            var behavior = new DisplayActionSheetBehavior()
            {
                CommandExecutor     = commandExecutorMock.Object,
                NotificationRequest = request,
                EventName           = "TestEvent",
                Title = "WhenCancelAndDestructionIsNullOnDisplayActionSheetRequested",
            };

            var page = new PageMock();

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

            bool   calledActionSheetButtonActionA = false;
            bool   calledActionSheetButtonActionB = false;
            string param = null;
            var    actionSheetButtonActionA = new ActionSheetButton {
                Message = "actionSheetButtonActionA", Action = () => { calledActionSheetButtonActionA = true; }
            };
            var actionSheetButtonActionB = new ActionSheetButton <string>
            {
                Message   = "actionSheetButtonActionB",
                Parameter = "Param",
                Action    =
                    x =>
                {
                    calledActionSheetButtonActionB = true;
                    param = x;
                }
            };

            request.Raise("WhenCancelAndDestructionIsNullOnDisplayActionSheetRequested", null, null, actionSheetButtonActionA, actionSheetButtonActionB);

            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(calledActionSheetButtonActionA);
            Assert.True(calledActionSheetButtonActionB);
            Assert.Equal("Param", param);
        }
Exemple #2
0
        public void WhenSelectedActionSheetButtonOnDisplayActionSheetRequested()
        {
            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 request  = new DisplayActionSheetRequest();
            var behavior = new DisplayActionSheetBehavior()
            {
                CommandExecutor     = commandExecutorMock.Object,
                NotificationRequest = request,
                Title                                  = "WhenSelectedActionSheetButtonOnDisplayActionSheetRequested",
                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 == "ReplacedWhenSelectedActionSheetButtonOnDisplayActionSheetRequested")
                {
                    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("actionSheetButtonActionB");
                }
            });

            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 <string>
            {
                Message   = "actionSheetButtonActionB",
                Parameter = "Param",
                Action    =
                    x =>
                {
                    calledActionSheetButtonActionB = true;
                    param = x;
                }
            };

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

            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);
            actionSheetButtonMockA.Verify(x => x.OnClicked(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Never);
            actionSheetButtonMockB.Verify(x => x.OnClicked(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Never);
            Assert.False(calledActionSheetButtonActionCancel);
            Assert.False(calledActionSheetButtonActionDestruction);
            Assert.False(calledActionSheetButtonActionA);
            Assert.True(calledActionSheetButtonActionB);
            Assert.Equal("Param", param);
        }
Exemple #3
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);
        }
Exemple #4
0
        private void TestMethod()
        {
            DisplayActionSheetRequest dp = new DisplayActionSheetRequest();

            dp.Raise("Worked");
        }