Exemple #1
0
        /// <summary>
        /// Initialize a Context with Strategy and Calcuate
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            try
            {
                //Initialize Pyramid Context with Default Strategy
                PyramidContext p = new PyramidContext(new DefaultPyramidStrategy());

                //Use Context Object to Build the Pyramid
                if (p.BuildPyramid(new PyramidData()))
                {
                    //On building the Pyramid
                    //Use Context Object to call the Strategy Method to Do the Calculation
                    ResultModel resultModel = p.WalkAndCalculate();

                    //Display the Result
                    if (null != resultModel)
                    {
                        resultModel.Display();
                    }
                }
                else
                {
                    Console.WriteLine("Building the Pyramid Failed");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occured: " + ex.Message.ToString());
            }
        }
        public void CheckInvalidPath()
        {
            string filePath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                            ConfigurationManager.AppSettings["relativeFilePath"].ToString() + "InvalidPathTest.txt"));

            PyramidContext pyramidContext = new PyramidContext();

            if (pyramidContext.BuildPyramid(new PyramidData(filePath)))
            {
                ResultModel resultModel = pyramidContext.WalkAndCalculate();

                //Display the Result
                if (null != resultModel)
                {
                    Assert.AreEqual(resultModel.path.Count, 0);
                }
            }
        }