public void Initialize()
        {
            order = new Order();
            order.OrderEntries = null;
            order.SentDate = DateTime.Now;
            order.Id = 10;
            order.User = null;
            userAcc = new UserAccount();
            userAcc.Id = 5;
            orders = new List<Order>();
            orderManagementDaoMock = _factory.CreateMock<IOrderManagementDao>();
            oms.OrderManagementDao = orderManagementDaoMock.MockObject;

            //    NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders = new List<Order>(){order}));
              //  orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            orderInformationDaoMock = _factory.CreateMock<IOrderInformationsDao>();
            ois.OrderInformationDao = orderInformationDaoMock.MockObject;

            orderInformationDaoMock.Expects.Any.MethodWith<Order>(x => x.GetOrderById(order.Id)).WillReturn(order);
            orderInformationDaoMock.Expects.Any.MethodWith<Order>(x => x.GetOrderById(-1)).WillReturn(null);
               // orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(-1)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));
            orderInformationDaoMock.Expects.Any.Method(x => x.GetUndeliveredOrders()).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED));
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetUndeliveredByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));
            //orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetDeliveredOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status == Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));
        }
        public void CreateBaseUsers()
        {
            if(ServiceLocator.UserInformationService.GetUserAccountById(ApplicationScope.AdministratorId) == null) {
                UserAccount administratorAccont = new UserAccount()
                {
                    Login = ApplicationScope.AdministratorLogin,
                    Password = ServiceLocator.AuthorizationService.EncryptPassword(ApplicationScope.AdministratorPassword),
                    ValidFrom = DateTime.MinValue,
                    ValidTo = DateTime.MaxValue
                };
                ServiceLocator.AccountAdministrationService.SaveOrUpdateUser(administratorAccont);
            }

            if (ServiceLocator.UserInformationService.GetUserAccountById(ApplicationScope.WorkerId) == null)
            {
                UserAccount workerAccount = new UserAccount()
                {
                    Login = ApplicationScope.WorkerLogin,
                    Password = ServiceLocator.AuthorizationService.EncryptPassword(ApplicationScope.WorkerPassword),
                    ValidFrom = DateTime.MinValue,
                    ValidTo = DateTime.MaxValue
                };
                ServiceLocator.AccountAdministrationService.SaveOrUpdateUser(workerAccount);
            }
        }
Example #3
0
 public LogInOutEvent(UserAccount account, String ipAddress, ActionType type)
 {
     this.UserAccount = account;
     this.IpAddress = ipAddress;
     this.GeneratedOn = DateTime.Now;
     this.Type = type;
 }
Example #4
0
 public UserAccount UserAccountHelper(UserAccount userAccount)
 {
     userAccount.AccountStatus = SpringMvc.Models.POCO.UserAccount.Status.ACTIVE;
     userAccount.Login = AuthorizationTestData.LOGIN;
     userAccount.Password = AuthorizationTestData.PASSWORD;
     userAccount.PersonalData = PersonalDataHelper();
     return userAccount;
 }
Example #5
0
 public void SaveSuccessfulLogInEventForUser(UserAccount userAccount, string ipAddress)
 {
     this.Session.Save(new LogInOutEvent()
     {
         GeneratedOn = DateTime.Now,
         UserAccount = userAccount,
         IpAddress = ipAddress,
         Type = LogInOutEvent.ActionType.LOGIN_SUCCESSFUL
     });
 }
