Пример #1
0
        public bool RunTestCases()
        {
            bool retResult = true;
            IPositionDataService dataService = new CSVPositionDataService(null, null);
            IPositionCalculator  netPosCalc  = new NetPositionCalculator(dataService);
            IPositionCalculator  boxPosCalc  = new BoxPositionCalculator(dataService);
            var positionList = new List <Position>();

            positionList.Add(new Position()
            {
                trader = "Joe", broker = "ML", symbol = "IBM", quantity = 50, price = 100.23
            });
            positionList.Add(new Position()
            {
                trader = "Joe", broker = "ML", symbol = "IBM", quantity = 100, price = 100.23
            });
            positionList.Add(new Position()
            {
                trader = "Joe", broker = "ML", symbol = "IBM", quantity = -50, price = 100.23
            });
            positionList.Add(new Position()
            {
                trader = "Joe", broker = "ML", symbol = "IBM", quantity = -20, price = 100.23
            });
            positionList.Add(new Position()
            {
                trader = "Joe", broker = "ML", symbol = "IBM", quantity = -10, price = 100.23
            });
            positionList.Add(new Position()
            {
                trader = "Joe", broker = "MLB", symbol = "IBM", quantity = -10, price = 100.23
            });
            netPosCalc.PositionList = positionList;
            var result = netPosCalc.Calculate();

            boxPosCalc.PositionList = positionList;
            var result2 = boxPosCalc.Calculate();

            if (result.Count == 1 && result[0].quantity == 60)
            {
                Console.WriteLine("Net Position Validated");
            }
            else
            {
                retResult = false; Console.WriteLine("Net Position validation error");
            }

            if (result2.Count == 1 && result2[0].quantity == 10)
            {
                Console.WriteLine("Box Position Validated");
            }
            else
            {
                retResult = false; Console.WriteLine("Box Position Validation error");
            }

            return(retResult);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            //Test cases usually set it up using nunit, here i just added below for simplocity
            //
            var test = new PositionCalculatorTest();

            if (!test.RunTestCases())
            {
                return;
            }

            // Only below code should be here and above test cases should be moved to nunit
            Console.WriteLine("Please Enter Position Data file fullpath(Including FileName)");
            Console.WriteLine("----");
            var inputFile = Console.ReadLine();

            Console.WriteLine("Please Enter Net Position Output File Path(Including FileName).");
            Console.WriteLine("----");
            var netOutputPathFile1 = Console.ReadLine();

            Console.WriteLine("Please Enter Box Position Output File Path(Including FileName).");
            Console.WriteLine("----");
            var boxOutputPathFile2 = Console.ReadLine();

            IPositionDataService netDataService = new CSVPositionDataService(inputFile, netOutputPathFile1);
            IPositionCalculator  netPocCalc     = new NetPositionCalculator(netDataService);
            var result = netPocCalc.ProcessFile();

            IPositionDataService boxDataService = new CSVPositionDataService(inputFile, boxOutputPathFile2);
            IPositionCalculator  boxPocCalc     = new BoxPositionCalculator(boxDataService);
            var result2 = boxPocCalc.ProcessFile();

            if (result && result2)
            {
                Console.WriteLine("Processing completed");
            }
            else
            {
                Console.WriteLine("Error occured");
            }

            Console.WriteLine("Press any key to continue.");
            Console.WriteLine("----");
            Console.ReadLine();
        }