Ejemplo n.º 1
0
            public void SetEnabled_Should_Throw_Exception_When_User_Is_Null()
            {
                UserListItemVm user   = null;
                User           result = this.GetUser();

                UserListItemVm actual = UserModelHelper.SetEnabled(user, result);
            }
Ejemplo n.º 2
0
            public void ToUserRoleVm_Should_Return_UserRoleVm()
            {
                Role result = new Role("1", "admin");

                UserRoleVm actual = UserModelHelper.ResultToUserRoleVm(result);

                Assert.AreEqual("admin", actual.Name);
            }
Ejemplo n.º 3
0
            public void ToUserListVm_Should_Throw_Exception_When_Results_Is_Null()
            {
                GetUsersQueryResult results = null;

                IConfiguration config = GetConfig();

                UserListVm actual = UserModelHelper.ResultToUserListVm(results, config);
            }
Ejemplo n.º 4
0
            public void ToUserGroupVm_Should_Return_UserGroupVm()
            {
                Group result = new Group("1", "admin", null);

                UserGroupVm actual = UserModelHelper.ResultToUserGroupVm(result);

                Assert.AreEqual("admin", actual.Name);
            }
Ejemplo n.º 5
0
            public void ToUserListVm_Should_Throw_Exception_When_Config_Is_Null()
            {
                ICollection <User>  users   = new List <User>();
                GetUsersQueryResult results = new GetUsersQueryResult(users);

                IConfiguration config = null;

                UserListVm actual = UserModelHelper.ResultToUserListVm(results, config);
            }
Ejemplo n.º 6
0
            public void SetEnabled_Should_Set_Enabled_When_User_Is_Enabled()
            {
                UserListItemVm user   = new UserListItemVm();
                User           result = this.GetUser();

                UserListItemVm actual = UserModelHelper.SetEnabled(user, result);

                Assert.AreEqual("Enabled", actual.Enabled);
                Assert.AreEqual("success", actual.EnabledClass);
            }
Ejemplo n.º 7
0
            public void SetEnabled_Should_Set_Disabled_When_User_Is_Disabled()
            {
                UserListItemVm user   = new UserListItemVm();
                User           result = this.GetUser(false);

                UserListItemVm actual = UserModelHelper.SetEnabled(user, result);

                Assert.AreEqual("Disabled", actual.Enabled);
                Assert.AreEqual("danger", actual.EnabledClass);
            }
Ejemplo n.º 8
0
        public void CreateToken_ShouldReturnBearerString()
        {
            //arrange
            var appSettings  = Options.Create(MockAppSettings().Object);
            var tokenManager = new TokenManager(appSettings, TestDateTime());

            //act
            var result = tokenManager.CreateToken(UserModelHelper.GetUser());

            //assert
            Assert.NotSame(-1, result.IndexOf("Bearer ", StringComparison.Ordinal));
        }
Ejemplo n.º 9
0
            public void ToUserListVm_Should_Return_UserListVm_When_No_Items_Found()
            {
                ICollection <User>  users   = new List <User>();
                GetUsersQueryResult results = new GetUsersQueryResult(users);

                IConfiguration config = GetConfig();

                UserListVm actual = UserModelHelper.ResultToUserListVm(results, config);

                Assert.AreEqual(MessagesModel.NoItemsFound, actual.Message);
                Assert.AreEqual(MessagesModel.MessageStyles.Info, actual.MessageStyle);
            }
Ejemplo n.º 10
0
        public void CreateToken_ShouldReturnResultOfExpectedLength()
        {
            //arrange
            var appSettings  = Options.Create(MockAppSettings().Object);
            var tokenManager = new TokenManager(appSettings, TestDateTime());

            //act
            var result = tokenManager.CreateToken(UserModelHelper.GetUser());

            //assert
            Assert.NotSame(7, result.Length);
        }
        public void GetClaims_ShouldReturnMatchingLastNameClaim()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.Equal(userModel.LastName, result.ToList().FirstOrDefault(i => i.Type == AutoRenterClaimNames.LastName).Value);
        }
Ejemplo n.º 12
0
        public void CreateJsonWebToken_ValidFromSultMatchTestDateTime()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(TestDateTime(), result.ValidFrom);
        }
Ejemplo n.º 13
0
        public void CreateJsonWebToken_TokenIssuerShouldMatchExpectedString()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal("FusionAlliance", result.Issuer);
        }
Ejemplo n.º 14
0
        public void CreateJsonWebToken_TokenExperationMinutesShouldBeAccessedOnce()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            appSettings.VerifyGet(i => i.TokenSettings.ExpirationMinutes, Times.Once);
        }
