示例#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);
        }
示例#2
0
        public void ElementExporting_FooterCell()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var exportViewModel = new ExportOptionsViewModel
            {
                ExportFileType = ExportFileType.Excel

            };

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

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            Mock.Arrange(() => e.Element).Returns(ExportElement.FooterCell);

            e.Value = "1,5";

            var column = new GridViewColumn { UniqueName = "Id" };
            column.AggregateFunctions.Add(new AverageFunction{ Caption = "Min"});
            column.AggregateFunctions.Add(new AverageFunction { Caption = "Max" });
            Mock.Arrange(() => e.Context).Returns(column);

            // act
            var privateAccessor = new PrivateAccessor(exportUtility);
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual("Min 1, Max 5", e.Value);

            // arrage
            Mock.Arrange(() => e.Context).Returns((GridViewColumn)null);
            e.Value = null;

            try
            {
                // act
                privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });
            }
            catch (Exception ex)
            {
                // assert
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
示例#3
0
        public void ElementExporting_Cell()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var exportViewModel = new ExportOptionsViewModel
            {
                ExportFileType = ExportFileType.Excel
                
            };

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

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            var parameters = new GridViewHtmlVisualExportParameters();
            Mock.Arrange(() => e.VisualParameters).Returns(parameters);
            Mock.Arrange(() => e.Element).Returns(ExportElement.Cell);

            var column = new GridViewDataColumn { UniqueName = "Notes" };
            Mock.Arrange(() => e.Context).Returns(column);

            var privateAccessor = new PrivateAccessor(exportUtility);

            var accessDeniedProperties = new List<string> { "Notes" };
            privateAccessor.SetField("_accessDeniedProperties", accessDeniedProperties);

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual("<Blocked>", e.Value);
            Assert.AreEqual(Colors.Red, parameters.Foreground);

            // arrange
            accessDeniedProperties.Clear();
            e.Value = "<Rich Text>";

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(Colors.Blue, parameters.Foreground);

            // arrage
            e.Value = new byte[] { };

            exportViewModel = new ExportOptionsViewModel
            {
                RowForeground = Colors.Yellow,
                ExportFileType = ExportFileType.Excel
                
            };

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

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });
            
            // assert
            Assert.AreEqual("binary data", e.Value);
            Assert.AreEqual(Colors.Yellow, parameters.Foreground);
        }
示例#4
0
        public void ElementExporting_FooterRow_GroupFooterRow()
        {
            // arrange
            var exportUtility = new ExportUtility();

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            var papameters = new GridViewHtmlVisualExportParameters();
            Mock.Arrange(() => e.VisualParameters).Returns(papameters);
            Mock.Arrange(() => e.Element).Returns(ExportElement.FooterRow);

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

            var privateAccessor = new PrivateAccessor(exportUtility);

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(Colors.LightGray, papameters.Background);

            // arrange
            Mock.Arrange(() => e.Element).Returns(ExportElement.GroupFooterRow);
            papameters.Background = Colors.Red;

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(Colors.LightGray, papameters.Background);

            // arrage
            Mock.Arrange(() => e.Element).Returns(ExportElement.FooterRow);
            exportViewModel.ExportFileType = ExportFileType.Pdf;

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(new KeyValuePair<string, string>("background-color", Colors.LightGray.ToString().Remove(1, 2)), papameters.Styles.First());

            // arrage
            Mock.Arrange(() => e.Element).Returns(ExportElement.GroupFooterRow);
            papameters.Styles.Clear();

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(new KeyValuePair<string, string>("background-color", Colors.LightGray.ToString().Remove(1, 2)), papameters.Styles.First());
        }
示例#5
0
        public void ElementExporting_GroupHeaderRow()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var exportViewModel = new ExportOptionsViewModel
            {
                ExportFileType = ExportFileType.Excel

            };

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

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            var parameters = new GridViewHtmlVisualExportParameters();
            Mock.Arrange(() => e.VisualParameters).Returns(parameters);
            Mock.Arrange(() => e.Element).Returns(ExportElement.GroupHeaderRow);

            var qcvg = Mock.Create<QueryableCollectionViewGroup>(Constructor.Mocked, Behavior.Loose);
            Mock.Arrange(() => qcvg.Items).Returns(new ReadOnlyObservableCollection<object>(new ObservableCollection<object> { new List<object>(), new List<object>() }));

            e.Value = qcvg;

            // act
            var privateAccessor = new PrivateAccessor(exportUtility);
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(new FontFamily("Arial Unicode MS"), parameters.FontFamily);
            Assert.AreEqual(Colors.LightGray, parameters.Background);
            Assert.AreEqual(30, parameters.Height);
            Assert.AreEqual("2 Items", e.Value);
        }
