Ejemplo n.º 1
0
        public void ExportCommand()
        {
            // arrange
            var exportUtility = new ExportUtility();

            var exportViewModel = new ExportOptionsViewModel();
            exportUtility.TheExportOptionsViewModel = new Lazy<ExportOptionsViewModel>(() => exportViewModel);

            var systemOptionsInfo = Mock.Create<ISystemOptionsInfo>(Behavior.Loose);
            Mock.Arrange(() => systemOptionsInfo.RestrictExportTo).Returns(10000);
            Mock.Arrange(() => SystemOptionsInfo.SystemOptions).Returns(systemOptionsInfo);

            Mock.Arrange(() => Utils.CurrentUserHasAdministratorRights).Returns(true);

            var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose);
            var popupBuilder = new PopupBuilder();
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => ok());
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);

            exportUtility.ThePopupFactory = new Lazy<PopupFactory>(() => popupFactory);

            Mock.Arrange(() => Arg.IsAny<SaveFileDialog>().ShowDialog()).Returns(true);

            var called = false;
            Action onAgreedToSaveFile = () => { called = true; };
            
            // act
            exportUtility.ExportSetup(PageOrientation.Portrait, 1000, onAgreedToSaveFile );

            // assert
            Assert.IsTrue(called); // Important. This method must be called to download the full list of info objects, together with Applied Filter, if this filter exists
            Assert.AreEqual(PageOrientation.Portrait, exportViewModel.PageOrientation);

            // act
            exportUtility.ExportSetup(PageOrientation.Landscape, 1000, onAgreedToSaveFile);

            // assert
            Assert.AreEqual(PageOrientation.Landscape, exportViewModel.PageOrientation);

            // arrange
            called = false;
            Mock.Arrange(() => Arg.IsAny<SaveFileDialog>().ShowDialog()).Returns(false);

            // act
            exportUtility.ExportSetup(PageOrientation.Landscape, 1000, onAgreedToSaveFile);

            // assert
            Assert.IsFalse(called);
        }
Ejemplo n.º 2
0
        public void ShowImageCommand()
        {
            // arrange
            var vm = new ImageFieldViewModel
                {
                    Value = new byte[] {1, 2, 3}
                };

            var imageViewerViewModel = Mock.Create<IImageViewerViewModel>(Behavior.Loose);

            vm.TheImageViewerFactory = new ExportFactory<IImageViewerViewModel>(() => new Tuple<IImageViewerViewModel, Action>(imageViewerViewModel, null));

            var okCalled = false;
            var popupFactory = Mock.Create<PopupFactory>();
            var popupBuilder = new PopupBuilder();
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) =>
                {
                    ok();
                    okCalled = true;
                });
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);

            vm.ThePopupFactory = popupFactory;

            // act
            vm.ShowImageCommand.Execute(null);

            // assert
            CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, (ICollection)imageViewerViewModel.Image);
            Assert.IsTrue(okCalled);
        }
Ejemplo n.º 3
0
        public void Prevent_ExecutePublish_IfAny()
        {
            var vm = new ProcessEditViewModel();

            var cs = new Lazy<ICommunicationService>();
            var val = new CommunicationService();
            Mock.Arrange(() => cs.Value).Returns(val);
            Mock.Arrange(() => vm.CommunicationService).Returns(cs);

            Mock.Arrange(() => vm.CommunicationService.Value.IsPublishingInProgress).Returns(false);

            var popupFactory = new PopupFactory();
            var popupBuilder = new PopupBuilder();
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => { });
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);
            vm.ThePopupFactory = new Lazy<PopupFactory>(() => popupFactory);

            var pvm = new Lazy<PublishViewModel>();
            Mock.Arrange(() => vm.PublishVM).Returns(pvm);

            var prevented = false;
            Mock.Arrange(() => popupBuilder.Message(LanguageService.Translate("Label_PublishingIsInProgress"))).DoInstead(() => prevented = true).Returns(popupBuilder);

            var model = Mock.Create<ProcessEdit>();
            Mock.Arrange(() => vm.Model).Returns(model);
            Mock.Arrange(() => vm.Model.IsValid).Returns(true);
            Mock.Arrange(() => vm.Model.IsDirty).Returns(false);
            Mock.Arrange(() => vm.Model.IsInactive).Returns(false);
            Mock.Arrange(() => Utils.CurrentUserIsReadOnly).Returns(false);

            vm.PublishCommand.Execute(null);
            Assert.IsFalse(prevented);

            Mock.Arrange(() => vm.CommunicationService.Value.IsPublishingInProgress).Returns(true);
            vm.PublishCommand.Execute(null);
            Assert.IsTrue(prevented);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Initializes a new instance of the <see cref="CommandWrapper"/> class.
            /// </summary>
            /// <param name="popup">The popup.</param>
            /// <param name="command">The command.</param>
            public CommandWrapper(PopupBuilder popup, ITitledCommand command)
            {
                _popup = popup;
                _titledCommand = command;

                if (_titledCommand.Command == null)
                    return;

                var weakListener = new WeakEventListener<CommandWrapper, ICommand, EventArgs>(this, _titledCommand.Command);

                _titledCommand.Command.CanExecuteChanged += weakListener.OnEvent;
                weakListener.OnEventAction += OnCommandCanExecuteChanged;
                weakListener.OnDetachAction += Static;
            }