Ejemplo n.º 15
0
        public void CreateJsonWebToken_ShoulReturnJwtSecurityToken()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.IsType(typeof(JwtSecurityToken), result);
        }
        public void CreateJsonWebToken_ResultShouldHaveCorrectClaimsCount()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(9, result.Claims.Count());
        }
Ejemplo n.º 17
0
        public void CreateJsonWebToken_ValidToShouldMatchExpectedDateTime()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal(TestDateTime().AddMinutes(5), result.ValidTo);
        }
        public void GetClaims_ShouldReturnListOfClaimsWithAdministoratorClaimWhenUserIsAdministrator()
        {
            //arrange
            var userModel    = UserModelHelper.GetAdministratorUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.True(Convert.ToBoolean(result.ToList().FirstOrDefault(i => i.Type == AutoRenterClaimNames.IsAdministrator).Value));
        }
        public void GetClaims_ShouldReturnArraryOfExpectedLength()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = Options.Create(new AppSettings());
            var tokenManager = new TokenManager(appSettings);

            //act
            var result = tokenManager.GetClaims(userModel);

            //assert
            Assert.Equal(5, result.Length);
        }
Ejemplo n.º 20
0
        public void CreateJsonWebToken_TokenAudienceShouldMatchExpectedString()
        {
            //arrange
            var userModel    = UserModelHelper.GetUser();
            var appSettings  = MockAppSettings();
            var tokenManager = new TokenManager(Options.Create(appSettings.Object), TestDateTime());

            //act
            var result = tokenManager.CreateJsonWebToken(userModel);

            //assert
            Assert.Equal("ThoseWhoRock", result.Audiences.FirstOrDefault());
        }
Ejemplo n.º 21
0
            public void ToUserListVm_Should_Return_UserListVm_When_Items_Found()
            {
                DateTime           date  = DateTime.Now;
                ICollection <User> users = new List <User>();
                User user = this.GetUser(true, "1");

                users.Add(user);
                user = this.GetUser(true, "2");
                users.Add(user);
                user = this.GetUser(true, "3");
                users.Add(user);
                GetUsersQueryResult results = new GetUsersQueryResult(users);

                IConfiguration config = GetConfig();

                UserListVm actual = UserModelHelper.ResultToUserListVm(results, config);

                Assert.AreEqual(3, actual.Users.Count);
            }
Ejemplo n.º 22
0
            public void ToUserRoleVm_Should_Throw_Exception_When_Result_Is_Null()
            {
                Role result = null;

                UserRoleVm actual = UserModelHelper.ResultToUserRoleVm(result);
            }
Ejemplo n.º 23
0
        /// <summary>
        /// Получает всех пользователей, которые имеют роль с идентификатором <paramref name="id"/>,
        /// затем оборачивает их в <see cref="UserModel"/>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList <UserModel> GetUsersByRole(int id)
        {
            IList <User> users = _accessRep.GetAllByRole(id);

            return(UserModelHelper.GetUserModel(users));
        }
 public AccountController()
 {
     _userHelper       = new UserModelHelper();
     _accountValidator = new AccountValidator();
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Возвращает всех приглашенных,
        /// но пока еще не зарегестрированных пользователей
        /// </summary>
        /// <returns></returns>
        public IList <UserModel> GetAllInvited()
        {
            IList <User> users = UserRep.FindAllInvited();

            return(UserModelHelper.GetUserModel(users));
        }
Ejemplo n.º 26
0
        private void addUserButton_Click(object sender, EventArgs e)
        {
            var userModel = UserModelHelper.CreateUserModel(firstNameTextbox.Text, lastNameTextbox.Text, (int)ageNumbericUpDown.Value, isAliveCheckbox.Checked);

            usersListBox.Items.Add(Display.UserInformation(userModel));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Возвращаем пользователя по его Id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public UserModel GetById(int Id)
        {
            User user = _userRep.FindOneById(Id);

            return(UserModelHelper.GetUserModel(user));
        }
Ejemplo n.º 28
0
 public HomeController()
 {
     _userHelper = new UserModelHelper();
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Список сообщений пользователя
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public IList <UserMessageModel> GetUserMessages(int id)
 {
     return(UserModelHelper.GetMessageModels(_userRep.GetUserMessages(id)));
 }
Ejemplo n.º 30
0
 public virtual ActionResult SignOff()
 {
     UserModelHelper.SignOff();
     return(this.RedirectToAction <HomeController>(a => a.Index()));
 }