Пример #1
0
        public void HaveDataTypeAttributeWithCorrectType()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("Password")
                       .GetCustomAttributes(typeof(DataTypeAttribute), false)[0]
                       as DataTypeAttribute;

            Assert.AreEqual(DataType.Password, attr.DataType);
        }
Пример #2
0
        public void HaveDisplayAttribute()
        {
            var viewModel = new RegisterViewModel();

            var hasAttr = viewModel.GetType()
                          .GetProperty("Password")
                          .GetCustomAttributes(typeof(DisplayAttribute), false)
                          .Any();

            Assert.IsTrue(hasAttr);
        }
Пример #3
0
        public void HaveCompareAttributeWithCorrectErrorMessage()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("ConfirmPassword")
                       .GetCustomAttributes(typeof(CompareAttribute), false)[0]
                       as CompareAttribute;

            Assert.AreEqual("The password and confirmation password do not match.", attr.ErrorMessage);
        }
Пример #4
0
        public void HaveStringLengthAttributeWithCorrectErrorMessage()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("Password")
                       .GetCustomAttributes(typeof(StringLengthAttribute), false)[0]
                       as StringLengthAttribute;

            Assert.AreEqual("The {0} must be at least {2} characters long.", attr.ErrorMessage);
        }
Пример #5
0
        public void HaveDisplayAttributeWithCorrectName()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("Password")
                       .GetCustomAttributes(typeof(DisplayAttribute), false)[0]
                       as DisplayAttribute;

            Assert.AreEqual("Password", attr.Name);
        }
Пример #6
0
        public void HaveCompareAttributeWithCorrectProperty()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("ConfirmPassword")
                       .GetCustomAttributes(typeof(CompareAttribute), false)[0]
                       as CompareAttribute;

            Assert.AreEqual("Password", attr.OtherProperty);
        }
Пример #7
0
        public void HaveEmailAddressAttribute()
        {
            var viewModel = new RegisterViewModel();

            var hasAttr = viewModel.GetType()
                          .GetProperty("Email")
                          .GetCustomAttributes(typeof(EmailAddressAttribute), false)
                          .Any();

            Assert.IsTrue(hasAttr);
        }
Пример #8
0
        public void HaveMaxLengthAttributeWithCorrectValue()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("Username")
                       .GetCustomAttributes(typeof(MaxLengthAttribute), false)[0]
                       as MaxLengthAttribute;

            Assert.AreEqual(20, attr.Length);
        }
Пример #9
0
        public void HaveMaxLengthAttribute()
        {
            var viewModel = new RegisterViewModel();

            var hasAttr = viewModel.GetType()
                          .GetProperty("Username")
                          .GetCustomAttributes(typeof(MaxLengthAttribute), false)
                          .Any();

            Assert.IsTrue(hasAttr);
        }
Пример #10
0
        public void HaveStringLengthAttributeWithCorrectLength()
        {
            var viewModel = new RegisterViewModel();

            var attr = viewModel.GetType()
                       .GetProperty("Password")
                       .GetCustomAttributes(typeof(StringLengthAttribute), false)[0]
                       as StringLengthAttribute;

            Assert.AreEqual(6, attr.MinimumLength);
            Assert.AreEqual(100, attr.MaximumLength);
        }
Пример #11
0
        public void Have_StringLengthAddressAttribute()
        {
            // Arrange
            string propertyName = "Password";

            RegisterViewModel registerViewModel = new RegisterViewModel();

            // Act
            bool hasAttribute = registerViewModel.GetType()
                                .GetProperty(propertyName)
                                .GetCustomAttributes(false)
                                .Where(p => p.GetType() == typeof(StringLengthAttribute))
                                .Any();

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Пример #12
0
        public void Have_DisplayAttribute()
        {
            // Arrange
            string propertyName = "Email";

            RegisterViewModel registerViewModel = new RegisterViewModel();

            // Act
            bool hasAttribute = registerViewModel.GetType()
                                .GetProperty(propertyName)
                                .GetCustomAttributes(false)
                                .Where(p => p.GetType() == typeof(DisplayAttribute))
                                .Any();

            // Assert
            Assert.IsTrue(hasAttribute);
        }
        private IdentityUser <int> GetUser(RegisterViewModel model)
        {
            switch (model)
            {
            case MemberEmailRegisterViewModel me:
                return(new MemberUser {
                    UserName = me.Email, NormalizedEmail = me.Nickname, Email = me.Email
                });

            case MemberPhoneRegisterViewModel mc:
                return(new MemberUser {
                    UserName = mc.PhoneNumber, NormalizedEmail = mc.Nickname, PhoneNumber = mc.PhoneNumber
                });

            default:
                throw new NotSupportedException(_localizer["Register not support type {0}", model.GetType().FullName]);
            }
        }