public void createBoatTest()
        {
            NarrowBoat NB = new NarrowBoat();

            NB.BoatDraft   = 3;
            NB.BoatLength  = 15;
            NB.NameOfBoat  = "Phantom Menance";
            NB.NameOfOwner = "Anakin Skywalker";
            MarinaMaintenanceObj MarinaMaintenance_Obj = new MarinaMaintenanceObj();
            Marina Marina = new Marina();

            Marina.ClearAllMarinaItems();
            //add new boat to marina
            Marina.addBoatToMarina(NB);
            List <string> listData = new List <string>();

            listData = Marina.convertMarinaToList();
            //write to  file

            FileOperations FP = new FileOperations();

            FP.writeToFile(listData);
            int index = Marina.getCurrentCapacityMarinaLength();

            List <string> list = new List <string>();

            list = FP.readDataFromFile();


            string nameOflastBoatInList = list.Last();

            //split array at commas and put result into an array
            string[] arrSplitRow = nameOflastBoatInList.Split(",".ToCharArray());
            string   actual      = arrSplitRow[1];

            Assert.AreEqual(actual.ToUpper(), NB.NameOfOwner.ToUpper());
        }
Beispiel #2
0
        public Boat createBoat()
        {
            int    boatLen      = 0;
            int    boatType     = 0;
            int    boatDraft    = 0;
            string strBoatOwner = string.Empty;
            string strBoatName  = string.Empty;


            Boat Boat = null;

            while (true)
            {
                Console.WriteLine("Enter Boat Length");
                string strBoatLength = Console.ReadLine();
                if (!string.IsNullOrEmpty(strBoatLength))
                {
                    int.TryParse(strBoatLength, out boatLen);
                }
                if (boatLen < 1)
                {
                    Console.WriteLine("Boat Length Cannot be less tha 1 meter");
                }
                if (boatLen > marinaLength || boatLen < 1)
                {
                    Console.WriteLine("Boat Length Cannot be Greater than Marina Length or less than 1 meter");
                }
                //else if(boatLen>(Marina.getCurrentCapacityMarinaLength()-Marina.MarinaLength))
                else if (boatLen > (marinaLength - Marina.getCurrentCapacityMarinaLength()))
                {
                    throw new ArgumentException("The current marina capacity of " + Marina.getCurrentCapacityMarinaLength().ToString() + " will not be enough to accomodate this boat");
                }
                else
                {
                    break;
                }
            }
            while (true)
            {
                Console.WriteLine("Enter Boat Draft");
                string strBoatDraft = Console.ReadLine();
                if (!string.IsNullOrEmpty(strBoatDraft))
                {
                    int.TryParse(strBoatDraft, out boatDraft);
                }
                if (boatDraft < 1)
                {
                    Console.WriteLine("Boat Draft Cannot be less tha 1 meter");
                }
                if (boatDraft > 5 || boatDraft < 1)
                {
                    Console.WriteLine("Boat Draft Cannot be Greater than 5 meters or less than 1 meter");
                }
                else
                {
                    break;
                }
            }
            //check reservation here
            bool proceed = calculateBoatResrvation();

            if (proceed)
            {
                while (true)
                {
                    Console.WriteLine("Enter Boat Owner");
                    strBoatOwner = Console.ReadLine();
                    if (!string.IsNullOrEmpty(strBoatOwner))
                    {
                        break;
                    }
                }

                while (true)
                {
                    Console.WriteLine("Enter Boat Name");
                    strBoatName = Console.ReadLine();
                    if (!string.IsNullOrEmpty(strBoatName))
                    {
                        break;
                    }
                }



                Console.WriteLine("Choose Boat Type:");
                while (true)
                {
                    try
                    {
                        boatType = DisplayManager.displayBoatTypesMenu();
                        break;
                    }
                    catch (Exception ex)
                    {
                        DisplayManager.displayMessage(ex.Message);
                    }
                }


                switch (boatType)
                {
                case 1:

                    MotorBoat MB        = (Factory.MotorBoat)BoatFactory.BuildBoat(boatType);
                    int       mbSubtype = BoatFactory.BuildBoatSubTypes(boatType);
                    MB.DriveType = MB.GetEnumNameFromValue(mbSubtype);
                    Boat         = MB;
                    break;

                case 2:

                    // NarrowBoat NB = new NarrowBoat("NarrowBoat", boatType);
                    NarrowBoat NB        = (Factory.NarrowBoat)BoatFactory.BuildBoat(boatType);
                    int        nbSubtype = BoatFactory.BuildBoatSubTypes(boatType);
                    NB.SternType = NB.GetEnumNameFromValue(nbSubtype);
                    Boat         = NB;
                    break;

                case 3:

                    //SailingBoat SB = new SailingBoat("Sailing", boatType);
                    SailingBoat SB        = (Factory.SailingBoat)BoatFactory.BuildBoat(boatType);
                    int         sbSubtype = BoatFactory.BuildBoatSubTypes(boatType);
                    SB.SailingType = SB.GetEnumNameFromValue(sbSubtype);
                    Boat           = SB;
                    break;

                default:
                    break;
                }

                if (Boat != null)
                {
                    Boat.BoatLength  = boatLen;
                    Boat.NameOfBoat  = strBoatName;
                    Boat.NameOfOwner = strBoatOwner;
                    Boat.BoatDraft   = boatDraft;
                    Factory.BoatHelperClass.showDetails(Boat);
                }
            }
            else
            {
                throw new Exception("User terminated Booking transaction");
            }



            return(Boat);
        }