示例#6
0
        public void ElementExporting_HeaderCell()
        {
            // arrange
            var exportUtility = new ExportUtility();

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            var parameters = new GridViewHtmlVisualExportParameters();
            Mock.Arrange(() => e.VisualParameters).Returns(parameters);
            Mock.Arrange(() => e.Element).Returns(ExportElement.HeaderCell);

            var exportViewModel = new ExportOptionsViewModel
            {
                HeaderForeground = Color.FromArgb(1, 1, 1, 1)
            };

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

            // act
            new PrivateAccessor(exportUtility).CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(Color.FromArgb(1, 1, 1, 1), parameters.Foreground);
        }
示例#7
0
        public void ElementExporting_Row()
        {
            // arrange
            var exportUtility = new ExportUtility();

            var e = Mock.Create<GridViewElementExportingEventArgs>(Behavior.Loose);
            var parameters = new GridViewHtmlVisualExportParameters();
            Mock.Arrange(() => e.VisualParameters).Returns(parameters);
            Mock.Arrange(() => e.Element).Returns(ExportElement.Row);

            var exportViewModel = new ExportOptionsViewModel
            {
                RowBackground = Color.FromArgb(1, 1, 1, 1)
            };

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

            var privateAccessor = new PrivateAccessor(exportUtility);

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(Color.FromArgb(1, 1, 1, 1), parameters.Background);

            // arrage
            exportViewModel.ExportFileType = ExportFileType.Pdf;
            exportViewModel.RowBackground = null;

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(0, parameters.Styles.Count);

            // arrange
            exportViewModel.RowBackground = Color.FromArgb(1, 1, 1, 1);

            // act
            privateAccessor.CallMethod("ElementExporting", new[] { new object(), e });

            // assert
            Assert.AreEqual(new KeyValuePair<string, string>("background-color", "#010101"), parameters.Styles.First());
        }
示例#8
0
        public void GetExtension()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var privateAccessor = new PrivateAccessor(exportUtility);

            // act
            var result = privateAccessor.CallMethod("GetExtension", new object[] { ExportFileType.Excel });
            
            // assert
            Assert.AreEqual("xls", result);

            // act
            result = privateAccessor.CallMethod("GetExtension", new object[] { ExportFileType.ExcelML });

            // assert
            Assert.AreEqual("xml", result);

            // act
            result = privateAccessor.CallMethod("GetExtension", new object[] { ExportFileType.Word });

            // assert
            Assert.AreEqual("doc", result);

            // act
            result = privateAccessor.CallMethod("GetExtension", new object[] { ExportFileType.Csv });

            // assert
            Assert.AreEqual("csv", result);

            // act
            result = privateAccessor.CallMethod("GetExtension", new object[] { ExportFileType.Pdf });

            // assert
            Assert.AreEqual("pdf", result);
        }
示例#9
0
        public void GetFormat()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var privateAccessor = new PrivateAccessor(exportUtility);

            // act
            var result = privateAccessor.CallMethod("GetFormat", new object[] { ExportFileType.Excel });

            // assert
            Assert.AreEqual(ExportFormat.Html, result);

            // act
            result = privateAccessor.CallMethod("GetFormat", new object[] { ExportFileType.Pdf });

            // assert
            Assert.AreEqual(ExportFormat.Html, result);

            // act
            result = privateAccessor.CallMethod("GetFormat", new object[] { ExportFileType.Word });

            // assert
            Assert.AreEqual(ExportFormat.Html, result);

            // act
            result = privateAccessor.CallMethod("GetFormat", new object[] { ExportFileType.ExcelML });

            // assert
            Assert.AreEqual(ExportFormat.ExcelML, result);

            // act
            result = privateAccessor.CallMethod("GetFormat", new object[] { ExportFileType.Csv });

            // assert
            Assert.AreEqual(ExportFormat.Csv, result);
        }
