public void Test_OpenDiagramEditor_Closed() { // Arrange. var diagram = new Diagram { File = testDiagramFile }; var diagramPreview = new PreviewDiagramViewModel(diagram); var editor = new Mock <IDiagramEditor>(); editor.SetupGet(e => e.Diagram).Returns(diagram); var diagramManager = CreateManager(d => editor.Object); diagramManager.OpenDiagramCommand.Execute(diagramPreview); DiagramClosedEventArgs closedArgs = null; diagramManager.DiagramClosed += (o, e) => closedArgs = e; // Act. editor.Raise(e => e.Closed += null, EventArgs.Empty); // Assert. Assert.Empty(diagramManager.OpenDiagrams); editor.Verify(e => e.SaveAsync(), Times.Never()); editor.Verify(e => e.Dispose()); Assert.NotNull(closedArgs); Assert.Equal(diagram, closedArgs.Diagram); }
public void Test_OpenDiagramEditor_Saved_NoMatchingPreview() { // Arrange. var image = new BitmapImage(); var diagramPreview = new PreviewDiagramViewModel(new Diagram { File = new FileInfo(testDiagramFile.FullName + "2") }); var editor = Mock.Of <IDiagramEditor>(e => e.Diagram == new Diagram { File = testDiagramFile }); Mock.Get(editor).SetupGet(e => e.DiagramImage).Returns(image); var diagramManager = CreateManager(d => editor); diagramManager.Explorer.PreviewDiagrams.Add(diagramPreview); diagramManager.OpenDiagramCommand.Execute(diagramPreview); // Act. Mock.Get(editor).Raise(e => e.Saved += null, EventArgs.Empty); // Assert. Assert.Null(diagramPreview.ImagePreview); }
public void Test_OpenDiagramCommand_DiagramAlreadyOpenedOnce() { // Arrange. var diagram = new Diagram { File = testDiagramFile }; var diagramPreview = new PreviewDiagramViewModel(diagram); var editor = Mock.Of <IDiagramEditor>(e => e.Diagram == diagram); var diagramManager = CreateManager(null); diagramManager.OpenDiagrams.Add(editor); DiagramOpenedEventArgs openedArgs = null; diagramManager.DiagramOpened += (o, e) => openedArgs = e; // Act. diagramManager.OpenDiagramCommand.Execute(diagramPreview); // Assert. Assert.Single(diagramManager.OpenDiagrams); Assert.Equal(editor, diagramManager.OpenDiagram); Assert.Null(openedArgs); }
public async Task Test_OpenDiagram_When_PreviewAlreadyExists() { // Arrange. string filePath = Path.Combine(diagramLocation.FullName, "TestFile.puml"); var existingDiagram = new Diagram { File = new FileInfo(filePath) }; var existingPreview = new PreviewDiagramViewModel(existingDiagram); explorer.PreviewDiagrams.Add(existingPreview); var diagramUri = new Uri(filePath, UriKind.Absolute); diagramIO.Setup(io => io.ReadAsync(It.Is <FileInfo>(f => f.FullName == filePath))) .Returns((FileInfo file) => Task.FromResult(new Diagram { File = file })); OpenPreviewRequestedEventArgs openArgs = null; explorer.OpenPreviewRequested += (o, e) => openArgs = e; // Act. var openedDiagram = await explorer.OpenDiagramAsync(diagramUri); // Assert. Assert.Same(existingDiagram, openedDiagram); Assert.Same(existingPreview.Diagram, explorer.PreviewDiagrams.Single().Diagram); Assert.NotNull(openArgs); Assert.Same(existingPreview, openArgs.RequestedPreview); }
public void Test_DiagramFileAdded_PreviewAlreadyExists() { // Arrange. var existingFile = new FileInfo("test.puml"); var existingPreview = new PreviewDiagramViewModel(new Diagram { File = existingFile }); explorer.DiagramLocation = existingFile.Directory; explorer.PreviewDiagrams.Add(existingPreview); diagramIO.Setup(dio => dio.ReadAsync(It.IsAny <FileInfo>())) .Returns(Task.FromResult(new Diagram { File = existingFile, Content = "New Diagram" })); // Act. diagramIO.Raise(dio => dio.DiagramFileAdded += null, new DiagramFileAddedEventArgs(existingFile)); // Assert. Assert.Single(explorer.PreviewDiagrams); Assert.Same(existingPreview, explorer.PreviewDiagrams.Single()); }
public void Test_CanDeleteDiagram(bool expected, PreviewDiagramViewModel preview) { // Act. bool actual = explorer.DeleteDiagramCommand.CanExecute(preview); // Assert. Assert.Equal(expected, actual); }
public void Test_CanRequestOpenPreview(bool expected, PreviewDiagramViewModel preview) { // Act. bool actual = explorer.RequestOpenPreviewCommand.CanExecute(preview); // Assert. Assert.Equal(expected, actual); }
public void Test_CodePreview(string expected, string input) { // Arrange. var diagram = new Diagram { Content = input }; var preview = new PreviewDiagramViewModel(diagram); // Act. var actual = preview.CodePreview; // Assert. Assert.Equal(expected, actual); }
public void Test_RequestOpenPreviewCommand() { // Arrange. var preview = new PreviewDiagramViewModel(new Diagram()); OpenPreviewRequestedEventArgs args = null; EventHandler <OpenPreviewRequestedEventArgs> handler = (o, e) => args = e; explorer.OpenPreviewRequested += handler; // Act. explorer.RequestOpenPreviewCommand.Execute(preview); // Assert. Assert.NotNull(args); Assert.Equal(preview, args.RequestedPreview); }
public async Task Test_DeleteDiagramCommand() { // Arrange. diagramIO.Setup(dio => dio.DeleteAsync(It.IsAny <Diagram>())) .Returns(Task.CompletedTask); var preview = new PreviewDiagramViewModel(new Diagram { File = new FileInfo("TestFile") }); explorer.PreviewDiagrams.Add(preview); // Act. await explorer.DeleteDiagramCommand.ExecuteAsync(preview); // Assert. Assert.Empty(explorer.PreviewDiagrams); diagramIO.Verify(dio => dio.DeleteAsync(preview.Diagram)); }
public void Test_OpenPreviewRequested() { // Arrange. var diagram = new Diagram { File = testDiagramFile }; var diagramPreview = new PreviewDiagramViewModel(diagram); var editor = Mock.Of <IDiagramEditor>(e => e.Diagram == diagram); var diagramManager = CreateManager(d => editor); // Act. explorer.Raise(p => p.OpenPreviewRequested += null, new OpenPreviewRequestedEventArgs(diagramPreview)); // Assert. Assert.Single(diagramManager.OpenDiagrams); Assert.Equal(editor, diagramManager.OpenDiagrams.Single()); Assert.Equal(editor, diagramManager.OpenDiagram); }
public void Test_DiagramFileDeleted() { // Arrange. var preview = new PreviewDiagramViewModel(new Diagram { File = new FileInfo("test.puml") }); explorer.PreviewDiagrams.Add(preview); DiagramDeletedEventArgs deleteArgs = null; EventHandler <DiagramDeletedEventArgs> deleteHandler = (o, e) => deleteArgs = e; explorer.DiagramDeleted += deleteHandler; // Act. diagramIO.Raise(dio => dio.DiagramFileDeleted += null, new DiagramFileDeletedEventArgs(new FileInfo("test.puml"))); // Assert. Assert.Empty(explorer.PreviewDiagrams); Assert.NotNull(deleteArgs); Assert.Equal("test.puml", deleteArgs.DeletedDiagram.File.Name); }
public void Test_OpenDiagramEditor_Saved_UpdatesPreviewDiagram() { // Arrange. var image = new BitmapImage(); var preview = new PreviewDiagramViewModel(new Diagram { Content = "blah", File = new FileInfo("diagram.puml"), ImageFile = new FileInfo("image.png") }); var editor = new Mock <IDiagramEditor>(); editor.SetupGet(e => e.Diagram).Returns(new Diagram { Content = "blah-blah", File = new FileInfo("diagram.puml"), ImageFile = new FileInfo("image2.svg") }); editor.SetupGet(e => e.DiagramImage).Returns(image); var diagramManager = CreateManager(d => editor.Object); diagramManager.Explorer.PreviewDiagrams.Add(preview); diagramManager.OpenDiagramCommand.Execute(preview); // Act. editor.Raise(e => e.Saved += null, EventArgs.Empty); // Assert. Assert.Equal(image, preview.ImagePreview); Assert.Equal("blah-blah", preview.Diagram.Content); Assert.Equal(ImageFormat.SVG, preview.Diagram.ImageFormat); Assert.Equal("image2.svg", preview.Diagram.ImageFile.Name); }