public void GetClone_SimpleValues_SameData() { //arrange //act var clone = _cluster.GetClone(); //assert clone.Count.Should().Be(2); clone.ClstrNo.Should().Be(9); clone.StartRecNo.Should().Be(16); var rec = clone[0]; rec.Count.Should().Be(3); rec.RecNo.Should().Be(16); rec.Items[0].Key.Should().Be("IDCD_ID"); rec.Keys[0].Should().Be("IDCD_ID"); rec[0].Should().Be("71941"); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); }
/// <summary> /// Helper function that replicates cluster as many times as the number of contained records with RECTYPE=ABCD and NAME=Mary /// Each replicated cluster is an exact replica of the input cluster /// </summary> /// <param name="cluster"></param> /// <returns></returns> private IEnumerable <KeyValCluster> ReplicateMary(ICluster cluster) { var clustersOut = new List <KeyValCluster>(); foreach (var rec in cluster.Records) { //verify, if this record "causes" new cluster if ((string)rec["RECTYPE"] == "ABCD" && (string)rec["NAME"] == "Mary") { var newClstr = cluster.GetClone(); //new cluster to be added to output; the cluster will be identical to input cluster // note that this is contrived example (shall we allow creation of arbitrary clusters?) //newClstr can be manipulated here clustersOut.Add((KeyValCluster)newClstr); } } return(clustersOut); }
/// <summary> /// Helper function to add extra record (to the cluster) for every record with NAME=J** (i.e. name starting with J) /// Extra records will be copies of those records with NAME=J**, except for NAME prefixed by "Dup_of_" and NUM item removed /// </summary> /// <param name="cluster"></param> /// <returns>A copy of the original cluster plus possible extra records</returns> private KeyValCluster DupRecsForJ(ICluster cluster) { KeyValCluster clstrToReturn = (KeyValCluster)cluster.GetClone(); //need to clone in order to manipulate foreach (var rec in cluster.Records) { //verify, if the record contains NAME=J** if (rec.ContainsKey("NAME") && ((string)rec["NAME"]).StartsWith("J")) { dynamic newRec = rec.GetClone(); newRec.NAME = "Dup_of_" + (string)rec["NAME"]; newRec.RemoveItem("NUM"); clstrToReturn.AddRecord(newRec); } } return(clstrToReturn); }