Example #6
0
 public void SaveLogOutEventForUser(UserAccount userAccount, string ipAddress)
 {
     this.Session.Save(new LogInOutEvent()
     {
         GeneratedOn = DateTime.Now,
         UserAccount = userAccount,
         IpAddress = ipAddress,
         Type = LogInOutEvent.ActionType.LOGOUT
     });
 }
        public void CheckedLoggedAccount()
        {
            authorizationService.AuthorizationDao = authorizationDaoMock.MockObject;
            authorizationService.LogEventsDao = logInOutEventDaoMock.MockObject;

            UserAccount user1 = new UserAccount();
            user1.Password = password;
            user1.Login = login;
            Assert.IsNotNull(user1);
            UserAccount user2 = new UserAccount();
            user2.Password = password2;
            user2.Login = login2;
            Assert.IsNotNull(user2);

            user1.Password = Encrypt(user1.Password);
            user2.Password = Encrypt(user2.Password);

            List<UserAccount> loggedUsers = new List<UserAccount>();

            NMock.Actions.InvokeAction akcja2 = new NMock.Actions.InvokeAction( new Action( () => loggedUsers.Add(user2)));
            NMock.Actions.InvokeAction akcja = new NMock.Actions.InvokeAction(new Action(() => loggedUsers.Add(user1)));

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login, password)).Will(akcja, new NMock.Actions.ReturnAction<UserAccount>(user1)); // WillReturn(user1);

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login2, password2)).Will(akcja2, new NMock.Actions.ReturnAction<UserAccount>(user2)); // WillReturn(user2);

            authorizationService.LoginUser(login, password);
            authorizationService.LoginUser(login2, password2);

            authorizationDaoMock.Expects.Any.Method(x => x.GetLoggedUsers()).WillReturn(loggedUsers);

            IEnumerable<UserAccount> LoggedAccounts = authorizationService.AllLoggedUserAccounts;
            Assert.AreEqual((new LinkedList<UserAccount>(LoggedAccounts)).Count, 2);
        }
 public long RegisterUser(UserAccount newUserAccount)
 {
     if (validateUniqueLogin(newUserAccount.Login) == false)
     {
         return 0;
     }
     newUserAccount.Password = EncryptPassword(newUserAccount.Password);
     newUserAccount.AccountStatus = UserAccount.Status.ACTIVE;
     newUserAccount.LastPasswordChangedDate = DateTime.Now;
     newUserAccount.ValidFrom = DateTime.Now;
     newUserAccount.ValidTo = new DateTime(newUserAccount.ValidFrom.Year + 1, newUserAccount.ValidFrom.Month, newUserAccount.ValidFrom.Day);
     return AuthorizationDao.RegisterUser(newUserAccount);
 }
 private UserAccount GenerateDatesForUserWithStatus(UserAccount.Status status, UserAccount user)
 {
     user.AccountStatus = status;
     if (status == UserAccount.Status.ACTIVE || status == UserAccount.Status.LOCKED_OUT)
     {
         int rand = new Random().Next(30);
         user.LastPasswordChangedDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(rand));
         user.LastSuccessfulSignInDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(rand - rand % 10));
         user.ValidTo = DateTime.Now.Date.AddDays(rand + 31);
         user.ValidFrom = DateTime.Now.Date.Subtract(TimeSpan.FromDays((rand % 5) * rand + 31));
     }
     else if (status == UserAccount.Status.REMOVED)
     {
         int rand = new Random().Next(61);
         user.LastPasswordChangedDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(3 * 31 + rand + rand % 10));
         user.LastSuccessfulSignInDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(3 * 31 + rand % 31));
         user.ValidTo = DateTime.Now.Date.Subtract(TimeSpan.FromDays(31 + rand % 31));
         user.ValidFrom = DateTime.Now.Date.Subtract(TimeSpan.FromDays(93 + 2 * ((rand % 4) + 1) * rand));
     }
     else
     {
         int rand = new Random().Next(61);
         user.LastPasswordChangedDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(31 + rand + rand % 10));
         user.LastSuccessfulSignInDate = DateTime.Now.Date.Subtract(TimeSpan.FromDays(31 + rand % 31));
         user.ValidTo = DateTime.Now.Date.Subtract(TimeSpan.FromDays(rand % 31));
         user.ValidFrom = DateTime.Now.Date.Subtract(TimeSpan.FromDays(62 + 2 * ((rand % 3) + 1) * rand));
     }
     return user;
 }
        public List<UserAccount> GenerateUsers(List<PersonalData> userPersonalDataList)
        {
            List<UserAccount> users = new List<UserAccount>();

            for (int index = 0; index < firstNames.Length; index++)
            {
                int rand = new Random().Next(30);
                UserAccount user = new UserAccount()
                {
                    Login = firstNames[index] + lastNames[index],
                    Password = AuthorizationService.EncryptPassword(lastNames[index]),
                    Email = firstNames[index].ToLower() + lastNames[index].ToLower() + "@mail.com",
                    PersonalData = userPersonalDataList.ElementAt(index),
                };
                switch (index % 10)
                {
                    case 7:
                        user = GenerateDatesForUserWithStatus(UserAccount.Status.EXPIRED, user);
                        break;
                    case 8:
                        user = GenerateDatesForUserWithStatus(UserAccount.Status.REMOVED, user);
                        break;
                    case 9:
                        user = GenerateDatesForUserWithStatus(UserAccount.Status.LOCKED_OUT, user);
                        break;
                    default:
                        user = GenerateDatesForUserWithStatus(UserAccount.Status.ACTIVE, user);
                        break;
                }
                users.Add(user);
            }
            return users;
        }
 public ActionResult Edit(UserAccount model)
 {
     ServiceLocator.AccountManagementService.EditUserPersonalData((long)Session["LoggedUserId"], model.PersonalData);
     return RedirectToAction("Index", "UserAccountPanel");
 }