Ejemplo n.º 5
0
        public void ImpersonateCommand_Execute_Tests()
        {
            // arrange
            var vm = NewAccountListViewModel();

            Mock.NonPublic.Arrange<bool>(vm, "IsAdmin", new object[] { ArgExpr.IsNull<object>() }).Returns(true);

            var accountInfo = Mock.Create<IAccountInfo>(Behavior.CallOriginal);
            Mock.Arrange(() => accountInfo.Id).Returns(1);

            vm.SelectedItem = accountInfo;

            Mock.Arrange(() => MQ1Principal.BeginImpersonate(1, Arg.IsAny<Action<string>>()))
                .DoInstead<int, Action<string>>((id, callback) => callback(null));

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

            var eventWasExecuted = false;
            Mock.Arrange(() => eventAggregator.Publish(Arg.IsAny<AuthenticationEvent>())).DoInstead(() => eventWasExecuted = true);
            vm.EventAggregator = eventAggregator;

            // act
            vm.ImpersonateCommand.Execute(null);

            // assert
            Assert.IsTrue(eventWasExecuted);

            // arrange
            eventWasExecuted = false;

            Mock.Arrange(() => MQ1Principal.BeginImpersonate(1, Arg.IsAny<Action<string>>()))
                .DoInstead<int, Action<string>>((id, callback) => callback(new Exception().ToString()));

            var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose);
            var popupBuilder = new PopupBuilder();
            var popupWasShowed = false;
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead(() => popupWasShowed = true);
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);

            vm.ThePopupFactory = new Lazy<PopupFactory>(() => popupFactory);

            var logger = Mock.Create<ILogger>(Behavior.CallOriginal);
            var wasLogged = false;
            Mock.Arrange(() => logger.Log(LogSeverity.Information, typeof(AccountListViewModel).ToString(), new Exception().ToString()))
                .DoInstead(() => wasLogged = true);

            vm.Logger = logger;

            // act
            vm.ImpersonateCommand.Execute(null);

            // assert
            Assert.IsTrue(popupWasShowed);
            Assert.IsTrue(wasLogged);
            Assert.IsFalse(eventWasExecuted);

            // arrnage
            vm.SelectedItem = null;

            var beginImpersonateWasCalled = false;
            Mock.Arrange(() => MQ1Principal.BeginImpersonate(Arg.AnyInt, Arg.IsAny<Action<string>>()))
                .DoInstead(() => beginImpersonateWasCalled = false);

            // act
            vm.ImpersonateCommand.Execute(null);

            // assert
            Assert.IsFalse(beginImpersonateWasCalled);
        }
        public void SelecLayoutEvenIfNameIsEmpty()
        {
            // arraange
            var vm = new ProcessLayoutsViewModel();
            Mock.NonPublic.Arrange<bool>(vm, "CanSortOrGroupLayout", new object[] { ArgExpr.IsNull<object>() }).Returns(true);
            vm.EditLayoutVM = new Lazy<EditLayoutViewModel>();

            var model = Mock.Create<ProcessEdit>();
            model.LayoutList = new ProcessLayoutList();
            Mock.Arrange(() => vm.Model).Returns(model);
            
            var popupBuilder = new PopupBuilder();
            var popupFactory = new PopupFactory { PopupFactoryFactory = new ExportFactory<PopupBuilder>(() => new Tuple<PopupBuilder, Action>(popupBuilder, () => { })) };
            Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => ok());
            Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder);
            vm.ThePopupFactory = popupFactory;
            
            var newLayoutViewModelFactory = Mock.Create<INewLayoutViewModelFactory>();
            Mock.Arrange(() => newLayoutViewModelFactory.CreateLayoutVM(Arg.IsAny<ProcessLayoutEdit>())).Returns<ProcessLayoutEdit>((l) => new NewLayoutViewModel(l) { Name = l.Name, Id = l.Id, LayoutString = l.LayoutInfo });
            vm.TheLayoutFactory = newLayoutViewModelFactory;

            vm.LayoutAddCommand.Execute(null);
            vm.LayoutAddCommand.Execute(null);

            vm.SelectedLayout = vm.LayoutList[0];
            vm.SelectedLayout.Name = string.Empty;
            vm.SelectedLayout = vm.LayoutList[1];
            
            // act
            vm.SelectedLayout = vm.LayoutList[0];

            // assert
            Assert.IsTrue(vm.SelectedLayout.GetHashCode() == vm.LayoutList[0].GetHashCode());
        }