예제 #1
0
        string When(CarProduced e)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("produce car {0}:", e.CarModel).AppendLine();
            foreach (var carPart in e.Parts)
            {
                builder.AppendFormat("     {0} {1} pcs", carPart.Name, carPart.Quantity).AppendLine();
            }

            return(builder.ToString());
        }
예제 #2
0
        void When(CarProduced e)
        {
            CreatedCars.Add(e.CarModel);

            foreach (var carPart in e.Parts)
            {
                var removed = carPart.Quantity;

                var quantitied = GetNumberOfAvailablePartsQuantity(carPart.Name);
                if (quantitied > 0)
                {
                    AvailableParts[carPart.Name] = quantitied > removed ? quantitied - removed : 0;
                }
            }

            var emptyPartKeys = AvailableParts.Where(x => x.Value == 0).Select(x => x.Key).ToList();

            foreach (var emptyPartKey in emptyPartKeys)
            {
                AvailableParts.Remove(emptyPartKey);
            }
        }