Skip to content

Commit 7e330bc

Browse files
committed
some fixes for tests; failed because of wrong/missing metadata
1 parent e34a7e6 commit 7e330bc

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

PSGraph.Tests/ExportGraphViewCmdletTests.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void ExportGraph_InvalidFormat_ThrowsException()
153153
public void ExportGraph_NoPathProvided_ReturnsOutput()
154154
{
155155
// Arrange
156-
var graph = CreateSampleGraph();
156+
var graph = CreateSampleGraphWithMetadata();
157157

158158
_powershell.AddCommand("Export-Graph")
159159
.AddParameter("Graph", graph)
@@ -173,7 +173,7 @@ public void ExportGraph_NoPathProvided_ReturnsOutput()
173173
public void ExportGraph_NoPathProvided_ReturnsVegaString()
174174
{
175175
// Arrange
176-
var graph = CreateSampleGraph();
176+
var graph = CreateSampleGraphWithMetadata();
177177

178178
var records = graph.ConvertToVegaNodeLink();
179179

@@ -326,6 +326,28 @@ private PsBidirectionalGraph CreateSampleGraph()
326326
var vertexB = new PSVertex("B");
327327
var vertexC = new PSVertex("C");
328328

329+
graph.AddVertexRange(new[] { vertexA, vertexB, vertexC });
330+
331+
var edgeAB = new PSEdge(vertexA, vertexB, new PSEdgeTag());
332+
var edgeBC = new PSEdge(vertexB, vertexC, new PSEdgeTag());
333+
334+
graph.AddEdgeRange(new[] { edgeAB, edgeBC });
335+
336+
return graph;
337+
}
338+
339+
private PsBidirectionalGraph CreateSampleGraphWithMetadata()
340+
{
341+
var graph = new PsBidirectionalGraph();
342+
343+
var vertexA = new PSVertex("A");
344+
vertexA.Metadata.TryAdd("group", 1);
345+
var vertexB = new PSVertex("B");
346+
vertexB.Metadata.TryAdd("group", 1);
347+
var vertexC = new PSVertex("C");
348+
vertexB.Metadata.TryAdd("group", 2);
349+
350+
329351
graph.AddVertexRange(new[] { vertexA, vertexB, vertexC });
330352

331353
var edgeAB = new PSEdge(vertexA, vertexB, new PSEdgeTag());

PSGraph.Vega.Extensions/VegaDataConverter.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ public static (List<NodeRecord> nodes, List<LinkRecord> links) ConvertToVegaNode
3838
if (vertexLookup.TryGetValue(edge.Source, out int sourceId) &&
3939
vertexLookup.TryGetValue(edge.Target, out int targetId))
4040
{
41-
{
42-
var groupObj = ((IDictionary<string, object?>)edge.Target.Metadata)["group"];
43-
if (groupObj != null && int.TryParse(groupObj.ToString(), out int parsedGroup))
44-
value = parsedGroup;
45-
}
41+
{
42+
if (((IDictionary<string, object?>)edge.Target.Metadata).ContainsKey("group"))
43+
{
44+
var groupObj = ((IDictionary<string, object?>)edge.Target.Metadata)["group"];
45+
if (groupObj != null && int.TryParse(groupObj.ToString(), out int parsedGroup))
46+
value = parsedGroup;
47+
}
48+
49+
}
4650
links.Add(new LinkRecord(sourceId, targetId, value, sourceId, targetId));
4751
}
4852
}

0 commit comments

Comments
 (0)