Example #12
0
        public string BuildInvoice(Order orderDetails, UserAccount userDetails, Invoice invoice)
        {
            BaseFont f_cb = BaseFont.CreateFont("c:\\windows\\fonts\\calibrib.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            BaseFont f_cn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            try {

                string currentDate = DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString();
                string projectPath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
                string invoiceName = "Invoice_" + orderDetails.Id.ToString() + "_" + currentDate + ".pdf";
                using (System.IO.FileStream fs = new FileStream(projectPath + "\\Tmp\\" + invoiceName, FileMode.Create))
                {
                    Document document = new Document(PageSize.A4, 25, 25, 30, 1);
                    PdfWriter writer = PdfWriter.GetInstance(document, fs);

                    document.AddAuthor("BookStore");
                    document.AddTitle("Customer Invoice - order id:" + orderDetails.Id.ToString());
                    document.Open();

                    PdfContentByte cb = writer.DirectContent;
                    iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(projectPath + "\\Images\\logo.png");
                    png.ScaleAbsolute(200, 55);
                    png.SetAbsolutePosition(40, 750);
                    cb.AddImage(png);
                    cb.BeginText();

                    writeText(cb, "BookStore Invoice", 350, 820, f_cb, 14);
                    writeText(cb, "Invoice Id", 350, 800, f_cb, 10);
                    writeText(cb, invoice.Id.ToString(), 420, 800, f_cn, 10);
                    writeText(cb, "Order date", 350, 788, f_cb, 10);
                    writeText(cb, orderDetails.OrderDate.ToString(), 420, 788, f_cn, 10);
                    writeText(cb, "Order Id", 350, 776, f_cb, 10);
                    writeText(cb, orderDetails.Id.ToString(), 420, 776, f_cn, 10);
                    writeText(cb, "Customer Id", 350, 764, f_cb, 10);
                    writeText(cb, orderDetails.User.Id.ToString(), 420, 764, f_cn, 10);

                    int left_margin = 40;
                    int top_margin = 720;
                    writeText(cb, "Delivery address", left_margin, top_margin, f_cb, 10);
                    writeText(cb, userDetails.PersonalData.FirstName
                        + " " + userDetails.PersonalData.LastName, left_margin, top_margin-12, f_cn, 10);
                    writeText(cb, userDetails.PersonalData.Address.Street, left_margin, top_margin-24, f_cn, 10);
                    writeText(cb, userDetails.PersonalData.Address.PostalCode
                        + " " + userDetails.PersonalData.Address.City, left_margin, top_margin-36, f_cn, 10);
                    writeText(cb, userDetails.PersonalData.Address.Country, left_margin, top_margin-48, f_cn, 10);

                    left_margin = 350;
                    writeText(cb, "Invoice address", left_margin, top_margin, f_cb, 10);
                    writeText(cb, ApplicationScope.CompanyName, left_margin, top_margin - 12, f_cn, 10);
                    writeText(cb, ApplicationScope.CompanyStreet, left_margin, top_margin - 24, f_cn, 10);
                    writeText(cb, ApplicationScope.CompanyPostalCode + " " + ApplicationScope.CompanyCity,
                        left_margin, top_margin - 36, f_cn, 10);
                    writeText(cb, ApplicationScope.CompanyCountry, left_margin, top_margin - 48, f_cn, 10);

                    cb.EndText();
                    cb.SetLineWidth(0f);
                    cb.MoveTo(40, 620);
                    cb.LineTo(610, 620);
                    cb.Stroke();
                    cb.BeginText();
                    int lastwriteposition = 100;

                    top_margin = 600;
                    left_margin = 40;
                    writeText(cb, "Item Id", left_margin, top_margin, f_cb, 10);
                    writeText(cb, "Description", left_margin+70, top_margin, f_cb, 10);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Qty", left_margin + 415, top_margin, 0);
                    writeText(cb, "Unit", left_margin + 420, top_margin, f_cb, 10);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Price", left_margin + 495, top_margin, 0);
                    writeText(cb, "Curr", left_margin+500, top_margin, f_cb, 10);

                    top_margin = 588;

                    Decimal totalInvoicedPrice = 0;
                    foreach (OrderEntry entry in orderDetails.OrderEntries)
                    {
                        writeText(cb, entry.BookType.Id.ToString(), left_margin, top_margin, f_cn, 10);
                        writeText(cb, entry.BookType.Authors + ", \"" + entry.BookType.Title + "\"", left_margin + 70, top_margin, f_cn, 10);
                        cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, entry.Amount.ToString(), left_margin + 415, top_margin, 0);
                        writeText(cb, ApplicationScope.InvoiceUnit, left_margin + 420, top_margin, f_cn, 10);
                        cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, entry.Price.ToString(), left_margin + 495, top_margin, 0);
                        writeText(cb, ApplicationScope.InvoiceCurrency, left_margin + 500, top_margin, f_cn, 10);

                        totalInvoicedPrice = Decimal.Add(totalInvoicedPrice, Decimal.Multiply(entry.Price, (Decimal) entry.Amount));

                        top_margin -= 12;

                        if(top_margin <= lastwriteposition)
                        {
                            cb.EndText();
                            document.NewPage();
                            cb.BeginText();
                            top_margin = 780;
                        }
                    }

                    top_margin -= 80;
                    left_margin = 350;

                    writeText(cb, "Invoice line totals", left_margin, top_margin, f_cb, 10);
                    writeText(cb, "VAT amount", left_margin, top_margin-12, f_cb, 10);
                    writeText(cb, "Invoice grand total", left_margin, top_margin-36, f_cb, 10);
                    left_margin = 540;
                    cb.SetFontAndSize(f_cn, 10);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ApplicationScope.InvoiceCurrency, left_margin, top_margin, 0);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ApplicationScope.InvoiceCurrency, left_margin, top_margin - 12, 0);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, ApplicationScope.InvoiceCurrency, left_margin, top_margin - 36, 0);
                    left_margin = 535;
                    cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, totalInvoicedPrice.ToString(), left_margin, top_margin, 0);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, invoice.VatPriceValue.ToString(), left_margin, top_margin - 12, 0);
                    cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, invoice.TotalValue.ToString(),
                        left_margin, top_margin - 36, 0);

                    cb.EndText();

                    document.Close();
                    writer.Close();
                    fs.Close();
                    return invoiceName;
                }
            }
            catch(Exception error)
            {
                System.Console.WriteLine(error.ToString());
                return null;
            }
        }
 public void SaveOrUpdateUser(UserAccount userAccount)
 {
     AccountAdministrationDao.SaveOrUpdateUser(userAccount);
 }
