public void EnterYourDetailsBodyViewModelnonCallbackMandatoryTest(Category category)
        {
            // Arrange
            var expectedErrors = new Dictionary <string, string>
            {
                { nameof(EnterYourDetailsBodyViewModel.FirstName), "Enter your" },
                { nameof(EnterYourDetailsBodyViewModel.LastName), "Enter your" },
                { nameof(EnterYourDetailsBodyViewModel.DateOfBirth), "Enter your" },
                { nameof(EnterYourDetailsBodyViewModel.Postcode), "Enter your" },
                { nameof(EnterYourDetailsBodyViewModel.EmailAddress), "Enter your" },
            };
            var viewModel = new EnterYourDetailsBodyViewModel
            {
                SelectedCategory = category,
            };

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count == expectedErrors.Count + 1);

            expectedErrors.Keys.ToList().ForEach(fe =>
            {
                Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == fe)));
                Assert.Contains(expectedErrors[fe], validationResults.First(f => f.MemberNames.Any(a => a == fe)).ErrorMessage, StringComparison.Ordinal);
            });

            Assert.NotNull(validationResults.First(f => f.ErrorMessage.Contains("You must accept our", StringComparison.Ordinal)));
        }
Exemple #2
0
        public void EnterYourDetailsBodyViewModelValidationReturnsSuccessForValidModel()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.True(isValid);
            Assert.True(validationResults.Count == 0);
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsSuccessCallbackValid()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.CallbackDateOptionSelected = CallbackDateOption.TodayPlus1;
            viewModel.CallbackTimeOptionSelected = CallbackTimeOption.Band3;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.True(isValid);
            Assert.True(validationResults.Count == 0);
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForTermsAndConditionsAcceptedInvalid()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.TermsAndConditionsAccepted = false;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.ErrorMessage.Contains("You must accept our", StringComparison.Ordinal)));
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForLastNameInvalid(string lastName)
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.LastName = lastName;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.LastName))));
            Assert.Contains("contains invalid characters", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.LastName))).ErrorMessage, StringComparison.Ordinal);
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForLastNameTooLong()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.LastName = string.Empty.PadLeft(101, 'a');

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.LastName))));
            Assert.Contains("is limited to between 1 and", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.LastName))).ErrorMessage, StringComparison.Ordinal);
        }
Exemple #7
0
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForTelephoneNumberInvalid(string telephoneNumber)
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.TelephoneNumber = telephoneNumber;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.TelephoneNumber))));
            Assert.Contains("requires numbers only", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.TelephoneNumber))).ErrorMessage, StringComparison.Ordinal);
        }
Exemple #8
0
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForDateOfBirthNotOver13YearsAgo()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.DateOfBirth = new DateOfBirthViewModel(DateTime.Today.AddYears(-13).AddDays(1));

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.DateOfBirth.Year))));
            Assert.Contains("You must be over 13 to use this service", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.DateOfBirth.Year))).ErrorMessage, StringComparison.Ordinal);
        }
Exemple #9
0
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForDateOfBirthMissing()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.DateOfBirth = new DateOfBirthViewModel();

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.DateOfBirth))));
            Assert.Contains("Enter your date of birth", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.DateOfBirth))).ErrorMessage, StringComparison.Ordinal);
        }
Exemple #10
0
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForEmailAddressInvalid(string emailAddress)
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.EmailAddress = emailAddress;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.EmailAddress))));
            Assert.Contains("Enter an email address in the correct format", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.EmailAddress))).ErrorMessage, StringComparison.Ordinal);
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForCallbackTimeMissing()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.CallbackDateOptionSelected = CallbackDateOption.TodayPlus1;
            viewModel.CallbackTimeOptionSelected = null;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.CallbackTimeOptionSelected))));
            Assert.Equal(EnterYourDetailsBodyViewModel.CallbackTimeOptionValidationError, validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.CallbackTimeOptionSelected))).ErrorMessage);
        }
        public void EnterYourDetailsBodyViewModelValidationReturnsSuccessCallbackNotRequired()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.CallbackDateOptionSelected = null;
            viewModel.CallbackTimeOptionSelected = null;
            viewModel.SelectedCategory           = Category.AdviceGuidance;
            viewModel.IsCallback = false;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.True(isValid);
            Assert.True(validationResults.Count == 0);
        }
Exemple #13
0
        public void EnterYourDetailsBodyViewModelValidationReturnsErrorForEmailAddressMissing()
        {
            // Arrange
            var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel();

            viewModel.SelectedCategory = Category.Other;
            viewModel.IsCallback       = false;
            viewModel.EmailAddress     = null;

            // Act
            var(isValid, validationResults) = ModelValidator.TryValidateModel(viewModel);

            // Assert
            Assert.False(isValid);
            Assert.True(validationResults.Count > 0);
            Assert.NotNull(validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.EmailAddress))));
            Assert.Contains("Enter your", validationResults.First(f => f.MemberNames.Any(a => a == nameof(EnterYourDetailsBodyViewModel.EmailAddress))).ErrorMessage, StringComparison.Ordinal);
        }