public void DeletePhone(Phone phone) { Contract.Requires<ArgumentNullException>(phone != null, "The phone must be non-null!"); using (var context = new SchoolContext()) { try { context.Phones.Attach(phone); context.Phones.Remove(phone); if (context.SaveChanges() != 0) { /* Logger.Write("The phone " + phone + " was successfully removed!", "General", 2, 2, TraceEventType.Information); * */ }/* else { Logger.Write("The phone " + phone + " was not removed!", "Important", 1, 1, TraceEventType.Error); }*/ } catch { throw new NoSuchEntityException("The semester with the id=" + phone + " does not exist in the database"); } } }
public void DeletePhone(int phoneId) { Contract.Requires<ArgumentOutOfRangeException>(phoneId > 0, "The phoneId must be > 0!"); using (var context = new SchoolContext()) { var phoneToBeDeleted = new Phone() { PhoneId = phoneId }; try { context.Phones.Attach(phoneToBeDeleted); context.Phones.Remove(phoneToBeDeleted); if (context.SaveChanges() != 0) { /* Logger.Write("The phone " + phoneToBeDeleted + " was successfully removed!", "General", 2, 2, TraceEventType.Information); * */ }/* else { Logger.Write("The phone " + phoneToBeDeleted + " was not removed!", "Important", 1, 1, TraceEventType.Error); }*/ } catch { throw new NoSuchEntityException("The semester with the id=" + phoneToBeDeleted + " does not exist in the database"); } } }
public void AddPhone(Phone phone) { Contract.Requires<ArgumentNullException>(phone != null, "The phone must be non-null!"); using (var context = new SchoolContext()) { context.Phones.Add(phone); if (context.SaveChanges() != 0) { /* Logger.Write("The phone: " + phone + " was successfully inserted!", "General", 2, 2, TraceEventType.Information); * */ }/* else { Logger.Write("The phone: " + phone + " was not inserted!", "Important", 1, 1, TraceEventType.Error); }*/ } }
public void DeletePhoneByObjectNoSuchEntity() { //create entity instance var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student, }; var phone2 = new Phone() { PhoneNumber = "1234 567890", Student = student, }; //insert entity //_phoneService.AddPhone(phone); var res = Validation.Validate(student); Assert.AreEqual(res.IsValid, true); res = Validation.Validate(phone); Assert.AreEqual(res.IsValid, true); //change entity properties;update entity int lastInsertedStudentId = phone.PhoneId; _phoneService.DeletePhone(phone); }
public void UpdatePhoneByObjectNullPhoneNumber() { //create entity instance var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student, }; var phone2 = new Phone() { PhoneNumber = "1234 567890", Student = student, }; //insert entity _phoneService.AddPhone(phone); var res = Validation.Validate(student); Assert.AreEqual(res.IsValid, true); res = Validation.Validate(phone); Assert.AreEqual(res.IsValid, true); //change entity properties;update entity int lastInsertedStudentId = phone.PhoneId; var updatedStudent1 = _phoneService.UpdatePhone(phone.PhoneId, (String) null); //read updated entity Phone updateStudent2 = _phoneService.GetPhoneById(lastInsertedStudentId); //compare changed entity and read entity Assert.AreEqual(updatedStudent1.PhoneNumber, updateStudent2.PhoneNumber); Assert.AreEqual(updatedStudent1.PhoneNumber, phone2.PhoneNumber); Assert.AreEqual(updateStudent2.PhoneNumber, phone2.PhoneNumber); //delete entity _phoneService.DeletePhone(lastInsertedStudentId); }
public void TestValidPhoneNumber() { var phone = new Phone("0134 123456"); var res = Validation.Validate(phone); Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.Single().Message); if (!res.IsValid) { var singleOrDefault = res.SingleOrDefault(); if (singleOrDefault != null) Trace.WriteLine(singleOrDefault.Message); } }
public void TestIsPhoneInsertedFail() { var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student }; _phoneService.AddPhone(phone); Assert.IsTrue(_phoneService.IsPhoneInserted(-123)); }
public void TestGetPhoneById() { var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student }; _phoneService.AddPhone(phone); var phoneAdded = _phoneService.GetPhoneById(phone.PhoneId); Assert.AreEqual(phoneAdded.PhoneId, phone.PhoneId); Assert.AreEqual(phoneAdded.PhoneNumber, phone.PhoneNumber); }
public void TestGetAllPhones() { var oldCount = _phoneService.GetAllPhones().Count; var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student }; _phoneService.AddPhone(phone); Assert.AreEqual(oldCount + 1, _phoneService.GetAllPhones().Count); }
public void TestDeletePhoneObjectSuccess() { var student = new Student { FirstName = "xqwe", LastName = "ywqe", CNP = "1234567891215", SID = 22, Emails = new[] { new Email("*****@*****.**") }, EnrollmentDate = DateTime.UtcNow }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student }; _phoneService.AddPhone(phone); _phoneService.DeletePhone(phone); Assert.IsNull(_phoneService.GetPhoneById(phone.PhoneId)); }
public void TestAddPhoneSuccess() { var student = new Student { FirstName = "firstname1", LastName = "lastname1", CNP = "1234567891234", SID = 123, EnrollmentDate = DateTime.Now, Emails = new[] { new Email("*****@*****.**") } }; var phone = new Phone() { PhoneNumber = "0123 123456", Student = student }; using (var es = new PhoneService()) using (var st = new StudentService()) { es.AddPhone(phone); var res = Validation.Validate(phone); Assert.AreEqual(res.IsValid, true, res.IsValid ? "" : "Validation Failed: " + res.First().Message); if (!res.IsValid) { var firstOrDefault = res.FirstOrDefault(); if (firstOrDefault != null) Trace.WriteLine(firstOrDefault.Message); } var stud = st.GetStudentById(student.StudentId); Assert.AreEqual(stud.StudentId, student.StudentId); Assert.IsTrue(stud.Phones.Any(e => e.PhoneNumber == phone.PhoneNumber)); } }
public Phone UpdatePhone(int phoneId, Phone phone) { Contract.Requires<ArgumentOutOfRangeException>(phoneId > 0, "The phoneId must be > 0!"); Contract.Requires<ArgumentNullException>(phone != null, "The phone must be non-null!"); using (var context = new SchoolContext()) { var phoneToBeUpdated = context.Phones.SingleOrDefault(p => p.PhoneId == phoneId); if (phoneToBeUpdated != null) { phoneToBeUpdated.PhoneNumber = phone.PhoneNumber; if (context.SaveChanges() != 0) { /* Logger.Write("The phone " + phoneToBeUpdated + " was successfully updated!", "General", 2, 2, TraceEventType.Information); * */ }/* else { Logger.Write("The phone " + phoneToBeUpdated + " was not updated!", "Important", 1, 1, TraceEventType.Error); }*/ return phoneToBeUpdated; } Logger.Write("The phone with id: " + phoneId + " doesn't exist in the database!", "Important", 1, 1, TraceEventType.Error); throw new NoSuchEntityException("The phone with id: " + phoneId + " doesn't exist in the database!"); } }
public Phone UpdatePhone(int phoneId, Phone phone) { return DataMapperFactory.GetMapperFactory().PhoneMapper.UpdatePhone (phoneId, phone); }
public void DeletePhone(Phone phone) { DataMapperFactory.GetMapperFactory().PhoneMapper.DeletePhone(phone); }
// Create public void AddPhone(Phone phone) { DataMapperFactory.GetMapperFactory().PhoneMapper.AddPhone(phone); }