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