Exemplo n.º 1
0
        public void Write_Delete_Read_Test_ThrowsKeyNotFoundException()
        {
            string data = @"_";

            Document      document = _application.Documents.Add();
            string        key      = "testKey";
            HiddenStorage storage  = new HiddenStorage(document, key);

            storage.Write(data);
            storage.Delete();
            Assert.Throws <KeyNotFoundException>(() => storage.Read());
        }
Exemplo n.º 2
0
        public void Write_Read_Test()
        {
            string expected = @"{ test: ""testvalue""}";

            Document      document = _application.Documents.Add();
            string        key      = "testKey";
            HiddenStorage storage  = new HiddenStorage(document, key);

            storage.Write(expected);
            string actual = storage.Read();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void Write_CloseFile_OpenFile_Read_Test()
        {
            string expected = @"{ test: ""testvalue""}";

            _tmpFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".docx");

            Document      document = _application.Documents.Add();
            string        key      = "testKey";
            HiddenStorage storage  = new HiddenStorage(document, key);

            storage.Write(expected);
            document.SaveAs(_tmpFile, WdSaveFormat.wdFormatXMLDocument);
            document.Close();

            Document      documentReopened = _application.Documents.Open(_tmpFile);
            HiddenStorage storageReopened  = new HiddenStorage(documentReopened, key);
            string        actual           = storageReopened.Read();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        void button1_Click(object sender, RibbonControlEventArgs e)
        {
            string        key     = "test_key";
            HiddenStorage storage = new HiddenStorage(Globals.ThisAddIn.Application.ActiveDocument, key);

            string textBeforeEdit = "";

            try {
                textBeforeEdit = storage.Read();
            }
            catch (KeyNotFoundException) {
                // means nothing saved yet
            }

            MetadataEditForm editForm = new MetadataEditForm(textBeforeEdit);

            if (editForm.ShowDialog() == DialogResult.OK)
            {
                storage.Write(editForm.Text);
            }
        }