Beispiel #1
0
        public void LoanTest()
        {
            const string userId = "164916";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserLoansXml());

            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual("530185", user.Loans.ElementAt(0).AdminisrtativeDocumentNumber);
            Assert.AreEqual("1001 filmer du må se før du dør", user.Loans.ElementAt(0).DocumentTitle);
            Assert.AreEqual("Hovedbiblioteket", user.Loans.ElementAt(0).SubLibrary);
            Assert.AreEqual("15.08.2012", user.Loans.ElementAt(0).OriginalDueDate);
            Assert.AreEqual("4 uker", user.Loans.ElementAt(0).ItemStatus);
            Assert.AreEqual("18.07.2012", user.Loans.ElementAt(0).LoanDate);
            Assert.AreEqual("15:04", user.Loans.ElementAt(0).LoanHour);
            Assert.AreEqual("15.08.2012", user.Loans.ElementAt(0).DueDate);
        }
Beispiel #2
0
        public void FineTest()
        {
            const string userId = "159222";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserXml());

            Assert.AreEqual("08.02.2007", user.Fines.ElementAt(0).Date);
            Assert.AreEqual("Ikke betalt ", user.Fines.ElementAt(0).Status);
            Assert.AreEqual('D', user.Fines.ElementAt(0).CreditDebit);
            Assert.AreEqual(30.00 , user.Fines.ElementAt(0).Sum);
            Assert.AreEqual("Nytt lånekort", user.Fines.ElementAt(0).Description);

            Assert.AreEqual(2, user.Fines.Count());
            Assert.AreEqual("19.03.2007", user.Fines.ElementAt(1).Date);
            Assert.AreEqual("For sent levert", user.Fines.ElementAt(1).Description);
            Assert.AreEqual("000230544", user.Fines.ElementAt(1).DocumentNumber);
            Assert.AreEqual("Gift", user.Fines.ElementAt(1).DocumentTitle);
        }
Beispiel #3
0
        public void PropertiesTest()
        {
            const string userId = "159222";
            var user = new UserInfo { BorrowerId = userId };
            user.FillProperties(getUserXml());
            Assert.AreEqual(userId, user.BorrowerId);
            Assert.AreEqual("STV000060009", user.Id);

            Assert.AreEqual("60.00", user.Balance);
            Assert.AreEqual("350.00", user.CashLimit);
            Assert.AreEqual("91562303", user.CellPhoneNumber);
            Assert.AreEqual("4019 STAVANGER", user.CityAddress);
            Assert.AreEqual("09.04.1989", user.DateOfBirth);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual("Hovedbibl.", user.HomeLibrary);
            Assert.AreEqual("51536695", user.HomePhoneNumber);
            Assert.AreEqual("Sindre Haaland", user.Name);
            Assert.AreEqual("Sindre Haaland", user.PrefixAddress);
            Assert.AreEqual("Bakkesvingen 8", user.StreetAddress);
            Assert.AreEqual("4019", user.Zip);
        }
Beispiel #4
0
        private IEnumerable<Notification> GetNotification(UserInfo user)
        {
            var notifications = new List<Notification>();

            if (user.Loans != null)
            {
                foreach (var loan in user.Loans)
                {
                    var day = Convert.ToInt32(loan.DueDate.Substring(0, 2));
                    var month = Convert.ToInt32(loan.DueDate.Substring(3, 2));
                    var year = Convert.ToInt32(loan.DueDate.Substring(6, 4));

                    var dueDate = new DateTime(year, month, day);
                    var today = DateTime.Now;

                    TimeSpan span = dueDate.Subtract(today);
                    var timeLeft = span.Days;

                    if (timeLeft > 0 && timeLeft < 4)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Loan",
                                                  Title = loan.DocumentTitle + " forfaller snart",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content =
                                                      "Lånet forfaller om mindre enn " + timeLeft +
                                                      " dager. Lever eller forny " +
                                                      "lånet for å unngå å få gebyr."
                                              });
                    }
                    else if (timeLeft == 0)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Loan",
                                                  Title = loan.DocumentTitle + " forfaller snart",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content = "Lånet forfaller om mindre ett døgn. Lever eller forny " +
                                                            "lånet for å unngå å få gebyr."
                                              });
                    }
                    else if (timeLeft < 0)
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Fine",
                                                  Title = loan.DocumentTitle + " skulle vært levert",
                                                  DocumentTitle = loan.DocumentTitle,
                                                  Content =
                                                      "Lånet har forfalt. Ved å fornye eller levere tilbake innen forfallsdato unngår du gebyr."
                                              });

                    }

                }

            }

            if (user.Reservations != null)
            {
                foreach (var reservation in user.Reservations)
                {
                    if (reservation.HoldRequestEnd != "")
                    {
                        notifications.Add(new Notification
                                              {
                                                  Type = "Reservation",
                                                  Title = reservation.DocumentTitle + " er klar til henting.",
                                                  DocumentTitle = reservation.DocumentTitle,
                                                  Content = "Den kan hentes på " + reservation.PickupLocation + " innen " + reservation.HoldRequestEnd,
                                              });
                    }
                }
            }

            return notifications;
        }
Beispiel #5
0
        private bool AuthenticateUser(ref UserInfo user, string userId, string verification)
        {
            const Operation function = Operation.AuthenticateUser;
            var options = new Dictionary<string, string> { { "bor_id", userId }, { "verification", verification } };

            var url = GetUrl(function, options);
            var authenticationDoc = RepositoryUtils.GetXmlFromStream(url);

            if (authenticationDoc != null && authenticationDoc.Root != null)
            {

                var xElement = authenticationDoc.Root.DescendantsAndSelf("z303").FirstOrDefault();
                user.IsAuthorized = xElement != null;

            }

            return user.IsAuthorized;
        }
Beispiel #6
0
        public UserInfo GetUserInformation(string userId, string verification)
        {
            var user = new UserInfo { BorrowerId = userId };
            AuthenticateUser(ref user, userId, verification);

            const Operation function = Operation.UserInformation;
            var options = new Dictionary<string, string> { { "bor_id", userId }, { "verification", verification } };
            var url = GetUrl(function, options);

            var userXDoc = RepositoryUtils.GetXmlFromStream(url);

            user.FillProperties(userXDoc.ToString());

            return user;
        }