Exemplo n.º 1
0
    public void DisplayInputDialogCommand_OnExecute_CallsDoSomethingWhenDialogConfirmed()
    {
        // Arrange
        Mock <IService> mockService = new Mock <IService>();
        IDelegateWorker worker      = new DelegateWorker();
        MyViewModel     vm          = new MyViewModel(mockService.Object, worker);

        vm.InputDialogInteractionRequest.Raised += (s, e) =>
        {
            Confirmation context = e.Context as Confirmation;
            ((Confirmation)context).Confirmed = true;
            e.Callback();
        };
        // Act
        vm.DisplayInputDialogCommand.Execute(null);
        // Assert
        mockService.Verify(s => s.DoSomething(), Times.Once());
    }
Exemplo n.º 2
0
    public void DisplayInputDialogCommand_OnExecute_ClearsIsBusyWhenDone()
    {
        // Arrange
        Mock <IService> mockService = new Mock <IService>();
        IDelegateWorker worker      = new DelegateWorker();
        MyViewModel     vm          = new MyViewModel(mockService.Object, worker);

        vm.InputDialogInteractionRequest.Raised += (s, e) =>
        {
            Confirmation context = e.Context as Confirmation;
            ((Confirmation)context).Confirmed = true;
            e.Callback();
        };
        // Act
        vm.DisplayInputDialogCommand.Execute(null);
        // Assert
        Assert.IsFalse(vm.IsBusy);
    }
Exemplo n.º 3
0
    public void DisplayInputDialogCommand_OnExecuteThrowsError_ShowsErrorDialog()
    {
        // Arrange
        Mock <IService> mockService = new Mock <IService>();

        mockService.Setup(s => s.DoSomething()).Throws(new Exception());
        DelegateWorker worker = new DelegateWorker();
        MyViewModel    vm     = new MyViewModel(mockService.Object, worker);

        vm.InputDialogInteractionRequest.Raised += (s, e) =>
        {
            Confirmation context = e.Context as Confirmation;
            ((Confirmation)context).Confirmed = true;
            e.Callback();
        };
        InteractionRequestTestHelper <Notification> irHelper
            = new InteractionRequestTestHelper <Notification>(vm.ErrorDialogInteractionRequest);

        // Act
        vm.DisplayInputDialogCommand.Execute(null);
        // Assert
        Assert.IsTrue(irHelper.RequestRaised);
    }
Exemplo n.º 4
0
    public void DisplayInputDialogCommand_OnExecuteThrowsError_ShowsErrorDialogWithCorrectErrorMessage()
    {
        // Arrange
        const string    ERROR_MESSAGE_TEXT = "do something failed";
        Mock <IService> mockService        = new Mock <IService>();

        mockService.Setup(s => s.DoSomething()).Throws(new Exception(ERROR_MESSAGE_TEXT));
        DelegateWorker worker = new DelegateWorker();
        MyViewModel    vm     = new MyViewModel(mockService.Object, worker);

        vm.InputDialogInteractionRequest.Raised += (s, e) =>
        {
            Confirmation context = e.Context as Confirmation;
            ((Confirmation)context).Confirmed = true;
            e.Callback();
        };
        InteractionRequestTestHelper <Notification> irHelper
            = new InteractionRequestTestHelper <Notification>(vm.ErrorDialogInteractionRequest);

        // Act
        vm.DisplayInputDialogCommand.Execute(null);
        // Assert
        Assert.AreEqual((string)irHelper.Content, ERROR_MESSAGE_TEXT);
    }