/// <summary>
        /// Initializes a new instance of the <see cref="WebMethodCallParameterViewModel"/> class.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="baseType">
        /// The base type.
        /// </param>
        /// <param name="parentViewModel">
        /// The parent view model.
        /// </param>
        /// <param name="parameterViewModelFactory">
        /// The parameter view model factory.
        /// </param>
        /// <param name="popupFactory">
        /// The popup factory.
        /// </param>
        public WebMethodCallParameterViewModel(
            IWebMethodCallParameter model,
            IWebServiceTypeDescription baseType,
            IWebMethodCallSettingsViewModel parentViewModel,
            IWebMethodCallParameterViewModelFactory parameterViewModelFactory,
            PopupFactory popupFactory)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (baseType == null)
                throw new ArgumentNullException("baseType");

            if (parentViewModel == null)
                throw new ArgumentNullException("parentViewModel");

            if (parameterViewModelFactory == null)
                throw new ArgumentNullException("parameterViewModelFactory");

            if (popupFactory == null)
                throw new ArgumentNullException("popupFactory");

            ParentViewModel = parentViewModel;
            ParameterViewModelFactory = parameterViewModelFactory;
            PopupFactory = popupFactory;
            RefreshInternal(model, baseType);
        }
Пример #2
0
        public void StartExport()
        {
            // arrange
            var exportUtility = new ExportUtility();

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

            var shell = Mock.Create<IShell>(Behavior.Loose);
            exportUtility.TheWindowManager = new Lazy<IShell>(() => shell);

            var dynamicTypeManager = Mock.Create<IDynamicTypeManager>(Behavior.Loose);
            exportUtility.TheDynamicTypeManager = new Lazy<IDynamicTypeManager>(() => dynamicTypeManager);

            Mock.Arrange(() => Utils.CurrentUserAccountId).Returns(-1);

            var beginInsertEmailLogWasCalled = false;
            Mock.Arrange(() => MethodCaller.CallFactoryMethod(Arg.IsAny<Type>(), Arg.AnyString, Arg.IsAny<object[]>())).DoInstead(() => beginInsertEmailLogWasCalled = true);

            var popupFactory = new PopupFactory();

            var notifySuccessCalled = false;
            Mock.Arrange(() => popupFactory.NotifySuccess(LanguageService.Translate("Msg_ProcessExported"), "Popup_Success")).DoInstead(() => notifySuccessCalled = true);

            var notifyFailureCalled = false;
            Mock.Arrange(() => popupFactory.NotifyFailure(LanguageService.Translate("Msg_ExportError"), "Popup_Error", 3, false)).DoInstead(() => notifyFailureCalled = true);

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

            var exportMethodWasCalled = false;
            Mock.NonPublic.Arrange<bool>(exportUtility, "Export", new object[] { ArgExpr.IsAny<GridViewDataControl>(), ArgExpr.IsAny<string>() }).DoInstead(() => exportMethodWasCalled = true).Returns(true);

            // act
            exportUtility.ExportStart("eCar_p", new GridViewDataControl(), "Id|CurrentState");

            // assert
            Assert.IsTrue(beginInsertEmailLogWasCalled);
            Assert.IsTrue(notifySuccessCalled);
            Assert.IsFalse(notifyFailureCalled);
            Assert.IsTrue(exportMethodWasCalled); // After exporting, we have to return it as it was, that is, back 25 info items

            // arrange
            notifySuccessCalled = notifyFailureCalled = false;
            Mock.NonPublic.Arrange<bool>(exportUtility, "Export", new object[] { ArgExpr.IsAny<GridViewDataControl>(), ArgExpr.IsAny<string>() }).Returns(false);

            // act
            exportUtility.ExportStart("eCar_p", new GridViewDataControl(), "Id|CurrentState");

            // assert
            Assert.IsFalse(notifySuccessCalled);
            Assert.IsTrue(notifyFailureCalled);
        }
Пример #3
0
        public void OnImageFailed()
        {
            // arrange
            var vm = new ImageFieldViewModel();
            var exception = Mock.Create<ExceptionRoutedEventArgs>(Behavior.CallOriginal);

            var popupFactory = new PopupFactory();
            var notifyFailureCalled = false;
            Mock.Arrange(() => popupFactory.NotifyFailure(Arg.IsAny<Exception>(), "Popup_Error", false)).DoInstead(() => notifyFailureCalled = true);

            vm.ThePopupFactory = popupFactory;

            // act
            new PrivateAccessor(vm).CallMethod("OnImageFailed", new object[] { null, exception });

            // assert
            Assert.IsTrue(notifyFailureCalled);
        }
