示例#1
0
        public void SerializeGroup()
        {
            Group srcGroup = new Group("Test Group");
            Student stud = new Student("Mr. Stud");
            srcGroup.AddStudent(stud);

            string tempFileName = Path.GetTempFileName();
            FileStream fs = File.Create(tempFileName);
            XmlSerializer ser = new XmlSerializer(typeof(Group));
            ser.Serialize(fs, srcGroup);
            fs.Close();
            fs = File.OpenRead(tempFileName);
            Group newGroup = (Group)ser.Deserialize(fs);
            fs.Close();
            File.Delete(tempFileName);

            Assert.AreEqual(srcGroup.Name, newGroup.Name, "Names expected to be equal");
            Assert.AreEqual(srcGroup.ID, newGroup.ID, "IDs expected to be equal");
            Assert.AreEqual(srcGroup.Students.Count(), newGroup.Students.Count(), "Something wrong with studList serialization");

            Student savedMrStud = newGroup.Students.ElementAt(0);
            StringAssert.Equals(stud.Name, savedMrStud.Name);

            Storage.Data.Students.RemoveItem(stud);
        }
示例#2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            testUniver = new University("Test Uni");

            testGroup = new Group("TestGroup");
            testGroup.AddStudent(new Student("Mr. Brilliant"));
            testGroup.AddStudent(new Student("Mr. Diamond"));
            testGroup.AddStudent(new Student("Mr. Carbone"));
            testUniver.AddGroup(testGroup);

            testTeacher = new Teacher("Mr. Smartpants");

            testCourse = new Course("Very hard course");
            testUniver.AddCourse(testCourse);
            testTeacher.AddCourse(testCourse);
        }
示例#3
0
        public void StudentsOfGroup()
        {
            Group tempGroup = new Group("TestGroup");
            Student stud1 = new Student("Mr. First");
            Student stud2 = new Student("Mr. Second");
            Student stud3 = new Student("Mr. Third");
            tempGroup.AddStudent(stud1);
            Storage.Data.Students.AddItem(stud2);
            tempGroup.AddStudent(stud3);

            var resEnum = tempGroup.Students;
            var arr = resEnum.ToArray();
            Assert.AreEqual(2, arr.Length, "Two students expected to be in the group");
            Assert.AreEqual(stud1.ID, arr[0].ID, "There should be stud1");
            Assert.AreEqual(stud3.ID, arr[1].ID, "There should be stud3");

            Storage.Data.Students.RemoveItem(stud1);
            Storage.Data.Students.RemoveItem(stud2);
            Storage.Data.Students.RemoveItem(stud3);
        }
示例#4
0
 public void TestStudList()
 {
     Group newGroup = new Group();
     Assert.IsNotNull(newGroup.Students);
 }
示例#5
0
 public void TestIDs()
 {
     University newUni = new University("Best Uni ever");
     Assert.IsFalse(string.IsNullOrEmpty(newUni.ID), "Univer's constructor with parameters must generate an ID");
     Student newStud = new Student("Mr. Studoid");
     Assert.IsFalse(string.IsNullOrEmpty(newStud.ID), "Student's constructor with parameters must generate an ID");
     Group newGroup = new Group("Test Group");
     Assert.IsFalse(string.IsNullOrEmpty(newGroup.ID), "Group's constructor with parameters must generate an ID");
 }
示例#6
0
 /// <summary>
 /// Removes the link to the group.
 /// Group stays in the Storage
 /// </summary>
 /// <param name="group"></param>
 public void RemoveGroup(Group group)
 {
     group.UniverID = string.Empty;
 }
示例#7
0
 /// <summary>
 /// Sets the link between this university and passed group. 
 /// Also tries to add a group to the Storage if nessesary
 /// </summary>
 /// <param name="group">Group being linked to the university</param>
 public void AddGroup(Group group)
 {
     if (Storage.Data.Groups.GetItem(group.ID) == null)
         Storage.Data.Groups.AddItem(group);
     group.UniverID = ID;
 }