using System.Collections.Generic;
public static void Main()
var testClass = new YourTestClass();
testClass.TestUpdatePartInformationSOQty();
public class YourTestClass
public void TestUpdatePartInformationSOQty()
var partList = new List<IPartInformation>
var data = new SAP_INTERFACE_MODELS.ZSD_GET_SO_BALANCE_QTY_INTERFACE.ZSO_BALANCE_QTY_STRUC[]
new SAP_INTERFACE_MODELS.ZSD_GET_SO_BALANCE_QTY_INTERFACE.ZSO_BALANCE_QTY_STRUC
new SAP_INTERFACE_MODELS.ZSD_GET_SO_BALANCE_QTY_INTERFACE.ZSO_BALANCE_QTY_STRUC
new SAP_INTERFACE_MODELS.ZSD_GET_SO_BALANCE_QTY_INTERFACE.ZSO_BALANCE_QTY_STRUC
var instanceUnderTest = new YourClass();
var result = instanceUnderTest.UpdatePartInformationSOQty(partList, data);
Console.WriteLine("Test Result: " + result);
public interface IPartInformation
string Part { get; set; }
double PGIQty { get; set; }
public class PartInformationDyson : IPartInformation
public string Part { get; set; }
public double PGIQty { get; set; }
public bool UpdatePartInformationSOQty(List<IPartInformation> partList, SAP_INTERFACE_MODELS.ZSD_GET_SO_BALANCE_QTY_INTERFACE.ZSO_BALANCE_QTY_STRUC[] data)
var groupedData = data.GroupBy(d => d.MATNR).Select(g => new { MATNR = g.Key, TotalKLMENG = g.Sum(d => d.KLMENG) });
foreach (var d in groupedData)
var pgiQty = d.TotalKLMENG;
var partsToUpdate = partList.Where(x => x.Part == d.MATNR).ToList();
if (!partsToUpdate.Any())
partsToUpdate.ForEach(part => part.PGIQty = pgiQty);
foreach (var x in partList){
Console.WriteLine("Test Result: " + x.Part + " - " + x.PGIQty);
namespace SAP_INTERFACE_MODELS
public class ZSD_GET_SO_BALANCE_QTY_INTERFACE
public class ZSO_BALANCE_QTY_STRUC
public string KUNNR { get; set; }
public string MATNR { get; set; }
public double KLMENG { get; set; }
public string MEINS { get; set; }
public string EDATU { get; set; }