Example #1
0
        public void Items_MaxDays_check()
        {
            AdultBook a = new AdultBook();
            ChildBook c = new ChildBook();
            DVD d = new DVD();
            VHS v = new VHS();

            Assert.AreEqual(14, a.maxDays());
            Assert.AreEqual(7, c.maxDays());
            Assert.AreEqual(2, d.maxDays());
            Assert.AreEqual(3, v.maxDays());
        }
Example #2
0
        public void Item_CheckOutValidation()
        {
            AdultBook a = new AdultBook();
            ChildBook c = new ChildBook();
            DVD d = new DVD();
            VHS v = new VHS();

            a.checkout("Tom");
            c.checkout("Dick");
            d.checkout("Harry");
            v.checkout("Mickey");

            Assert.AreEqual("Tom", a.whoCheckedOut);
            Assert.AreEqual("Dick", c.whoCheckedOut);
            Assert.AreEqual("Harry", d.whoCheckedOut);
            Assert.AreEqual("Mickey", v.whoCheckedOut);
        }
Example #3
0
        // Assumed C# will create default constructor and destructor
        public static void readFile()
        {
            string inputstring = null;
            StreamReader data = null;
            Stream myStream = null;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "c://";
            openFileDialog1.Filter = "bin files(*.bin)|*bin";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    data = new StreamReader(myStream);
                }
                else
                    throw new Exception("streamReader problem");
            }

            itemsList = new List<Item>();
            // populate items list
            try
            {
                string star = data.ReadLine();
                if (star != "*")
                    throw new FileLoadException("No Star found");
                do
                {
                    inputstring = data.ReadLine();
                    if (inputstring != "**")
                    {
                        string title = inputstring;
                        string category = data.ReadLine();
                        string whoCheckedout = data.ReadLine();
                        string tempInt = data.ReadLine();
                        bool checkStatus = (tempInt == "1") ? true : false;

                        // read in checkedout date
                        string time = data.ReadLine();
                        DateTime checkedOut = DateTime.Parse(time);

                        //read in duedate
                        time = data.ReadLine();
                        DateTime dueDate = DateTime.Parse(time);

                        // create a items object and push
                        // need items constructor
                        if (category == "AdultBook")
                        {

                            AdultBook temp = new AdultBook(title, checkStatus, whoCheckedout, checkedOut, dueDate);
                            itemsList.Add(temp);
                        }
                        else if (category == "ChildBook")
                        {
                            ChildBook temp = new ChildBook(title, checkStatus, whoCheckedout, checkedOut, dueDate);
                            itemsList.Add(temp);

                        }
                        else if (category == "DVD")
                        {
                            DVD temp = new DVD(title, checkStatus, whoCheckedout, checkedOut, dueDate);
                            itemsList.Add(temp);
                        }
                        else if (category == "VHS")
                        {
                            VHS temp = new VHS(title, checkStatus, whoCheckedout, checkedOut, dueDate);
                            itemsList.Add(temp);
                        }
                        else
                            throw new FileLoadException("invalid file");

                    }
                } while (inputstring != "**");

            patronsList = new List<Patron>();

                do
                {
                    inputstring = data.ReadLine();
                    if (inputstring == "***")
                        break;

                    string fname = inputstring;
                    string lname = data.ReadLine();
                    string category = data.ReadLine();
                    string numItems = data.ReadLine();

                    if (category == "Adult")
                    {
                        Adult temp = new Adult(fname, lname, int.Parse(numItems));
                        patronsList.Add(temp);
                    }
                    else
                    {
                        Child temp = new Child(fname, lname, int.Parse(numItems));
                        patronsList.Add(temp);
                    }

                } while (inputstring != "***");

                MessageBox.Show("File Loaded!!");
            }
            catch (Exception e)
            {
                data.Close();
                throw new FileLoadException("Unable to Load");
            }
            finally
            {
                myStream.Close();
            }
        }