public static void GetWorkshopsFile()
        {
            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                fs = new FileStream("workshopInfo.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                sw = new StreamWriter(fs);

                List <Workshop> workshops = Data.GetWorkshops();

                fs.SetLength(0);

                foreach (var workshop in workshops.Where(w => w.GetType().Name == nameof(OnlineWorkshop)))
                {
                    OnlineWorkshop ws = (OnlineWorkshop)workshop;
                    string         teacher;
                    if (ws.Presenter != null)
                    {
                        teacher = ws.Presenter.FirstName + " " + ws.Presenter.LastName;
                    }
                    else
                    {
                        teacher = "None";
                    }
                    sw.WriteLine($"ONLINE(Title: {ws.Title}, Description: {ws.Description}, Teacher: {teacher}, Capacity: {ws.Capacity}, URL:{ws.URL})");
                }
                foreach (var workshop in workshops.Where(w => w.GetType().Name == nameof(InBuildingWorkshop)))
                {
                    InBuildingWorkshop ws = (InBuildingWorkshop)workshop;
                    string             teacher;
                    if (ws.Presenter != null)
                    {
                        teacher = ws.Presenter.FirstName + " " + ws.Presenter.LastName;
                    }
                    else
                    {
                        teacher = "None";
                    }
                    sw.WriteLine($"INBUILDING(Title:{ws.Title}, Description:{ws.Description}, Teacher:{teacher}, Capacity:{ws.Capacity}, Location: {ws.Address} {ws.RoomNumber}) ");
                    //var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                    //path = path.Substring(6);
                }
                Process.Start("notepad.exe", "workshopInfo");
            }
            catch (IOException)
            {
                MessageBox.Show("Error writing file");
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
        }
        public void RemoveParticipant_Throws_Exception()
        {
            var    workshop = new InBuildingWorkshop("test", "testDescription", 10, "Whateverstraat, 42", 21);
            Person person   = new Student("Cristian", "Tirotta", 449204);

            workshop.RemoveParticipant(person);

            Assert.Fail();
        }
        public void AddParticipantToInBuildingWorkshop()
        {
            var    workshop = new InBuildingWorkshop("test", "testDescription", 10, "Whateverstraat, 42", 21);
            Person person   = new Student("Cristian", "Tirotta", 449204);

            workshop.AddParticipant(person);

            CollectionAssert.Contains(workshop.GetParticipants(), person);
        }
Beispiel #4
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            //Get workshop data
            string title       = tbxTitle.Text;
            string description = rtbDescription.Text;
            int    capacity    = (int)numCapacity.Value;

            //Create a new workshop

            try
            {
                Workshop ws = null;
                if (!String.IsNullOrEmpty(title) || !String.IsNullOrEmpty(description) || capacity > 0)
                {
                    if (rbInBuilding.Checked)
                    {
                        string address    = tbxAddress.Text;
                        int    roomNumber = (int)numRoomNumber.Value;
                        if (String.IsNullOrEmpty(address) || roomNumber <= 0)
                        {
                            throw new ArgumentException("Please provide valid address and room number values");
                        }
                        ws = new InBuildingWorkshop(title, description, capacity, address, roomNumber);
                    }
                    else if (rbOnline.Checked)
                    {
                        string url = tbxURL.Text;
                        if (String.IsNullOrEmpty(url))
                        {
                            throw new ArgumentException("URL cannot be null or empty");
                        }
                        ws = new OnlineWorkshop(title, description, capacity, url);
                    }
                    else
                    {
                        MessageBox.Show($"Please select a workshop type (Online/In Building)");
                        return;
                    }
                    //Add to list
                    this.workshops.Add(ws);
                    Data.UpdateWorkshops(this.workshops);
                    Dashboard dashboard = new Dashboard();
                    this.Hide();
                    dashboard.ShowDialog();
                }
                else
                {
                    MessageBox.Show($"Please fill all the required fields.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void AddAlreadyExistingParticipant()
        {
            var    workshop = new InBuildingWorkshop("test", "testDescription", 10, "Whateverstraat, 42", 21);
            Person person   = new Student("Cristian", "Tirotta", 449204);

            workshop.AddParticipant(person);
            workshop.AddParticipant(person);

            Assert.Fail();
        }
        public void AddToUnavailableWorkshop()
        {
            var    workshop = new InBuildingWorkshop("test", "testDescription", 1, "Whateverstraat, 42", 21);
            Person student  = new Student("Cristian", "Tirotta", 449204);
            Person teacher  = new Teacher("Mark", "Zuckerberg", 123940);

            workshop.AddParticipant(student);
            workshop.AddParticipant(teacher);

            Assert.Fail();
        }