public void RegisterViewModel_AllFieldsValid_NoErrors()
        {
            // Arrange
            var model = MockRegisterViewModel.Get(0);

            // Act
            var validation = ModelValidator.ValidateModel(model);

            // Assert
            Assert.Equal(0, validation.Count);
        }
        public void ApplicationUserViewModelConstructor_Getter_Matches()
        {
            // Arrange
            var viewModel = MockRegisterViewModel.Get(0);

            // Act
            var user = new ApplicationUser(viewModel);

            // Assert
            Assert.Equal(viewModel.Email, user.Email);
            Assert.Equal(viewModel.Email, user.UserName);
            Assert.Equal(viewModel.Name, user.Name);
        }
Exemplo n.º 3
0
        public async Task Register_RegisterFailException_Unauthorized()
        {
            // Arrange
            var service = new MockAccountService {
                MRegister = (model) => throw new RegisterFailException()
            };
            var controller = new AccountController(service);

            // Act
            var result = await controller.Register(MockRegisterViewModel.Get(0)) as UnauthorizedResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(401, result.StatusCode);
        }
        public void RegisterViewModel_Setter_Modifies()
        {
            // Arrange
            var model = MockRegisterViewModel.Get(1);

            // Act
            model.Name     = "Curtis";
            model.Email    = "*****@*****.**";
            model.Password = "******";

            // Assert
            Assert.Equal("Curtis", model.Name);
            Assert.Equal("*****@*****.**", model.Email);
            Assert.Equal("Xx14$$", model.Password);
        }
Exemplo n.º 5
0
        public async Task Register_PasswordModelException_BadRequest()
        {
            // Arrange
            var service = new MockAccountService {
                MRegister = (model) => throw new PasswordModelException()
            };
            var controller = new AccountController(service);

            // Act
            var result = await controller.Register(MockRegisterViewModel.Get(1)) as BadRequestObjectResult;

            var errorMessage = result?.Value as HashSet <string>;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(400, result.StatusCode);
            Assert.NotNull(errorMessage);
            Assert.Equal(new HashSet <string>(PasswordLimits.SettingsErrorMessages), errorMessage);
        }
Exemplo n.º 6
0
        public async Task Register_Valid_OkWithToken()
        {
            // Arrange
            var mockToken = "This is not a love-token song";
            var service   = new MockAccountService {
                MRegister = (model) => string.Copy(mockToken)
            };
            var controller = new AccountController(service);

            // Act
            var result = await controller.Register(MockRegisterViewModel.Get(0)) as ObjectResult;

            var tokenReceived = result?.Value as string;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(201, result.StatusCode);
            Assert.NotNull(tokenReceived);
            Assert.Equal(string.Copy(mockToken), tokenReceived);
        }
Exemplo n.º 7
0
        public async Task Register_InvalidState_BadRequest()
        {
            // Arrange
            const string field        = "dog-error";
            const string errorMessage = "The hair of the dog that bit you";
            var          service      = new MockAccountService {
                MRegister = (model) => "Doesn't really matter a fourth time"
            };
            var controller = new AccountController(service);

            controller.ModelState.AddModelError(field, errorMessage);

            // Act
            var result = await controller.Register(MockRegisterViewModel.Get(0)) as BadRequestObjectResult;

            var error = result?.Value as SerializableError;

            // Assert
            Assert.NotNull(error);
            Assert.Equal(400, result.StatusCode);
            Assert.Single(error.Keys);
            Assert.True(error.ContainsKey(field));
            Assert.Equal(new[] { errorMessage }, error.GetValueOrDefault(field));
        }