Esempio n. 1
0
        public async Task Summary_post_returns_redirect_to_index_with_email_in_use_register_error()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationData();

            controller.TempData.Set(data);
            A.CallTo(
                () => registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> ._,
                    A <string> ._,
                    A <bool> ._,
                    A <int> ._
                    )
                )
            .Throws(new DelegateCreationFailedException(DelegateCreationError.EmailAlreadyInUse));
            A.CallTo(() => request.Headers).Returns(
                new HeaderDictionary(
                    new Dictionary <string, StringValues> {
                { "X-Forwarded-For", new StringValues(IpAddress) }
            }
                    )
                );

            // When
            var result = await controller.Summary(new SummaryViewModel());

            // Then
            result.Should().BeRedirectToActionResult().WithActionName("Index");
        }
Esempio n. 2
0
        public async Task Summary_post_returns_500_error_with_unexpected_register_error()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationData();

            controller.TempData.Set(data);
            A.CallTo(
                () => registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> ._,
                    A <string> ._,
                    A <bool> ._,
                    A <int> ._
                    )
                )
            .Throws(new DelegateCreationFailedException(DelegateCreationError.UnexpectedError));
            A.CallTo(() => request.Headers).Returns(
                new HeaderDictionary(
                    new Dictionary <string, StringValues> {
                { "X-Forwarded-For", new StringValues(IpAddress) }
            }
                    )
                );

            // When
            var result = await controller.Summary(new SummaryViewModel());

            // Then
            result.Should().BeStatusCodeResult().WithStatusCode(500);
        }
Esempio n. 3
0
        public async Task Summary_post_registers_delegate_with_expected_values()
        {
            // Given
            const string candidateNumber = "TN1";
            var          data            = RegistrationDataHelper.GetDefaultDelegateRegistrationData();

            controller.TempData.Set(data);
            A.CallTo(
                () => registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> ._,
                    A <string> ._,
                    A <bool> ._,
                    A <int> ._
                    )
                )
            .Returns((candidateNumber, true));
            A.CallTo(() => request.Headers).Returns(
                new HeaderDictionary(
                    new Dictionary <string, StringValues> {
                { "X-Forwarded-For", new StringValues(IpAddress) }
            }
                    )
                );

            // When
            var result = await controller.Summary(new SummaryViewModel());

            // Then
            A.CallTo(
                () =>
                registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> .That.Matches(
                        d =>
                        d.FirstName == data.FirstName &&
                        d.LastName == data.LastName &&
                        d.Email == data.Email &&
                        d.Centre == data.Centre &&
                        d.JobGroup == data.JobGroup &&
                        d.PasswordHash == data.PasswordHash &&
                        d.Answer1 == data.Answer1 &&
                        d.Answer2 == data.Answer2 &&
                        d.Answer3 == data.Answer3 &&
                        d.Answer4 == data.Answer4 &&
                        d.Answer5 == data.Answer5 &&
                        d.Answer6 == data.Answer6 &&
                        d.Active &&
                        d.IsSelfRegistered &&
                        d.NotifyDate != null &&
                        d.AliasId == null
                        ),
                    IpAddress,
                    false,
                    SupervisorDelegateId
                    )
                )
            .MustHaveHappened();
            result.Should().BeRedirectToActionResult().WithActionName("Confirmation");
        }