Пример #4
0
        public void DownloadImageCommand()
        {
            // arrange
            var vm = new ImageFieldViewModel();

            var saveFileDialog = Mock.Create<SaveFileDialog>(Behavior.CallOriginal);
            Mock.Arrange(() => saveFileDialog.ShowDialog()).Returns(false);

            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_saveFileDialog", saveFileDialog);

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

            var editableRoot = Mock.Create<IEditableRoot>(Behavior.Loose);
            Mock.Arrange(() => editableRoot.ProcessName).Returns("eCar_p");
            Mock.Arrange(() => editableRoot.Id).Returns(1);

            Mock.Arrange(() => vm.ParentModel).Returns(editableRoot);

            Mock.Arrange(() => vm.Property).Returns(GetType().GetProperty("Image2"));

            // act
            try
            {
                vm.DownloadImageCommand.Execute(null);
            }
            catch(Exception ex)
            {
                // assert
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }

            // arrange
            Mock.Arrange(() => saveFileDialog.ShowDialog()).Returns(true);

            Mock.Arrange(() => saveFileDialog.OpenFile()).Returns(new MemoryStream());

            var array = new byte[8 * 1024 + 1];
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = new byte();
            }

            vm.Value = array;

            var popupFactory = new PopupFactory();
            var notifySuccessCalled = false;
            Mock.Arrange(() => popupFactory.NotifySuccess(LanguageService.Translate("Msg_SuccessfullySaved"), "Popup_Success")).DoInstead(() => notifySuccessCalled = true);

            vm.ThePopupFactory = popupFactory;

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

            // assert
            Assert.IsTrue(notifySuccessCalled);
            Assert.IsNull(privateAccessor.GetField("_saveFileDialog"));
        }
