public void Should_ReturnEmployeeRole_WhenGettingUserRole()
        {
            //Arrange
            UserModel user = new UserModel {
                Id = 3, Name = "RoleName", Password = "******", ConfirmPassword = "******", Role = "Employee"
            };

            //Act
            userLogic.AddUser(user);

            //Assert
            Assert.True(userLogic.GetRoleUser(3) == "Employee");
        }
Example #2
0
        public void Should_RegisterAnUser_WhenEverythingIsFilledInCorrectly()
        {
            //Arrange
            UserModel user = new UserModel {
                Id = 1, Name = "AddName", Password = "******", ConfirmPassword = "******", Role = "Normal"
            };

            //Act
            bool userAdded = userLogic.AddUser(user);

            //Assert
            Assert.True(userAdded);
        }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            User user = new User();

            user.Username = textBox1.Text.Trim();
            user.Remark   = textBox2.Text;
            user.Flag     = checkBox1.Checked ? 1 : 0;
            user.Password = textBox3.Text;
            Department dep = comboBox2.SelectedItem as Department;

            if (dep != null)
            {
                user.Departments.Clear();
                user.Departments.Add(dep);
            }
            UserLogic ul = UserLogic.GetInstance();

            if (ul.ExistsName(user.Username))
            {
                if (MessageBox.Show("系统中已经存在该名称,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    int id = ul.AddUser(user);
                    if (id > 0)
                    {
                        user.ID = id;
                        data.Add(user);
                        RefreshInfo();
                        MessageBox.Show("添加成功!");
                    }
                }
                else
                {
                    textBox1.Focus();
                    textBox1.SelectAll();
                }
            }
            else
            {
                int id = ul.AddUser(user);
                if (id > 0)
                {
                    user.ID = id;
                    data.Add(user);
                    RefreshInfo();
                    MessageBox.Show("添加成功!");
                }
            }
        }
Example #4
0
        public void EditPost()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var PostLogic = new PostLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");
            PostLogic.Add(new PostDTO("Title", "Content", "Tag", "CategoryName"));

            var Post = PostLogic.GetAll().ToList()[0];

            Assert.AreEqual(PostLogic.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Title, "Title");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Content, "Content");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Tags, "Tag");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].CategoryName, "CategoryName");

            Post.Title        = "Programming";
            Post.CategoryName = "C#";

            PostLogic.EditPost(Post.Id, Post);

            Post = PostLogic.GetAll().ToList()[0];

            Assert.AreEqual(PostLogic.GetAll().Count(), 1);
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Title, "Programming");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Content, "Content");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].Tags, "Tag");
            Assert.AreEqual(PostLogic.GetAll().ToList()[0].CategoryName, "C#");
        }
Example #5
0
        public void CreateUser()
        {
            var  mock = new Mock <IUserDao>();
            User user = new User()
            {
                Name     = "Олег",
                LastName = "Арзямов",
                EMail    = "*****@*****.**",
                Password = "******"
            };

            byte[] data = user.Password.Select(x => (byte)x).ToArray();
            byte[] result;
            using (SHA512 shaM = SHA512.Create())
            {
                result = shaM.ComputeHash(data);
            }
            mock.Setup(item => item.AddUser(user, result.ToList())).Returns(100);

            var logic = new UserLogic(mock.Object);

            int id = logic.AddUser(user);

            Assert.AreEqual(id, 100);
        }
        private void AddUser()
        {
            Console.Clear();
            Console.WriteLine("Enter name");
            Console.Write("> ");
            string name = Console.ReadLine();

            Console.WriteLine("Enter date of birth");
            Console.Write("> ");
            DateTime date;

            while (!DateTime.TryParse(Console.ReadLine(), out date))
            {
                Console.WriteLine("Input Error!");
                Console.WriteLine("Enter correct date please.");
                Console.Write("> ");
            }

            if (logic.AddUser(name, date, DateTime.Now.Year - date.Year))

            {
                Console.WriteLine("User added successfully.");
            }
            else
            {
                Console.WriteLine("User not added.");
            }
        }