Esempio n. 4
0
        public void LearnerInformation_constructor_using_data_populates_viewmodel_correctly()
        {
            // Given
            var data = RegistrationDataHelper.SampleRegistrationData();

            // When
            var result = new LearnerInformationViewModel(data);

            // Then
            result.JobGroup.Should().Be(data.JobGroup);
        }
        public void Summary_constructor_using_delegate_data_populates_viewmodel_correctly()
        {
            // Given
            var data = RegistrationDataHelper.SampleDelegateRegistrationData();

            // When
            var result = new SummaryViewModel(data);

            // Then
            result.FirstName.Should().Be(data.FirstName);
            result.LastName.Should().Be(data.LastName);
            result.Email.Should().Be(data.Email);
        }
        public void Summary_post_registers_delegate_with_expected_values()
        {
            // Given
            const string candidateNumber = "TN1";
            var          data            = RegistrationDataHelper.GetDefaultDelegateRegistrationByCentreData(
                welcomeEmailDate: DateTime.Now
                );

            controller.TempData.Set(data);
            A.CallTo(
                () => registrationService.RegisterDelegateByCentre(
                    A <DelegateRegistrationModel> ._,
                    A <string> ._
                    )
                )
            .Returns(candidateNumber);

            // When
            var result = controller.Summary(new SummaryViewModel());

            // Then
            A.CallTo(
                () =>
                registrationService.RegisterDelegateByCentre(
                    A <DelegateRegistrationModel> .That.Matches(
                        d =>
                        d.FirstName == data.FirstName &&
                        d.LastName == data.LastName &&
                        d.Email == data.Email &&
                        d.Centre == data.Centre &&
                        d.JobGroup == data.JobGroup &&
                        d.PasswordHash == data.PasswordHash &&
                        d.Answer1 == data.Answer1 &&
                        d.Answer2 == data.Answer2 &&
                        d.Answer3 == data.Answer3 &&
                        d.Answer4 == data.Answer4 &&
                        d.Answer5 == data.Answer5 &&
                        d.Answer6 == data.Answer6 &&
                        d.AliasId == data.Alias &&
                        d.Active &&
                        d.Approved &&
                        !d.IsSelfRegistered &&
                        d.NotifyDate == data.WelcomeEmailDate &&
                        d.ProfessionalRegistrationNumber == data.ProfessionalRegistrationNumber
                        ),
                    A <string> ._
                    )
                )
            .MustHaveHappened();
            result.Should().BeRedirectToActionResult().WithActionName("Confirmation");
        }
        public void PersonalInformation_constructor_using_data_populates_viewmodel_correctly()
        {
            // Given
            var data = RegistrationDataHelper.SampleRegistrationData();

            // When
            var result = new PersonalInformationViewModel(data);

            // Then
            result.FirstName.Should().Be(data.FirstName);
            result.LastName.Should().Be(data.LastName);
            result.Email.Should().Be(data.Email);
            result.Centre.Should().Be(data.Centre);
        }
        public void LearnerInformation_constructor_using_delegate_data_populates_viewmodel_correctly()
        {
            // Given
            var data = RegistrationDataHelper.SampleDelegateRegistrationData();

            // When
            var result = new LearnerInformationViewModel(data, false);

            // Then
            result.JobGroup.Should().Be(data.JobGroup);
            result.Answer1.Should().Be(data.Answer1);
            result.Answer2.Should().Be(data.Answer2);
            result.Answer3.Should().Be(data.Answer3);
        }
Esempio n. 9
0
        public void Summary_post_returns_redirect_to_index_with_email_in_use_register_error()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationByCentreData();

            controller.TempData.Set(data);
            A.CallTo(() => registrationService.RegisterDelegateByCentre(A <DelegateRegistrationModel> ._, A <string> ._))
            .Throws(new DelegateCreationFailedException(DelegateCreationError.EmailAlreadyInUse));

            // When
            var result = controller.Summary(new SummaryViewModel());

            // Then
            result.Should().BeRedirectToActionResult().WithActionName("Index");
        }
Esempio n. 10
0
        public void Summary_post_returns_500_error_with_unexpected_register_error()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationByCentreData();

            controller.TempData.Set(data);
            A.CallTo(() => registrationService.RegisterDelegateByCentre(A <DelegateRegistrationModel> ._, A <string> ._))
            .Throws(new DelegateCreationFailedException(DelegateCreationError.UnexpectedError));

            // When
            var result = controller.Summary(new SummaryViewModel());

            // Then
            result.Should().BeStatusCodeResult().WithStatusCode(500);
        }
        public void MapToDelegateRegistrationModel_returns_correct_DelegateRegistrationModel()
        {
            // Given
            var data = RegistrationDataHelper.SampleDelegateRegistrationData();

            // When
            var result = RegistrationMappingHelper.MapSelfRegistrationToDelegateRegistrationModel(data);

            // Then
            result.FirstName.Should().Be(data.FirstName);
            result.LastName.Should().Be(data.LastName);
            result.Email.Should().Be(data.Email);
            result.Centre.Should().Be(data.Centre);
            result.JobGroup.Should().Be(data.JobGroup);
            result.PasswordHash.Should().Be(data.PasswordHash);
            result.Answer1.Should().Be(data.Answer1);
            result.Answer2.Should().Be(data.Answer2);
            result.Answer3.Should().Be(data.Answer3);
        }
Esempio n. 12
0
        public async Task Summary_post_returns_default_view_with_invalid_model()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationData();

            controller.TempData.Set(data);
            controller.ModelState.AddModelError("", "");

            // When
            var result = await controller.Summary(new SummaryViewModel());

            // Then
            A.CallTo(
                () =>
                registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> ._,
                    IpAddress,
                    false,
                    SupervisorDelegateId
                    )
                )
            .MustNotHaveHappened();
            result.Should().BeViewResult().WithDefaultViewName();
        }
Esempio n. 13
0
        public async Task Summary_post_returns_redirect_to_index_view_with_missing_job_group()
        {
            // Given
            var data = RegistrationDataHelper.GetDefaultDelegateRegistrationData(jobGroup: null);

            controller.TempData.Set(data);
            controller.ModelState.AddModelError("", "");

            // When
            var result = await controller.Summary(new SummaryViewModel());

            // Then
            A.CallTo(
                () =>
                registrationService.RegisterDelegate(
                    A <DelegateRegistrationModel> ._,
                    IpAddress,
                    false,
                    SupervisorDelegateId
                    )
                )
            .MustNotHaveHappened();
            result.Should().BeRedirectToActionResult().WithActionName("Index");
        }