Пример #5
0
        public void UploadImageCommand()
        {
            // arrange
            var vm = new ImageFieldViewModel();

            var openFileDialog = Mock.Create<OpenFileDialog>(Behavior.CallOriginal);
            Mock.Arrange(() => openFileDialog.ShowDialog()).Returns(false);

            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_openFileDialog", openFileDialog);

            try
            {
                // act
                vm.UploadImageCommand.Execute(null);
            }
            catch (Exception ex)
            {
                // assert
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }

            // arrange
            Mock.Arrange(() => openFileDialog.ShowDialog()).Returns(true);

            var file = Mock.Create<FileInfo>(Behavior.CallOriginal);
            Mock.Arrange(() => file.Length).Returns(8 * 1024);
            Mock.Arrange(() => openFileDialog.File).Returns(file);

            var popupFactory = new PopupFactory();
            var notifyFailureCalled = false;
            Mock.Arrange(() => popupFactory.NotifyFailure(Arg.AnyString, "Popup_Error", 3, false)).DoInstead(() => notifyFailureCalled = true);

            vm.ThePopupFactory = popupFactory;

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

            // assert
            Assert.IsTrue(notifyFailureCalled);

            // arrange
            Mock.NonPublic.Arrange<ulong>(vm, "MaxFileSize").Returns((ulong)file.Length + 1);

            var fileStream = Mock.Create<FileStream>(Behavior.Loose);

            var exit = false;
            Mock.Arrange(() => fileStream.Read(Arg.IsAny<byte[]>(), 0, Arg.AnyInt)).Returns(() =>
                    {
                        if (!exit)
                        {
                            exit = true;
                            return 1;
                        }

                        return 0;
                    });

            Mock.Arrange(() => file.OpenRead()).Returns(fileStream);

            var imageVisibilityRaises = false;
            Mock.NonPublic.Arrange(vm, "RaisePropertyChanged", ArgExpr.IsAny<Expression<Func<bool>>>()).DoInstead(() => imageVisibilityRaises = true);

            var downloadImageCommandRaises = false;
            Mock.Arrange(() => vm.DownloadImageCommand.RaiseCanExecuteChanged()).DoInstead(() => downloadImageCommandRaises = true);

            var clearImageCommandRaises = false;
            Mock.Arrange(() => vm.ClearImageCommand.RaiseCanExecuteChanged()).DoInstead(() => clearImageCommandRaises = true);

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

            // assert
            Assert.AreEqual(8 * 1024, ((byte[])vm.Value).Length);
            Assert.IsTrue(imageVisibilityRaises);
            Assert.IsTrue(downloadImageCommandRaises);
            Assert.IsTrue(clearImageCommandRaises);
            Assert.IsNull(privateAccessor.GetField("_openFileDialog"));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WebMethodCallResultViewModel"/> class.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="field">
        /// The field.
        /// </param>
        /// <param name="parentNode">
        /// The parent node.
        /// </param>
        /// <param name="popupFactory">
        /// The popup factory.
        /// </param>
        /// <param name="selectChildTypeFieldsViewModel">
        /// The select child type fields view model.
        /// </param>
        /// <param name="resultViewModelFactory">
        /// The result view model factory.
        /// </param>
        /// <param name="resultFieldFactory">
        /// The result field factory.
        /// </param>
        public WebMethodCallResultViewModel(
            IWebMethodCallResultField model,
            IWebServiceTypeFieldDescription field,
            IWebMethodCallResultViewModel parentNode,
            PopupFactory popupFactory,
            ISelectChildTypeFieldsViewModel selectChildTypeFieldsViewModel,
            IWebMethodCallResultViewModelFactory resultViewModelFactory,
            IWebMethodCallResultFieldFactory resultFieldFactory)
        {
            if (field == null)
                throw new ArgumentNullException("field");

            if (parentNode == null)
                throw new ArgumentNullException("parentNode");

            if (popupFactory == null)
                throw new ArgumentNullException("popupFactory");

            if (selectChildTypeFieldsViewModel == null)
                throw new ArgumentNullException("selectChildTypeFieldsViewModel");

            if (resultViewModelFactory == null)
                throw new ArgumentNullException("resultViewModelFactory");

            if (resultFieldFactory == null)
                throw new ArgumentNullException("resultFieldFactory");

            _model = model;
            _name = field.Name;
            _baseType = field.FieldType;
            _declaringType = field.DeclaringType;
            _parentNode = parentNode;
            PopupFactory = popupFactory;
            SelectChildTypeFieldsViewModel = selectChildTypeFieldsViewModel;
            ResultViewModelFactory = resultViewModelFactory;
            ResultFieldFactory = resultFieldFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WebMethodCallResultViewModel"/> class.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="parentSettings">
        /// The parent settings.
        /// </param>
        /// <param name="popupFactory">
        /// The popup factory.
        /// </param>
        /// <param name="selectChildTypeFieldsViewModel">
        /// The select child type fields view model.
        /// </param>
        /// <param name="resultViewModelFactory">
        /// The result view model factory.
        /// </param>
        /// <param name="resultFieldFactory">
        /// The result field factory.
        /// </param>
        public WebMethodCallResultViewModel(
            IWebMethodCallResultField model,
            IWebServiceMethodParameterDescription parameter,
            IWebMethodCallSettingsViewModel parentSettings,
            PopupFactory popupFactory,
            ISelectChildTypeFieldsViewModel selectChildTypeFieldsViewModel,
            IWebMethodCallResultViewModelFactory resultViewModelFactory,
            IWebMethodCallResultFieldFactory resultFieldFactory)
        {
            if (parameter == null)
                throw new ArgumentNullException("parameter");

            if (parentSettings == null)
                throw new ArgumentNullException("parentSettings");

            if (popupFactory == null)
                throw new ArgumentNullException("popupFactory");

            if (selectChildTypeFieldsViewModel == null)
                throw new ArgumentNullException("selectChildTypeFieldsViewModel");

            if (resultViewModelFactory == null)
                throw new ArgumentNullException("resultViewModelFactory");

            if (resultFieldFactory == null)
                throw new ArgumentNullException("resultFieldFactory");

            _model = model;
            _name = parameter.Name;
            _baseType = parameter.ParameterType;
            _parentSettings = parentSettings;
            PopupFactory = popupFactory;
            SelectChildTypeFieldsViewModel = selectChildTypeFieldsViewModel;
            ResultViewModelFactory = resultViewModelFactory;
            ResultFieldFactory = resultFieldFactory;
        }
Пример #8
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);
        }
        public void ExportDataGrid()
        {
            // arrange
            var vm = new ProcessSearchGridGadgetGridTabViewModel
                {
                    ExportGridControl = new GridViewDataControl()
                };

            var exportUtility = new ExportUtility();
            Mock.Arrange(() => exportUtility.ExportRecordCount).Returns(int.MaxValue);

            Mock.Arrange(() => exportUtility.ExportSetup(null, Arg.IsAny<int>(), Arg.IsAny<Action>()))
                .DoInstead<object, int, Action>((orientation, totalRowCount, action) => action());

            vm.TheExportUtility = new Lazy<ExportUtility>(() => exportUtility);

            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_currentPageNumber", 10);
            privateAccessor.SetField("_pageSize", 25);

            var called = false;
            Mock.Arrange(() => vm.RefreshView()).DoInstead(() => called = true);

            // act
            vm.ExportDataGrid();

            // assert
            Assert.IsTrue(called);

            Assert.AreEqual(10, privateAccessor.GetField("_tempCurrentPageNumber"));
            Assert.AreEqual(25, privateAccessor.GetField("_tempPageSize"));

            Assert.AreEqual(0, privateAccessor.GetField("_currentPageNumber"));
            Assert.AreEqual(int.MaxValue, privateAccessor.GetField("_pageSize"));

            // arrange
            called = false;
            vm.ExportGridControl = null;
            
            var popupFactory = new PopupFactory();

            var notifyFailureCalled = false;
            Mock.Arrange(() => popupFactory.NotifyFailure(LanguageService.Translate("Msg_OpenGridViewBeforeExport"), "Popup_Error", 3, false)).DoInstead(() => notifyFailureCalled = true);

            vm.ThePopupFactory = popupFactory;

            // act
            vm.ExportDataGrid();
            
            // assert
            Assert.IsTrue(notifyFailureCalled);
            Assert.IsFalse(called);
        }
        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());
        }