Example #7
0
        public ActionResult AddUser([FromBody] AddUserInfoDto userInfo)
        {
            var response = new ResponseDataHelper <UserInfoDto>();

            try
            {
                //var user=
                var user = _userLogic.GetUserByLoginName(userInfo.LoginName);
                if (user == null)
                {
                    user = _userLogic.AddUser(userInfo.ToUser());
                    response.ResponseData = UserInfoDto.CreateFromUser(user);
                }
                else
                {
                    response.ResponseCode    = -1;
                    response.ResponseMessage = "登录名已存在";
                }
            }
            catch (Exception e)
            {
                response.ResponseCode    = -1;
                response.ResponseMessage = e.Message;
            }
            return(Json(response));
        }
Example #8
0
        public void ReservingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            TourLogic.AddTour(new Logic.DTOs.TourDTO("ODessa", 250, "Excursion", "Ukraine", "Zaporogie", 3, "Go at beach"));
            UserLogic.AddUser(new Logic.DTOs.UserDTO("Dimon", Logic.DTOs.UserType.Manager, "Cherneckii", "Login", "Password"));

            UserLogic.ReserveTour(1, 1);

            var User = UserLogic.GetAllUsers().First(u => u.Id == 1);

            Assert.That(User.Tours.Count() == 1);
            Assert.That(User.Tours[0].Name == "ODessa");
            Assert.That(User.Tours[0].Price == 250);
            Assert.That(User.Tours[0].Type == "Excursion");
            Assert.That(User.Tours[0].Country == "Ukraine");
            Assert.That(User.Tours[0].City == "Zaporogie");
            Assert.That(User.Tours[0].Duration == 3);
            Assert.That(User.Tours[0].Description == "Go at beach");
        }
Example #9
0
        public async Task <QueueResult> Handle(string data)
        {
            QueueResult result = new QueueResult(Data.Enums.ProcessType.AddUser);

            if (string.IsNullOrEmpty(data))
            {
                result.ExceptionCode = ExceptionCode.MissingQueueData;
            }
            UserQueue userQueue = null;

            try
            {
                userQueue = JsonConvert.DeserializeObject <UserQueue>(data);
                UserLogic userLogic = new UserLogic(this.db, result.AdditionalData, this.loggerFactory, this.settings);
                var       cityId    = await userLogic.AddUser(userQueue);

                result.AdditionalData.Add("userId", cityId.ToString());
                result.AdditionalData.Add("userFirstName", userQueue.FirstName);
                result.AdditionalData.Add("userLastName", userQueue.LastName);

                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                HandleException(ex, result, userQueue);
            }
            return(result);
        }
Example #10
0
        public void AddingTransport()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TransportLogic = new TransportLogic(UoW.Object);
            var UserLogic      = new UserLogic(UoW.Object);

            UserLogic.AddUser(new Logic.DTOs.UserDTO("Dimon", Logic.DTOs.UserType.Manager, "Cherneckii", "Login", "Password"));
            UserLogic.Login("Login", "Password");

            TransportLogic.AddTransport(new Logic.DTOs.TransportDTO("Bus", "Kyiv", DateTimeOffset.Parse("21.12.15 21:15"), "odessacity", DateTimeOffset.Parse("22.12.15 9:15")), 30, 150);

            var Transport = TransportLogic.GetAllTransport().ToList()[0];

            Assert.That(TransportLogic.GetAllTransport().Count() == 1);
            Assert.That(Transport.Type == "Bus");
            Assert.That(Transport.DeparturePoint == "Kyiv");
            Assert.That(Transport.DepartureTime == DateTimeOffset.Parse("21.12.15 21:15"));
            Assert.That(Transport.ArrivalPoint == "odessacity");
            Assert.That(Transport.ArrivalTime == DateTimeOffset.Parse("22.12.15 9:15"));
            Assert.That(Transport.TransportPlaces.Count == 30);
            Assert.That(Transport.TransportPlaces[0].Number == 1);
            Assert.That(Transport.TransportPlaces[0].Price == 150);
            Assert.That(Transport.TransportPlaces[0].Transport.Id == Transport.Id);
        }
