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); }