public void TestScreenUpdate()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                object officeDocument = null;
                try
                {
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    Assert.IsTrue(application.ScreenUpdating);

                    officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                    Assert.IsNotNull(officeDocument);

                    Assert.IsFalse(application.ScreenUpdating);

                    applicationController.CloseDocument(officeDocument, false);

                    Assert.IsTrue(application.ScreenUpdating);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;
                }
            }
        }
        public void TestEventsDisabledForAutoMacros()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);

                Excel.Workbook workbook = null;

                try
                {
                    workbook = (Excel.Workbook)applicationController.OpenDocument(m_testPath + "McKinzie bounce-test2.xls", false);
                    Assert.IsNotNull(workbook);
                    Assert.IsTrue(workbook.Saved);
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    Assert.IsNotNull(application);
                    Assert.IsFalse(application.EnableEvents);
                    applicationController.CloseDocument(workbook, false);
                }
                finally
                {
                    if (null != workbook)
                        Marshal.ReleaseComObject(workbook);

                    workbook = null;
                }
            }
        }
 public void TestCloseInvalidDocument()
 {
     using(ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.CloseDocument(new object(), false);
     }
 }
 public void TestCloseNullDocument()
 {
     using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
     {
         applicationController.CreateHostApplication(2000);
         applicationController.CloseDocument(null, false);
     }
 }
        public void TestCloseDocumentOnAlreadyClosedDocument()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                Excel.Workbook workbook = (Excel.Workbook)applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(workbook);

                try
                {
                    object vtMissing = Missing.Value;
                    workbook.Close(vtMissing, vtMissing, vtMissing);

                    applicationController.CloseDocument(workbook, false);
                }
                finally
                {
                    if (null != workbook)
                        Marshal.ReleaseComObject(workbook);

                    workbook = null;
                }
            }
        }
        public void TestCloseDocument()
        {
            using (ExcelApplicationController applicationController = new ExcelApplicationController(true))
            {
                applicationController.CreateHostApplication(2000);
                object officeDocument = applicationController.OpenDocument(m_testPath + "test.xls", false);
                Assert.IsNotNull(officeDocument);

                Excel.Workbooks workbooks = null;
                try
                {
                    Assert.IsInstanceOf(typeof(Excel.Workbook), officeDocument);
                    Excel._Application application = (Excel._Application)applicationController.HostApplication;
                    workbooks = (Excel.Workbooks)application.Workbooks;
                    Assert.AreEqual(1, workbooks.Count);

                    applicationController.CloseDocument(officeDocument, false);
                    Assert.AreEqual(0, workbooks.Count);
                }
                finally
                {
                    if (null != officeDocument)
                        Marshal.ReleaseComObject(officeDocument);

                    officeDocument = null;

                    if (null != workbooks)
                        Marshal.ReleaseComObject(workbooks);

                    workbooks = null;
                }
            }
        }