public void ReloadOnSaveTest() { // Arrange void CheckIntegrity(OfficeDocumentViewModel innerModel) { Assert.AreEqual(2, innerModel.Children.Count); for (var i = 0; i < 2; ++i) { var innerPart = (OfficePartViewModel)innerModel.Children[i]; if (innerPart.Part?.PartType == XmlPart.RibbonX12) { Assert.AreEqual(1, innerPart.Children.Count); Assert.AreEqual("redo", ((IconViewModel)innerPart.Children[0]).Name); } else { Assert.AreEqual(2, innerPart.Children.Count); Assert.AreEqual("changedId", ((IconViewModel)innerPart.Children[0]).Name); Assert.AreEqual("redo", ((IconViewModel)innerPart.Children[1]).Name); } } } using (var doc = new OfficeDocument(this.sourceFile)) using (var viewModel = new OfficeDocumentViewModel(doc)) { viewModel.InsertPart(XmlPart.RibbonX12); viewModel.InsertPart(XmlPart.RibbonX14); var part = (OfficePartViewModel)viewModel.Children[0]; part.InsertIcon(this.undoIcon); part.InsertIcon(this.redoIcon); part.RemoveIcon("undo"); part = (OfficePartViewModel)viewModel.Children[1]; part.InsertIcon(this.redoIcon); var icon = (IconViewModel)part.Children[0]; icon.Name = "changedId"; part.InsertIcon(this.redoIcon); // Act / assert CheckIntegrity(viewModel); viewModel.Save(false, this.destFile); } using (var doc = new OfficeDocument(this.destFile)) using (var viewModel = new OfficeDocumentViewModel(doc)) { CheckIntegrity(viewModel); viewModel.Save(true, this.destFile); } using (var doc = new OfficeDocument(this.destFile)) using (var viewModel = new OfficeDocumentViewModel(doc)) { CheckIntegrity(viewModel); } }
public void PartShouldBeInserted() { // Arrange var doc = new OfficeDocument(this.sourceFile); var viewModel = new OfficeDocumentViewModel(doc); // Act viewModel.InsertPart(XmlParts.RibbonX12); // Assert Assert.AreEqual(1, viewModel.Children.Count); }
public void DocumentShouldBeSaved() { // Arrange using var doc = new OfficeDocument(_sourceFile); using var viewModel = new OfficeDocumentViewModel(doc); viewModel.InsertPart(XmlPart.RibbonX12); Assume.That(File.Exists(_destFile), Is.False, "File was not deleted before test"); // Act doc.Save(_destFile); // Assert Assert.IsTrue(File.Exists(_destFile), "File was not saved"); }