Example #11
0
        public void AddingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new Logic.DTOs.UserDTO("Dimon", Logic.DTOs.UserType.Manager, "Cherneckii", "Login", "Password"));
            UserLogic.Login("Login", "Password");


            TourLogic.AddTour(new Logic.DTOs.TourDTO("odessa", 250, "Excursion", "Ukraine", "beach", 3, "go at beach and f**k a bithc"));

            var Tour = TourLogic.GetAllToursTemplates().ToList()[0];

            Assert.That(TourLogic.GetAllToursTemplates().Count() == 1);
            Assert.That(Tour.Name == "odessa");
            Assert.That(Tour.Price == 250);
            Assert.That(Tour.Type == "Excursion");
            Assert.That(Tour.Country == "Ukraine");
            Assert.That(Tour.City == "beach");
            Assert.That(Tour.Duration == 3);
            Assert.That(Tour.Description == "go at beach and f**k a bithc");
        }
Example #12
0
        public void AddingTransport()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TransportLogic = new TransportLogic(UoW.Object);
            var UserLogic      = new UserLogic(UoW.Object);

            UserLogic.AddUser(new BLL.DTOs.UserDTO("Liza", BLL.DTOs.UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");

            TransportLogic.AddTransport(new BLL.DTOs.TransportDTO("Bus", "Kyiv", DateTimeOffset.Parse("22.10.18 11:15"), "Krakow", DateTimeOffset.Parse("22.10.18 23:45")), 30, 150);

            var Transport = TransportLogic.GetAllTransport().ToList()[0];

            Assert.That(TransportLogic.GetAllTransport().Count() == 1);
            Assert.That(Transport.Type == "Bus");
            Assert.That(Transport.DeparturePoint == "Kyiv");
            Assert.That(Transport.DepartureTime == DateTimeOffset.Parse("22.10.18 11:15"));
            Assert.That(Transport.ArrivalPoint == "Krakow");
            Assert.That(Transport.ArrivalTime == DateTimeOffset.Parse("22.10.18 23:45"));
            Assert.That(Transport.TransportPlaces.Count == 30);
            Assert.That(Transport.TransportPlaces[0].Number == 1);
            Assert.That(Transport.TransportPlaces[0].Price == 150);
            Assert.That(Transport.TransportPlaces[0].Transport.Id == Transport.Id);
        }
Example #13
0
        public ActionResult Register(string UsernameRegister, string PasswordRegister, string EmailRegister)
        {
            var userLogic = new UserLogic(_personContext);

            userLogic.AddUser(UsernameRegister, PasswordRegister, EmailRegister);
            return(RedirectToAction("Index", "Home"));
        }
Example #14
0
        public void ReservingTicket()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var UserLogic      = new UserLogic(UoW.Object);
            var TransportLogic = new TransportLogic(UoW.Object);

            UserLogic.AddUser(new BLL.DTOs.UserDTO("Liza", BLL.DTOs.UserType.User, "Bril", "Login", "Password"));
            TransportLogic.AddTransport(new BLL.DTOs.TransportDTO("Bus", "Kyiv", DateTimeOffset.Parse("22.10.18 11:15"), "Krakow", DateTimeOffset.Parse("22.10.18 23:45")), 30, 150);

            UserLogic.ReserveTicket(1, 1, 1);

            var User = UserLogic.GetAllUsers().First(u => u.Id == 1);

            //Assert.That(User.TransportTickets.Count == 1);
            //Assert.That(User.TransportTickets[0].TransportType == "Bus");
            //Assert.That(User.TransportTickets[0].PassangerName == "Liza");
            //Assert.That(User.TransportTickets[0].PassangerSurname == "Bril");
            //Assert.That(User.TransportTickets[0].NumberOfSeat == 1);
            //Assert.That(User.TransportTickets[0].DeparturePoint == "Kyiv");
            //Assert.That(User.TransportTickets[0].DepartureTime == DateTimeOffset.Parse("22.10.18 11:15"));
            //Assert.That(User.TransportTickets[0].ArrivalPoint == "Krakow");
            //Assert.That(User.TransportTickets[0].ArrivalTime == DateTimeOffset.Parse("22.10.18 23:45"));
            //Assert.That(User.TransportTickets[0].Price == 150);

            Assert.That(TransportLogic.GetAllTransport().First(t => t.Id == 1).TransportPlaces.First(r => r.Id == 1).IsBooked);
            Assert.Throws <AlreadyBookedItemException>(delegate { UserLogic.ReserveTicket(1, 1, 1); });
        }
