Example #1
0
        public void Init()
        {
            // arrange
            var eventAggregator = Mock.Create<IEventAggregator>(Behavior.Loose);
            var vm = new EmailViewModel { EventAggregator = eventAggregator };

            // act
            vm.Init(new RootStub());

            // assert
            Assert.AreEqual("This is action name", (string)vm.ActionList[0].Name);
            Assert.AreEqual("This is action subject", (string)vm.ActionList[0].SubjectTemplate.Template);
        }
Example #2
0
        public void SelectedActionProperty()
        {
            // arrange
            const string Subject = "Test Subject";
            const string Message = "Test Message";
            const string Email1 = "*****@*****.**";
            const string Email2 = "*****@*****.**";
            const string Email3 = "*****@*****.**";
            var actionGuid = new Guid("EB8CCBA8-5903-4AB4-9CD4-192E7790B68D");

            var actionBuilder = new ApprovalActionDefinition.Builder
                                    {
                                        Guid = actionGuid,
                                        SubjectTemplate = new ActionSubjectTemplate("x"),
                                        MessageTemplate = new ActionMessageTemplate("y")
                                    };
            var selectedAction = actionBuilder.Build();
            var dynamicManagerMock = Mock.Create<IDynamicTypeManager>();
            var logger = Mock.Create<ILogger>(Behavior.Loose);
            var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose);
            var windowManager = Mock.Create<IShell>(Behavior.Loose);

            var editableRoot = new RootStub { Id = 1, ProcessName = "AnyProcessName" };

            var command = Mock.Create<IGetActionInfoCommand>(Behavior.Loose);
            var commandResult = Mock.Create<IGetActionInfoResult>(Behavior.Loose);
            Mock.Arrange(() => commandResult.Subject).Returns(Subject);
            Mock.Arrange(() => commandResult.Message).Returns(Message);
            Mock.Arrange(() => commandResult.EmailList).Returns(new[] { Email1, Email2, Email3 });
            Mock.Arrange(() => command.ExecuteAsync(actionGuid, editableRoot)).Returns(TaskHelper.FromResult(commandResult));

            var eventAggregator = Mock.Create<IEventAggregator>(Behavior.Loose);

            var vm = new EmailViewModel
                         {
                             EventAggregator = eventAggregator,
                             DynamicManager = dynamicManagerMock,
                             Logger = logger,
                             ThePopupFactory = new Lazy<PopupFactory>(() => popupFactory),
                             WindowManager = new Lazy<IShell>(() => windowManager),
                             GetActionInfoCommand = command
                         };
            vm.Init(editableRoot);

            vm.SelectedAction = selectedAction;

            // assert
            Assert.AreEqual(Subject, vm.Subject);
            Assert.AreEqual(Message, vm.HtmlContent);

            // assert getter
            Assert.AreEqual(selectedAction, vm.SelectedAction);

            Mock.Assert(() => logger.Log(LogSeverity.Error, Arg.AnyString, Arg.IsAny<Exception>()), Occurs.Never());
            Mock.Assert(() => popupFactory.NotifyFailure(Arg.IsAny<Exception>(), Arg.AnyString, Arg.AnyBool), Occurs.Never());
        }
Example #3
0
        public void SendEmailCommand()
        {
            // test 1: if possible execute the command
            // arrange
            var eventAggregator = Mock.Create<IEventAggregator>(Behavior.Loose);
            var emailSettings = Mock.Create<IEmailSettings>(Behavior.Loose);
            Mock.Arrange(() => emailSettings.CanSendFromDetails).Returns(true);
            var emailViewModel = new EmailViewModel
                                     {
                                         EventAggregator = eventAggregator,
                                         EmailSettings = emailSettings,
                                         ReceiverCarbonCopyEmail = "*****@*****.**"
                                     };

            // assert
            Assert.IsTrue(emailViewModel.SendEmailCommand.CanExecute(null));

            // test 2. command body
            // mock returns the normal, working object
            // arrange
            var emailMock = Mock.Create<ISendEmailCommand>();
            Mock.Arrange(
                () => emailMock.BeginSendEmail(Arg.IsAny<string>(), Arg.IsAny<string>(), Arg.IsAny<string>(), Arg.IsAny<string>(), Arg.IsAny<IEnumerable<EmailLinkedResource>>(), Arg.IsAny<EventHandler<DataPortalResult<SendEmailCommand>>>()))
                .DoInstead<string, string, string, string, IEnumerable<EmailLinkedResource>, EventHandler<DataPortalResult<SendEmailCommand>>>(
                    (receiver, receiverCC, subject, message, linkedResources, callback) =>
                        {
                            var result = new DataPortalResult<SendEmailCommand>(new SendEmailCommand(), null, null);
                            callback(null, result);
                        });

            emailViewModel.SendEmailCslaCommand = emailMock;

            // when close window stub setup
            var windowManager = Mock.Create<IShell>();
            emailViewModel.WindowManager = new Lazy<IShell>(() => windowManager);

            // popup stub setup
            var popupMock = Mock.Create<PopupFactory>();
            Mock.Arrange(() => popupMock.NotifySuccess(Arg.IsAny<string>(), Arg.IsAny<string>()));
            emailViewModel.ThePopupFactory = new Lazy<PopupFactory>(() => popupMock);

            // dynamic type manager stub setup
            var type = new ReflectionStub().GetType();
            var dynamicManager = Mock.Create<IDynamicTypeManager>();
            Mock.Arrange(() => dynamicManager.GetCustomType(Arg.IsAny<string>(), "AuditLogCommand", false)).Returns(type);
            emailViewModel.DynamicManager = dynamicManager;

            // editable root stub setup
            emailViewModel.Init(new RootStub());

            // act
            emailViewModel.SendEmailCommand.Execute(null);

            // assert
            Mock.Assert(() => windowManager.CloseWindow(emailViewModel), Occurs.Once());
        }