public void ReadNodePropertyFields_Throws_If_Not_In_Required_State(VnaFileSection state) { var reader = new VnaAdjListReader(); reader.State = state; var ex = Assert.Throws<InvalidOperationException>(() => reader.ReadNodePropertyFields(new string[] { "X" }, null, -1, null)); }
public void ReadNodePropertyFields_Reads_Fields_Into_NodeAttribs_From_StarNodeData_Section(int index, string[] dataFields, string[] dataFieldNames, Type[] dataTypes, int[] srcFieldIndices) { int nodeCount = 3; // simulate initialized network var net = Blob.TestSupport.Network.BasicAdjListGenerator.GenerateAdjListWithDataAttribs(nodeCount, 0, false, true, false); var builder = new Blob.TestSupport.Network.DataAttributesBuilder(); builder.AddColumns((INodeAttributes)net, dataTypes, dataFieldNames, false); var reader = new VnaAdjListReader(); reader.State = VnaFileSection.NodeProperties; // simulate the list of HeaderField objects that would have been created in 1st pass for (int i = 0; i < dataFields.Length; i++) reader.NodePropertyHeaders.Add(new HeaderField(dataFieldNames[i], VnaFileSection.NodeProperties, srcFieldIndices[i], null) { AttribColumnIndex = srcFieldIndices[i] }); int targetNodeIndex = 1; INode owner = net.Nodes[targetNodeIndex]; reader.ReadNodePropertyFields(dataFields, net, targetNodeIndex, reader.NodePropertyHeaders); for (int i = 0; i < dataTypes.Length; i++) { if (dataTypes[i] == typeof(string)) { var val = net.NodeData.GetValue<string>(owner, i); Assert.Equal(dataFields[i], val); } else if (dataTypes[i] == typeof(int)) { var val = net.NodeData.GetValue<int>(owner, i); Assert.Equal(Convert.ToInt32(dataFields[i]), val); } else if (dataTypes[i] == typeof(float)) { var val = net.NodeData.GetValue<float>(owner, i); Assert.Equal(Convert.ToSingle(dataFields[i]), val); } else if (dataTypes[i] == typeof(double)) { var val = net.NodeData.GetValue<double>(owner, i); Assert.Equal(Convert.ToDouble(dataFields[i]), val); } else { Assert.True(false); //force a fail } } }