Example #15
0
        public void ReservingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            TourLogic.AddTour(new BLL.DTOs.TourDTO("Krakow tour", 250, "Excursion", "Poland", "Krakow", 3, "The best tour to Krakow"));
            UserLogic.AddUser(new BLL.DTOs.UserDTO("Liza", BLL.DTOs.UserType.Manager, "Bril", "Login", "Password"));

            UserLogic.ReserveTour(1, 1);

            var User = UserLogic.GetAllUsers().First(u => u.Id == 1);

            Assert.That(User.Tours.Count() == 1);
            Assert.That(User.Tours[0].Name == "Krakow tour");
            Assert.That(User.Tours[0].Price == 250);
            Assert.That(User.Tours[0].Type == "Excursion");
            Assert.That(User.Tours[0].Country == "Poland");
            Assert.That(User.Tours[0].City == "Krakow");
            Assert.That(User.Tours[0].Duration == 3);
            Assert.That(User.Tours[0].Description == "The best tour to Krakow");
        }
Example #16
0
        public void AddingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new BLL.DTOs.UserDTO("Liza", BLL.DTOs.UserType.Manager, "Bril", "Login", "Password"));
            UserLogic.Login("Login", "Password");

            TourLogic.AddTour(new BLL.DTOs.TourDTO("Krakow tour", 250, "Excursion", "Poland", "Krakow", 3, "The best tour to Krakow"));

            var Tour = TourLogic.GetAllToursTemplates().ToList()[0];

            Assert.That(TourLogic.GetAllToursTemplates().Count() == 1);
            Assert.That(Tour.Name == "Krakow tour");
            Assert.That(Tour.Price == 250);
            Assert.That(Tour.Type == "Excursion");
            Assert.That(Tour.Country == "Poland");
            Assert.That(Tour.City == "Krakow");
            Assert.That(Tour.Duration == 3);
            Assert.That(Tour.Description == "The best tour to Krakow");
        }
Example #17
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <returns></returns>
        private bool AddUser()
        {
            User user = new User
            {
                //赋值
                UserName     = txtUserName.Text,
                UserRealName = txtRealName.Text,
                UserPassword = txtPwd.Text,
                UserAddress  = txtAddress.Text,
                UserMobile   = txtMobile.Text,
                UserSex      = rdoMale.Checked,
                UserEnable   = chkUserEnable.Checked,
            };
            bool ok = _userLogic.AddUser(user);

            if (ok)
            {
                tvUser.Nodes.Clear();
                InitUserTree();
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加 失败");
            }
            return(true);
        }
        public void ReservingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            TourLogic.AddTour(new Logic.DTOs.TourDTO("Karpaty", 250, "Excursion", "Ukraine", "Hust", 3, "Very nice mountains tour"));
            UserLogic.AddUser(new Logic.DTOs.UserDTO("Sasha", Logic.DTOs.UserType.Manager, "Veklych", "Login", "Password"));

            UserLogic.ReserveTour(1, 1);

            var User = UserLogic.GetAllUsers().First(u => u.Id == 1);

            Assert.That(User.Tours.Count() == 1);
            Assert.That(User.Tours[0].Name == "Karpaty");
            Assert.That(User.Tours[0].Price == 250);
            Assert.That(User.Tours[0].Type == "Excursion");
            Assert.That(User.Tours[0].Country == "Ukraine");
            Assert.That(User.Tours[0].City == "Hust");
            Assert.That(User.Tours[0].Duration == 3);
            Assert.That(User.Tours[0].Description == "Very nice mountains tour");
        }
        public void AddingTour()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var TourLogic = new TourLogic(UoW.Object);
            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new Logic.DTOs.UserDTO("Sasha", Logic.DTOs.UserType.Manager, "Veklych", "Login", "Password"));
            UserLogic.Login("Login", "Password");

            TourLogic.AddTour(new Logic.DTOs.TourDTO("Karpaty", 250, "Excursion", "Ukraine", "Hust", 3, "Very nice mountains tour"));

            var Tour = TourLogic.GetAllToursTemplates().ToList()[0];

            Assert.That(TourLogic.GetAllToursTemplates().Count() == 1);
            Assert.That(Tour.Name == "Karpaty");
            Assert.That(Tour.Price == 250);
            Assert.That(Tour.Type == "Excursion");
            Assert.That(Tour.Country == "Ukraine");
            Assert.That(Tour.City == "Hust");
            Assert.That(Tour.Duration == 3);
            Assert.That(Tour.Description == "Very nice mountains tour");
        }