示例#10
0
        public void Export()
        {
            // arrange
            var exportUtility = new ExportUtility();
            var privateAccessor = new PrivateAccessor(exportUtility);

            // act
            var result = (bool)privateAccessor.CallMethod("Export", new object[] { null, null });

            // assert
            Assert.IsFalse(result);

            // arrange
            var dialog = Mock.Create<SaveFileDialog>();
            privateAccessor.SetField("_saveFileDialog", dialog);

            // act
            result = (bool)privateAccessor.CallMethod("Export", new object[] { null, null });

            // assert
            Assert.IsFalse(result);

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

            var grid = new GridViewDataControl();

            using (var stream = new MemoryStream())
            {
                Mock.Arrange(() => dialog.OpenFile()).Returns(stream);

                // act
                result = (bool)privateAccessor.CallMethod("Export", new object[] { grid, "Id|CurrentState" });

                // assert
                Assert.IsTrue(result);
            }

            // arrange
            Mock.Arrange(() => grid.IsGrouping).Returns(true);
            Mock.Arrange(() => grid.Export(Arg.IsAny<Stream>(), Arg.IsAny<GridViewExportOptions>())).DoNothing();
            using (var stream = new MemoryStream())
            {
                Mock.Arrange(() => dialog.OpenFile()).Returns(stream);

                // act
                result = (bool)privateAccessor.CallMethod("Export", new object[] { grid, "Id|CurrentState" });

                // assert
                Assert.IsTrue(result);
            }

            // arrange
            using (var stream = new MemoryStream())
            {
                Mock.Arrange(() => dialog.OpenFile()).Returns(stream);
                exportViewModel.ExportFileType = ExportFileType.Pdf;

                // act
                result = (bool)privateAccessor.CallMethod("Export", new object[] { grid, null });

                // assert
                Assert.IsTrue(result);

                // arrange
                Mock.NonPublic.Arrange(exportUtility, "CreateDocument", grid).DoNothing();

                // act
                result = (bool)privateAccessor.CallMethod("Export", new object[] { grid, null });

                // assert
                Assert.IsFalse(result);
            }

            // arrange
            Mock.Arrange(() => grid.IsGrouping).Returns(false);
            using (var stream = new MemoryStream())
            {
                // arrange
                Mock.Arrange(() => dialog.OpenFile()).Returns(stream);
                Mock.NonPublic.Arrange(exportUtility, "CreateDocument", grid).CallOriginal();

                // act
                result = (bool)privateAccessor.CallMethod("Export", new object[] { grid, null });

                // assert
                Assert.IsTrue(result);
            }
        }
示例#11
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);
        }
        public void OnAfterDataRefreshed()
        {
            var vm = GetNewSearchListVm();

            var infoClass = Mock.Create<IInfoClass>(Behavior.Loose);
            Mock.Arrange(() => vm.InfoListViewSource).ReturnsCollection(new Collection<IInfoClass> { infoClass });
            
            var exportUtility = new ExportUtility();

            var exportStartWasCalled = false;
            Mock.Arrange(() => exportUtility.ExportStart(Arg.AnyString, Arg.IsAny<GridViewDataControl>(), Arg.AnyString)).DoInstead(() => exportStartWasCalled = true);

            var refreshSearchListWasCalled = false;
            Mock.Arrange(() => vm.RefreshSearchList(Arg.IsAny<IFilterViewModel>())).DoInstead(() => refreshSearchListWasCalled = true);

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

            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_tempPageSize", 25);
            privateAccessor.SetField("_tempPageIndex", 10);

            // act
            privateAccessor.CallMethod("OnAfterDataRefreshed", new[] { new object(), EventArgs.Empty});

            // assert
            Assert.IsTrue(exportStartWasCalled);
            Assert.IsTrue(refreshSearchListWasCalled);

            Assert.AreEqual(25, privateAccessor.GetField("_pageSize"));
            Assert.AreEqual(10, privateAccessor.GetField("_currentPageNumber"));

            // arrange
            exportStartWasCalled = false;
            Mock.Arrange(() => vm.InfoListViewSource).ReturnsCollection(new Collection<IInfoClass>());

            // act
            privateAccessor.CallMethod("OnAfterDataRefreshed", new[] { new object(), EventArgs.Empty});

            // assert
            Assert.IsFalse(exportStartWasCalled);
        }
        public void ExportCommand()
        {
            // arrange
            var vm = GetNewSearchListVm();

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

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

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

            Mock.Arrange(() => vm.PageSize).Returns(25);
            Mock.Arrange(() => vm.PageIndex).Returns(10);

            var called = false;
            Mock.Arrange(() => vm.RefreshSearchList(Arg.IsAny<IFilterViewModel>())).DoInstead(() => called = true);

            // act
            vm.ExportCommand.Execute(PageOrientation.Landscape);

            // assert
            Assert.IsTrue(called);

            var privateAccessor = new PrivateAccessor(vm);
            Assert.AreEqual(25, privateAccessor.GetField("_tempPageSize"));
            Assert.AreEqual(10, privateAccessor.GetField("_tempPageIndex"));

            Assert.AreEqual(int.MaxValue, privateAccessor.GetField("_pageSize"));
            Assert.AreEqual(0, privateAccessor.GetField("_currentPageNumber"));
        }
        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);
        }