Пример #1
0
        public void ArchivePersonTest()
        {
            var target = new PersonsDAO();

            var actual = target.CreatePerson("Test" + new Random().Next(), "Test" + new Random().Next(), "076/482.04.78", "*****@*****.**", department);

            target.ArchivePerson(actual);

            var person = target.GetPersonByID(actual);

            Assert.IsNotNull(person, "Person must not be null");
            Assert.AreEqual(true, person.Archived, "The person must be archived");
        }
Пример #2
0
        public void CreatePersonTest()
        {
            var target = new PersonsDAO();

            var name = "Test" + new Random().Next();
            var actual = target.CreatePerson("New", name, "076/482.04.78", "*****@*****.**", department);

            Assert.IsTrue(actual > 0, "The id must be greater than 0");

            var created = target.GetPersonByID(actual);

            Assert.AreEqual(name, created.Name, "Values must be the same");
            Assert.AreEqual("New", created.FirstName, "Values must be the same");
            Assert.AreEqual("076/482.04.78", created.Phone, "Values must be the same");
            Assert.AreEqual("*****@*****.**", created.Email, "Values must be the same");
            Assert.AreEqual(department, created.Department.Id, "Values must be the same");
            Assert.AreEqual(false, created.Archived, "Values must be the same");
        }
Пример #3
0
        public void SavePersonTest()
        {
            var target = new PersonsDAO(); // TODO: Initialize to an appropriate value

            var actual = target.CreatePerson("Test" + new Random().Next(), "Test" + new Random().Next(), "076/482.04.78", "*****@*****.**", department);

            var firstname = "Test" + new Random().Next();
            var name = "Test" + new Random().Next();
            var phone = "076/482.04.79";
            var email = "*****@*****.**";

            using(var connection = DBManager.GetInstance().GetNewConnection())
            {
                var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                target.SavePerson(actual, firstname, name, phone, email, department, transaction);

                transaction.Commit();
            }

            var result = target.GetPersonByID(actual);

            Assert.AreEqual(name, result.Name, "Values must be the same");
            Assert.AreEqual(firstname, result.FirstName, "Values must be the same");
            Assert.AreEqual(phone, result.Phone, "Values must be the same");
            Assert.AreEqual(email, result.Email, "Values must be the same");
        }
Пример #4
0
        public void GetPersonByIDTest()
        {
            var target = new PersonsDAO();

            var actual = target.GetPersonByID(-1);
            Assert.IsNull(actual, "This person must not exists");

            //This method is already tested for correctness in CreatePersonTest
        }
Пример #5
0
        /// <summary>
        /// Create a XMLDocument with contract field
        /// </summary>
        /// <returns>A XMLDocument</returns>
        private XmlDocument createXML()
        {
            var departmentTab = new int[PersonSelectedList.Items.Count + DepartmentSelectedList.Items.Count];
            var index = 0;

            var xmlDoc = new XmlDocument();

            // Write down the XML declaration
            var xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-16", null);

            // Create the root element
            var rootNode = xmlDoc.CreateElement("contract");
            rootNode.SetAttribute("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "contract.xsd");

            rootNode.SetAttribute("title", TitleText.Text);
            rootNode.SetAttribute("startDate", StartDate.Text);
            rootNode.SetAttribute("endDate", EndDate.Text);
            rootNode.SetAttribute("contractType", ContractTypeList.SelectedValue);
            rootNode.SetAttribute("authorLogin", "");

            xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
            xmlDoc.AppendChild(rootNode);

            using (var connection = DBManager.GetInstance().GetNewConnection())
            {
                var contactsNode = xmlDoc.CreateElement("contacts");
                xmlDoc.DocumentElement.PrependChild(contactsNode);

                var personsDAO = new PersonsDAO();
                for (var i = 0; i < PersonSelectedList.Items.Count; i++)
                {
                    var w = PersonSelectedList.Items[i].Value.Split(';');
                    var person = personsDAO.GetPersonByID(w[0].ToInt(), connection);
                    var personNode = xmlDoc.CreateElement("person");
                    personNode.SetAttribute("name", person.Name);
                    personNode.SetAttribute("firstName", person.FirstName);
                    personNode.SetAttribute("phone", person.Phone);
                    personNode.SetAttribute("departmentId", person.Department.Id.ToString());
                    personNode.SetAttribute("role", w[1]);

                    departmentTab[index++] = w[0].ToInt();
                    contactsNode.AppendChild(personNode);
                }

                var destinationsNode = xmlDoc.CreateElement("destinations");
                xmlDoc.DocumentElement.PrependChild(destinationsNode);

                for (var i = 0; i < DepartmentSelectedList.Items.Count; i++)
                {
                    var id = DepartmentSelectedList.Items[i].Value.ToInt();

                    var destinationNode = xmlDoc.CreateElement("destination");
                    destinationNode.SetAttribute("id", id.ToString());
                    destinationsNode.AppendChild(destinationNode);

                    departmentTab[index++] = id;
                }

                var institutionsDAO = new InstitutionsDAO();

                var departmentsNode = xmlDoc.CreateElement("departments");
                xmlDoc.DocumentElement.PrependChild(departmentsNode);
                foreach (var id in departmentTab)
                {
                    var d = institutionsDAO.GetDepartmentById(id, connection);
                    var departmentNode = xmlDoc.CreateElement("department");
                    departmentNode.SetAttribute("id", d.Id.ToString());
                    departmentNode.SetAttribute("name", d.Name);
                    departmentNode.SetAttribute("institutionName", d.InstitutionName);
                    departmentNode.SetAttribute("institutionCity", d.InstitutionCity);
                    departmentNode.SetAttribute("institutionLanguage", d.InstitutionLanguage);
                    departmentNode.SetAttribute("institutionCountry", d.InstitutionCountry);

                    departmentsNode.AppendChild(departmentNode);
                }
            }

            return xmlDoc;
        }
Пример #6
0
        private void WriteDocument(Document document, IEnumerable<string> contracts, IEnumerable<string> persons)
        {
            var title = "Historique " + Request.QueryString["year"];

            document.AddTitle(title);

            document.Add(new Paragraph(title, new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD)));

            var subtitleFont = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD);

            using(var connection = DBManager.GetInstance().GetNewConnection())
            {
                var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                document.Add(new Paragraph(" ", subtitleFont));
                document.Add(new Paragraph("Contrats", subtitleFont));

                var contractsDAO = new ContractsDAO();

                var contractsData = contracts.Select(contract => contract.ToInt()).Aggregate("<ul>", (current, id) => current + ("<li>" + contractsDAO.GetContractById(id, transaction) + "</li>")) + "</ul>";

                ParseHtml(document, contractsData);

                document.Add(new Paragraph(" ", subtitleFont));
                document.Add(new Paragraph("Personnes", subtitleFont));

                var personsDAO = new PersonsDAO();

                var personsData = persons.Select(person => person.ToInt()).Aggregate("<ul>", (current, id) => current + ("<li>" + personsDAO.GetPersonByID(id, transaction) + "</li>")) + "</ul>";

                ParseHtml(document, personsData);

                transaction.Commit();
            }
        }