Exemple #1
0
        static void Main(string[] args)
        {
            _commonFactorService = new CommonFactorService();
            _addressService      = new AddressService();

            int[] testNumbers = new int[]
            {
                8, 12, 24, 32
            };

            var result = _commonFactorService.highestCommonFactor(testNumbers);

            Console.WriteLine("Given the following set of numbers:");
            var list = testNumbers.ToList();

            list.ForEach((x) =>
            {
                Console.WriteLine(x);
            });
            Console.WriteLine("The Highest common factor is " + result);
            //Get Data from JSON
            _addressService.loadAddresses().Wait();

            Console.WriteLine("All Addresses");
            PrintAllToConsole(_addressService.Addresses);
            Console.WriteLine();
            Console.WriteLine("Specific Address Types");
            PrintByType(_addressService.Addresses, "business");
            Console.WriteLine();
            Console.WriteLine("Show invalid Addresses");
            PrintAllToConsole(_addressService.Addresses, showInvalid: true);
            Console.WriteLine();
            Console.ReadLine();
        }
        public void TestInsertAddressWithStudent()
        {
            var student = new Student
            {
                FirstName = "xqwe",
                LastName = "yrtret",
                CNP = "1234567891234",
                SID = 123,
                EnrollmentDate = DateTime.Now,
                Phones = new[] { new Phone("0123 123456") }
            };

            var address = new Address
            {
                City = "New York",
                Country = "USA",
                State = "NYQ",
                PostalCode = "12345",
                Street = "Brooklyn 33",
                Student = student
            };

            student.Address = address;

            var res = Validation.Validate(address);
            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);
            }

            res = Validation.Validate(student);
            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);
            }

            using (var addressService = new AddressService())
            using (var studentService = new StudentService())
            {
                studentService.AddStudent(student);

                var lastid = student.StudentId;
                Trace.WriteLine(lastid);
                var lastAddress = addressService.GetAddressById(lastid);
                Assert.IsNotNull(lastAddress);
                Assert.AreNotEqual(student, lastAddress);

                Assert.AreEqual(student.StudentId, lastAddress.Student.StudentId);
                Assert.AreEqual(student.FirstName, lastAddress.Student.FirstName);
                Assert.AreEqual(student.LastName, lastAddress.Student.LastName);
                Assert.AreEqual(student.CNP, lastAddress.Student.CNP);
                Assert.AreEqual(student.SID, lastAddress.Student.SID);

                Assert.IsNotNull(student.Address);
                Assert.IsNotNull(lastAddress);
                Assert.AreEqual(student.Address.City, lastAddress.City);
                Assert.AreEqual(student.Address.Country, lastAddress.Country);
                Assert.AreEqual(student.Address.PostalCode, lastAddress.PostalCode);
                Assert.AreEqual(student.Address.State, lastAddress.State);
                Assert.AreEqual(student.Address.Street, lastAddress.Street);
                Assert.AreEqual(student.Address.StudentId, lastAddress.StudentId);

                //studentService.DeleteStudent(student.StudentId);
            }
        }