Example #20
0
        public int AddUser(string firstName, string lastName)
        {
            int userId = 0;

            userId = userLogic.AddUser(firstName, lastName);

            return(userId);
        }
        public IActionResult Register([Bind("Password, Username, Nickname, Confirm Password")] RegisterViewModel user)
        {
            if (!ModelState.IsValid && user.Password == user.ConfirmPassword)
            {
                return(View());
            }
            User userToAdd = new User
            {
                Nickname = user.Nickname,
                Password = user.Password,
                Role     = "Member",
                Username = user.Username
            };

            userLogic.AddUser(userToAdd);
            AuthorizeUser(userToAdd);
            return(RedirectToAction("Index", "Home")); //redirect naar page om cookies te refreshen
        }
Example #22
0
        public void LoggingIn()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new UserDTO("Liza", UserType.User, "Bril", "Login", "Password"));

            Assert.AreEqual(UserLogic.Login("Login", "Password").Id, UserLogic.GetAllUsers().ToList()[0].Id);
        }
Example #23
0
        public IActionResult AddUser([FromBody] User user)
        {
            if (user == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userLogic = new UserLogic(new UserData(_context));

            userLogic.AddUser(user);

            return(Created("A new user was created", user));
        }
        public void Should_Change_Status_AfterDelete()
        {
            var user = new FakeUserCreateModel();

            _userLogic.AddUser(user);

            var numberOfAddedUsers = _userLogic.GetAvailableUsers().Count();

            _userLogic.DeleteUser(user.Email);
            var numberAfterDelete = _userLogic.GetAvailableUsers().Count();

            Assert.AreEqual(numberOfAddedUsers - 1, numberAfterDelete);
        }
Example #25
0
 public IActionResult Create([FromBody] UserDTO user)
 {
     try
     {
         userLogic.AddUser(user);
         return(Ok());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Something went wrong inside AddUser action: {ex.Message}");
         return(StatusCode(500, "Internal server error"));
     }
 }
Example #26
0
        public void LoggingIn()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new BLL.DTOs.UserDTO("Liza", BLL.DTOs.UserType.Manager, "Bril", "Login", "Password"));

            Assert.That(UserLogic.Login("Login", "Password").Id == UserLogic.GetAllUsers().ToList()[0].Id);
            Assert.Throws <InvalidLoginPasswordCombinationException>(delegate { UserLogic.Login("Wrong", "Password"); });
        }
Example #27
0
        public void AddUser_Test()
        {
            UserRegistrationDTO u = new UserRegistrationDTO()
            {
                Email    = "*****@*****.**",
                Password = "******",
                Username = "******"
            };

            Assert.AreEqual(3, _userLogic.GetAllUsers(0, 5).Count);
            _userLogic.AddUser(u);
            Assert.AreEqual(4, _userLogic.GetAllUsers(0, 5).Count);
        }
        public void Entering()
        {
            var UoW = new Mock <UnitOfWork>();

            UoW.Object.DeleteDB();

            var UserLogic = new UserLogic(UoW.Object);

            UserLogic.AddUser(new Logic.DTOs.UserDTO("Sasha", Logic.DTOs.UserType.User, "Veklych", "Login", "Password"));

            Assert.That(UserLogic.Login("Login", "Password").Id == UserLogic.GetAllUsers().ToList()[0].Id);
            Assert.Throws <InvalidLoginPasswordCombinationException>(delegate { UserLogic.Login("Wrong", "Password"); });
        }
Example #29
0
 public UserDto Register(AddUserRequest userUserRequest)
 {
     try
     {
         return(_userLogic.AddUser(userUserRequest.Name, userUserRequest.Email, userUserRequest.Password,
                                   userUserRequest.Token, userUserRequest.Phone)
                .Map());
     }
     catch (Exception e)
     {
         // todo : log exception
         throw new FaultException("Sikertelen regisztráció.");
     }
 }
Example #30
0
 public void TestInitialize()
 {
     ULogic = new UserLogic();
     user   = new User
     {
         Id              = 1,
         Email           = "*****@*****.**",
         IsEmailVerified = false,
         Password        = "******",
         ConfirmPassword = "******",
         Mobile          = 0684522582,
         RememberMe      = true,
     };
     ULogic.AddUser(user);
 }