Esempio n. 1
0
        public void FindSimilar_ShouldFindTwoResults()
        {
            List <Motor> allMotors = new List <Motor>()
            {
                motorsExamples1[0], motorsExamples1[1], motorsExamples1[2]
            };
            Motor compared = motorsExamples2[0];

            //TODO: Refactor the data initiation - should be common list of motors with BOM and second list should be it's depp-copy with changed bom afterwards
            allMotors[0].AddPart(partsExamples[0], 1, 1);
            allMotors[0].AddPart(partsExamples[1], 2, 1);
            allMotors[0].AddPart(partsExamples[2], 2, 1);
            allMotors[1].AddPart(partsExamples[3], 3, 1);
            allMotors[1].AddPart(partsExamples[4], 4, 1);
            allMotors[1].AddPart(partsExamples[5], 5, 1);
            allMotors[2].AddPart(partsExamples[0], 3, 1);
            allMotors[2].AddPart(partsExamples[2], 4, 1);
            allMotors[2].AddPart(partsExamples[4], 5, 1);

            compared.AddPart(partsExamples[0], 1, 1);
            compared.AddPart(partsExamples[1], 2, 1);
            compared.AddPart(partsExamples[3], 2, 1);

            List <KeyValuePair <int, Motor> > expected = new List <KeyValuePair <int, Motor> >();

            expected.Add(new KeyValuePair <int, Motor>(1, allMotors[0]));
            expected.Add(new KeyValuePair <int, Motor>(2, allMotors[1]));
            expected.Add(new KeyValuePair <int, Motor>(2, allMotors[2]));

            MotorService motorService = new MotorService(new DataAccessByMemoryCache());

            List <KeyValuePair <int, Motor> > actual = motorService.FindSimilar(compared, allMotors);

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        internal static IEnumerable <Motor> BulidMotor(IEnumerable <MotorRecord> motors)
        {
            if (motors == null)
            {
                return(null);
            }
            var result = new List <Motor>();

            foreach (var motor in motors)
            {
                var newMotor = new Motor(
                    motorNumber: motor.MotorNumber,
                    motorType: motor.MotorType,
                    displacement: Convert.ToUInt32(motor.Displacement),
                    feature: motor.Feature,
                    description: motor.Description);
                for (int i = 0; i < motor.BOM.Count(); i++)
                {
                    var bomItem = motor.BOM[i];
                    newMotor.AddPart(bomItem.PartItem, bomItem.PositionNumber, bomItem.Quantity);
                }
                result.Add(newMotor);
            }
            return(result);
        }
Esempio n. 3
0
        static public Motor CreateMotorWithPredefinedParts(List <Part> parts, int maxNumberOfPartsInBOM, int minNumberOfPartsInBOM = 1)
        {
            if (parts == null)
            {
                parts = new List <Part>();
            }

            Motor result = new Motor
                               (RandomPartNumber(),
                               RandomMotorFamily(),
                               RandomDisplacement(),
                               RandomFeature(),
                               RandomDescription()
                               );

            var numberOfPartsInBom = random.Next(minNumberOfPartsInBOM, maxNumberOfPartsInBOM);

            if (numberOfPartsInBom == 0 && parts.Count() != 0)
            {
                numberOfPartsInBom = 1;
            }
            for (int i = 0; i < numberOfPartsInBom; i++)
            {
                var index = random.Next(0, parts.Count());
                result.AddPart(
                    parts.ElementAt(index),
                    RandomPositionNumber(),
                    RandomQuantity());
            }

            return(result);
        }
Esempio n. 4
0
        public void AddPart_shouldCreate2BOMItems()
        {
            int expectedBOMItemCount = 2;
            var motor = new Motor(motorNumber: "12345678");
            var parts = new List <Part>()
            {
                new Part(partNumber: "11111111"), new Part(partNumber: "22222222")
            };

            foreach (var part in parts)
            {
                motor.AddPart(part, 1, 1);
            }

            Assert.Equal(motor.BOM.Count, expectedBOMItemCount);
        }
Esempio n. 5
0
        internal static Motor BulidMotor(MotorRecord motor, IEnumerable <BOMItemRecord> bomItemRecords, IEnumerable <Part> parts)
        {
            if (motor == null)
            {
                return(null);
            }

            var newMotor = new Motor(motor.MotorNumber, motor.MotorType, Convert.ToUInt32(motor.Displacement), motor.Feature, motor.Description);

            foreach (var partItem in bomItemRecords)
            {
                var partToAdd = parts.First(p => p.PartNumber == partItem.PartItem.PartNumber);
                newMotor.AddPart(partToAdd, Convert.ToUInt32(partItem.PositionNumber), Convert.ToUInt32(partItem.Quantity));
            }
            return(newMotor);
        }
Esempio n. 6
0
        static public Motor CreateMotor(MotorFamily family, int numberOfParts)
        {
            Motor result = new Motor
                               (RandomPartNumber(),
                               family,
                               RandomDisplacement(),
                               RandomFeature(),
                               RandomDescription()
                               );

            for (int i = 0; i < numberOfParts; i++)
            {
                result.AddPart(AllParts[random.Next(0, AllParts.Count - 1)], RandomPositionNumber(), RandomQuantity());
            }

            return(result);
        }
Esempio n. 7
0
        public IEnumerable <Motor> ReadSheetAndConvertForMotors()
        {
            ISheet sheet = Workbook.GetSheet(SheetName);

            List <Motor> motors = new List <Motor>();
            List <Part>  parts  = new List <Part>();

            for (int i = motorsRow; i <= sheet.LastRowNum; i++)
            {
                var    row = sheet.GetRow(i);
                string designationCellText = LoadCellAsString(row.GetCell(motorsDesignationColumn));
                string motorNumber         = LoadPartNumber(row.GetCell(motorsColumn));
                if (motorNumber == null)
                {
                    continue;
                }
                uint?       displacement     = LoadDisplacement(designationCellText);
                string      MotorType        = LoadMotorType(designationCellText);
                MotorFamily motorFamily      = LoadMotorFamily(designationCellText);
                string      motorDescription = LoadCellAsString(row.GetCell(motorsDescriptionColumn));

                Motor newMotor = new Motor(motorNumber, motorFamily, displacement, MotorType, motorDescription);

                motors.Add(newMotor);

                for (int j = partsColumn; j <= row.LastCellNum; j++)
                {
                    var cell = row.GetCell(j);
                    if (cell == null)
                    {
                        continue;
                    }
                    else if (String.IsNullOrWhiteSpace(cell.ToString()))
                    {
                        continue;
                    }
                    string partNumber        = LoadPartNumber(sheet.GetRow(partsRow).GetCell(j));
                    string positionNumberTxt = LoadPositionNumber(sheet.GetRow(partsPositionNoRow).GetCell(j));
                    string designation       = LoadPartDesignation(sheet.GetRow(partsDesignationRow).GetCell(j));
                    string description       = LoadDescription(sheet.GetRow(partsDescriptionRow).GetCell(j));
                    uint   quantity          = LoadQuantity(row.GetCell(j));

                    uint positionNumber = 0;

                    if (IsLawrencePart(positionNumberTxt))
                    {
                        continue;
                    }
                    else
                    {
                        UInt32.TryParse(positionNumberTxt, out positionNumber);
                    }
                    if (!IsRecordCorrect(partNumber, positionNumber))
                    {
                        newMotor.RemoveAllParts();
                        break;
                    }
                    else
                    {
                        //TODO: Instead of looking to the list it should be Dictionary
                        Part partToAdd = parts.FirstOrDefault(p => p.PartNumber.Equals(partNumber));
                        if (partToAdd == null)
                        {
                            parts.Add(partToAdd = new Part(partNumber, designation, description));
                        }
                        newMotor.AddPart(partToAdd, positionNumber, quantity);
                    }
                }
            }

            return(motors);
        }