コード例 #1
0
        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);
        }
コード例 #2
0
        public void Test_AddNewDiagramCommand_Unsuccessful()
        {
            // Arrange.
            string newDiagramFilePath = Path.Combine(diagramLocation.FullName, "new-diagram.puml");

            diagramIO.Setup(dio => dio.SaveAsync(It.IsAny <Diagram>(), It.IsAny <bool>()))
            .Returns(Task.FromException(new InvalidOperationException()));

            explorer.DiagramLocation    = diagramLocation;
            explorer.NewDiagramTemplate = "New Diagram";

            OpenPreviewRequestedEventArgs newDiagramArgs = null;

            explorer.OpenPreviewRequested += (o, e) => newDiagramArgs = e;

            // Act.
            explorer.AddNewDiagramCommand.Execute(new Uri(newDiagramFilePath));

            // Assert.
            Assert.Null(newDiagramArgs);

            diagramIO.Verify(dio => dio.SaveAsync(
                                 It.Is <Diagram>(d => d.Content == "New Diagram" && d.File.FullName == newDiagramFilePath),
                                 false));
        }
コード例 #3
0
        public void Test_AddNewDiagramCommand()
        {
            // Arrange.
            string newDiagramFilePath = Path.Combine(diagramLocation.FullName, "new-diagram.puml");

            explorer.DiagramLocation    = diagramLocation;
            explorer.NewDiagramTemplate = "New Diagram";

            OpenPreviewRequestedEventArgs newDiagramArgs = null;

            explorer.OpenPreviewRequested += (o, e) => newDiagramArgs = e;

            diagramIO.Setup(dio => dio.ReadAsync(It.IsAny <FileInfo>()))
            .Returns((FileInfo file) => Task.FromResult(new Diagram {
                File = file
            }));

            // Act.
            explorer.AddNewDiagramCommand.Execute(new Uri(newDiagramFilePath));

            // Assert.
            Assert.Single(explorer.PreviewDiagrams);
            Assert.Equal(newDiagramFilePath, explorer.PreviewDiagrams.Single().Diagram.File.FullName);

            Assert.NotNull(newDiagramArgs);
            Assert.Equal(explorer.PreviewDiagrams.Single(), newDiagramArgs.RequestedPreview);
            Assert.Equal(explorer.PreviewDiagrams.Single(), explorer.CurrentPreviewDiagram);

            diagramIO.Verify(dio => dio.SaveAsync(
                                 It.Is <Diagram>(d => d.File.FullName == newDiagramFilePath),
                                 false));
        }
コード例 #4
0
        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);
        }