Example #14
0
 public ActionResult Register(RegisterModel model)
 {
     UserAccount newUserAccount = new UserAccount() { Login = model.Login, Password = model.Password, Email = model.Email };
     if (ServiceLocator.AuthorizationService.RegisterUser(newUserAccount) == 0)
     {
         ModelState.AddModelError("Login Unique Error", "Provided login already exists in the system. Please enter another one.");
         return View();
     }
     return RedirectToAction("Create", "UserAccountPanel", new { userAccountId = newUserAccount.Id });
 }
        public void TestIdentityCardNumber()
        {
            UserAccount userAcc = new UserAccount();
            PersonalData personalData = new PersonalData();
            personalData.PESEL = PESEL;
            personalData.Sex = SEX;
            personalData.FirstName = firstName;
            personalData.LastName = lastName;
            personalData.IdentityCardNumber = IDCN;
            personalData.PhoneNumber = PHONE;
            userAcc.PersonalData = personalData;

            List<UserAccount> userAccounts = new List<UserAccount>();
            NMock.Actions.InvokeAction addUserAccounts = new NMock.Actions.InvokeAction(() => userAccounts.Add(userAcc));
            accountAdministrationDao.Expects.One.MethodWith(x => x.SaveOrUpdateUser(userAcc)).Will(addUserAccounts);

            aas.SaveOrUpdateUser(userAcc);
            userInformationService.Expects.One.MethodWith(x => x.GetUserAccountById(userAcc.Id)).WillReturn(userAcc);
            PersonalData returnedPD = sps.GetUserPersonalDataById(userAcc.Id);
            Assert.AreEqual(PESEL, returnedPD.PESEL);
            Assert.AreEqual(SEX, returnedPD.Sex);
            Assert.AreEqual(firstName, returnedPD.FirstName);
            Assert.AreEqual(lastName, returnedPD.LastName);
            Assert.AreEqual(IDCN, returnedPD.IdentityCardNumber);
            Assert.AreEqual(PHONE, returnedPD.PhoneNumber);
        }
Example #16
0
 public long RegisterUser(UserAccount newUserAccount)
 {
     return (long)this.Session.Save(newUserAccount);
 }
 public void SaveOrUpdateUser(UserAccount userAccount)
 {
     this.Session.SaveOrUpdate(userAccount);
 }