Exemple #1
0
        public void Register_ValidateUsername_AlreadyExists()
        {
            var resources = new Resources();

            using (resources.Context.Database.BeginTransaction())
            {
                // Given
                TestHelper.RemoveUsers(resources.Context);
                var user = TestHelper.CreateUser(resources.Context, username: "******");

                var requestModel = new ValidateUserRequestModel
                {
                    Username = user.Username
                };

                // When
                var result = resources.Controller.FindUsername(requestModel);

                // Then
                Assert.IsNotNull(result);
                Assert.IsFalse(result.IsValid);
                Assert.AreEqual("Username already exists", result.Messages[0].Message);

                var savedUser = resources.Context.Users.First(u => u.Username == requestModel.Username);
                Assert.IsNotNull(savedUser);
            }
        }
Exemple #2
0
        public ValidationResult FindUsername([FromBody] ValidateUserRequestModel requestModel)
        {
            var result = new ValidationResult();

            var existingUser = Context.Users.FirstOrDefault(r => r.Username.ToUpper() == requestModel.Username.ToUpper());

            if (existingUser == null)
            {
                return(result);
            }
            else
            {
                result.InValidate("", "Username already exists");
                return(result);
            }
        }
Exemple #3
0
        public void Register_ValidateUsername_Successful()
        {
            var resources = new Resources();

            using (resources.Context.Database.BeginTransaction())
            {
                // Given
                var requestModel = new ValidateUserRequestModel
                {
                    Username = "******"
                };

                // When
                var result = resources.Controller.FindUsername(requestModel);

                // Then
                Assert.IsNotNull(result);
                Assert.IsTrue(result.IsValid);
                var savedUser = resources.Context.Users.FirstOrDefault(u => u.Username == requestModel.Username);
                Assert.IsNull(savedUser);
            }
        }